@extends('layouts.app')
@section('title','Borrows')
@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.borrows')}}</h3>
                @can('borrows.create')
                <a href="{{route('borrows.create')}}" class="btn btn-primary" title="{{__('lang.new_borrow')}}">
                    <i class='bi bi-plus'></i>
                </a>
                @endcan
            </div>
            <div class="tile-body">
                <div class="row my-3">
                    <div class="col-md-3">
                        <label for="is_returned">{{__('messages.is_returned')}}</label>
                        <select id="is_returned" class="form-control form-control-sm">
                            <option value="">{{__('lang.select_option')}}</option>
                            <option value="1">{{__('lang.returned')}}</option>
                            <option value="0">{{__('lang.not_returned')}}</option>
                        </select>
                    </div>
                    <div class="col-md-3">
                        <label for="from_date">{{__('lang.returned_date_from')}}</label>
                        <input type="date" class="form-control form-control-sm" id="from_date">
                    </div>
                    <div class="col-md-3">
                        <label for="to_date">{{__('lang.returned_date_to')}}</label>
                        <input type="date" class="form-control form-control-sm" id="to_date">
                    </div>
                    <div class="col-md-3">
                        <br>
                        <button class="btn btn-primary btn-sm" id="btn-filter">{{__('lang.search')}}</button>
                    </div>
                </div>
                <div class="table-responsive">
                    <table class="table table-hover table-bordered" id="my-table">
                        <thead class="table-primary">
                            <tr>
                                <th>#</th>
                                <th>{{__('lang.book')}}</th>
                                <th>{{__('lang.member')}}</th>
                                <th>{{__('lang.borrow_date')}}</th>
                                <th>{{__('lang.return_date')}}</th>
                                <th>{{__('lang.status')}}</th>
                                <th>{{__('lang.action')}}</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@push('scripts')

<script type="text/javascript">
    const table = new DataTable('#my-table', {
        processing: true,
        serverSide: true,
        "ordering": false,
        ajax: {
            url: '{{ route('borrows.dataTable') }}',
            data: function (d) {
                d.is_returned = $('#is_returned').val();
                d.from_date = $('#from_date').val();
                d.to_date = $('#to_date').val();
            }
        },
        columns: [
            { data: 'id', name: 'id' },
            { data: 'book', name: 'book' },
            { data: 'member', name: 'member' },
            { data: 'borrow_date', name: 'borrow_date' },
            { data: 'return_date', name: 'return_date' },
            { data: 'status', name: 'status' },
            { data: 'action', name: 'action', searchable: false }
        ],
    });

    $('#btn-filter').on('click', function () {
        table.ajax.reload();
    });

</script>
@endpush