@extends('layouts.app')
@section('title','Languages')
@include('layouts.datatable')
@section('content')
<div class="row">
    <div class="col-lg-12">
        <div class="tile">
            <div class="tile-title-w-btn">
                <h3 class="title"><i class="bi bi-list-ul"></i> {{__('lang.languages')}}</h3>
                @can('languages.create')
                <x-buttons.modal modal="myModal" text="<i class='bi bi-plus'></i>" />
                @endcan
            </div>
            <div class="tile-body">
                <div class="table-responsive">
                    <table class="table" id="my-table">
                        <thead class="table-primary">
                            <tr>
                                <th>#</th>
                                <th>{{__('lang.name')}}</th>
                                <th>{{__('lang.action')}}</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <!-- New Modal -->
    <x-modal id="myModal" title="<i class='bi bi-plus'></i>{{__('lang.language')}}">
        <form action="{{route('languages.store')}}" method="post">
            @csrf
            @include('language.partials._form')
            <x-buttons.save />
        </form>
    </x-modal>
</div>
@endsection

@push('scripts')

<script type="text/javascript">
    $("#myModal").on("shown.bs.modal",function(){
        $("#name").focus();
    });
    @if($errors->any())
    const myModal=new bootstrap.Modal("#myModal",{
        keyboard:false
    });
    myModal.show();
    @endif

    new DataTable('#my-table', {
        processing: true,
        serverSide: true,
        "ordering": false,
        ajax: {
            url: '{{ route('languages.dataTable') }}',
        },
        columns: [
            { data: 'id', name: 'id' },
            { data: 'name', name: 'name' },
            { data: 'action', name: 'action', searchable: false }
        ],
    });

</script>
@endpush