@extends('layouts.template')

@section('content')
    @include('components.notification')

    {{-- <div class="row justify-content-between">
        <div class="col-md-6">
            @include('components.button-add', ['btnText' => $btnText, 'btnLink' => $btnLink])
        </div>
        <div class="col-md-4">
        </div>
    </div> --}}
    <form action="">
        <div class="row">
            <div class="col-md-3">
                <label for="">Dari Tanggal</label>
                <input type="date" name="dari" id="" class="form-control"
                    value="{{ isset($_GET['dari']) ? $_GET['dari'] : date('Y-m-d') }}">
            </div>
            <div class="col-md-3">
                <label for="">Sampai Tanggal</label>
                <input type="date" name="sampai" id="" class="form-control"
                    value="{{ isset($_GET['sampai']) ? $_GET['sampai'] : date('Y-m-d') }}">
            </div>
            <div class="col-md-3">
                <label for="">Cabang</label>
                <select class='form-control select2' name='branch'>
                    <option value=''>Semua Cabang</option>
                    @foreach ($branch as $item)
                        <option value='{{ $item->id }}'
                            {{ isset($_GET['branch']) && $_GET['branch'] == $item->id ? 'selected' : '' }}>
                            {{ $item->cabang }}</option>
                    @endforeach
                </select>
            </div>
            <div class="col-md-3">
                <label for="">Tipe Member</label>
                {{-- <select class='form-control select2' name='category'>
                    <option value=''>Semua Kategori</option>
                    @foreach ($category as $item)
                        <option value='{{$item->id}}' {{isset($_GET['category']) && $_GET['category'] == $item->id ? 'selected' : ''}}>{{$item->category}}</option>
                    @endforeach
                </select> --}}

            </div>
            <div class="col">
                <br>
                <button type="submit" class="btn btn-primary"><span class="fa fa-filter"></span> Filter</button>
                @if (isset($_GET['dari']))
                    <a href='{{ url("list-member?dari=$_GET[dari]&sampai=$_GET[sampai]&branch=$_GET[branch]&kategori_member=$_GET[kategori_member]&export=true") }}'
                        class="btn btn-success"><span class="fa fa-file-excel"></span> Export</a>
                @endif
            </div>
        </div>
    </form>
    @isset($_GET['dari'])
        <br>
        @include('customer._table-list')
    @endisset
    </div>
@endsection

@push('custom-script')
    @isset($_GET['dari'])
        <script type="text/javascript">
            $(function() {
                var table = $('.myTable').DataTable({
                    processing: true,
                    serverSide: true,
                    orderable: false,
                    ajax: "<?= url('list-member?dari=' . $_GET['dari'] . '&sampai=' . $_GET['sampai']) . '&branch=' . $_GET['branch'] . '&kategori_member=' . $_GET['kategori_member'] ?>",
                    columns: [{
                            data: 'DT_RowIndex',
                            name: 'DT_RowIndex',
                        },
                        {
                            data: 'nama',
                            name: 'nama'
                        },
                        {
                            data: 'email',
                            name: 'email'
                        },
                        {
                            data: 'phone',
                            name: 'phone'
                        },
                        {
                            data: 'tgl_lahir',
                            name: 'tgl_lahir'
                        },
                        {
                            data: 'poin',
                            name: 'poin'
                        },
                        {
                            data: 'cabang',
                            name: 'cabang'
                        },
                        {
                            data: 'kategori_member',
                            name: 'kategori_member',
                        },
                        {
                            data: 'specific_member_data', // This is the new column
                            name: 'specific_member_data',
                            orderable: false, // Make it not sortable if preferred
                            searchable: false // Make it not searchable if preferred
                        },
                        // {
                        //     data: 'action',
                        //     name: 'action',
                        //     orderable: false,
                        //     searchable: false
                        // },
                    ],
                    order: [
                        [0, 'asc']
                    ],
                });
            });

            function indoDate(newDate) {
                const today = new Date(newDate);
                const yyyy = today.getFullYear();
                let mm = today.getMonth() + 1; // Months start at 0!
                let dd = today.getDate();
                let hh = newDate.substr(11, 2);
                let ii = newDate.substr(14, 2);

                if (dd < 10) dd = '0' + dd;
                if (mm < 10) mm = '0' + mm;

                const formattedToday = dd + '-' + mm + '-' + yyyy + ' ' + hh + ':' + ii;
                return formattedToday
            }
        </script>
    @endisset
@endpush
