
<?php $__env->startSection('title', 'Gate Passes'); ?>
<?php $__env->startPush('plugin-styles'); ?>
<link rel="stylesheet" href="<?php echo e(asset('theme/vendors/datatables.net-bs5/dataTables.bootstrap5.css')); ?>">
<link rel="stylesheet" href="<?php echo e(asset('theme/vendors/flatpickr/flatpickr.min.css')); ?>">
<link rel="stylesheet" href="<?php echo e(asset('theme/vendors/sweetalert2/sweetalert2.min.css')); ?>">
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
<div class="accordion mb-3" id="gpFilterAccordion">
    <div class="accordion-item">
        <h2 class="accordion-header" id="gpFilterHeading">
            <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#gpFilterCollapse" aria-expanded="false" aria-controls="gpFilterCollapse">
                Filters
            </button>
        </h2>
        <div id="gpFilterCollapse" class="accordion-collapse collapse" aria-labelledby="gpFilterHeading" data-bs-parent="#gpFilterAccordion">
            <div class="accordion-body">
                <div class="row g-3 align-items-end">
                    <div class="col-md-4">
                        <label class="form-label">Status</label>
                        <select id="filterStatus" class="form-select">
                            <option value="">All</option>
                            <option value="pending">Pending</option>
                            <option value="completed">Completed</option>
                            <option value="cancelled">Cancelled</option>
                        </select>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">Created Date Range</label>
                        <input id="filterDateRange" class="form-control" placeholder="YYYY-MM-DD to YYYY-MM-DD">
                    </div>
                </div>
                <div class="mt-3 d-flex gap-2">
                    <button id="btnApplyFilters" class="btn btn-primary" type="button">Apply</button>
                    <button id="btnResetFilters" class="btn btn-secondary" type="button">Reset</button>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="card">
    <div class="card-body">
        <div class="d-flex justify-content-between align-items-center mb-3">
            <h6 class="card-title mb-0">Gate Passes</h6>
            <a href="<?php echo e(route('gatepasses.create')); ?>" class="btn btn-primary">
                <i class="fas fa-plus me-2"></i>
                Add Gate Pass
            </a>
        </div>

        <?php if(session('success')): ?>
            <div class="alert alert-success"><?php echo e(session('success')); ?></div>
        <?php endif; ?>
        <?php if($errors->any()): ?>
            <div class="alert alert-danger"><?php echo e($errors->first()); ?></div>
        <?php endif; ?>

        <div class="table-responsive">
            <table id="gate-passes-table" class="table table-hover">
                <thead class="table-light">
                    <tr>
                        <th>ID</th>
                        <th>GP #</th>
                        <th>PO #</th>
                        <th>Vehicle No</th>
                        <th>Driver Name</th>
                        <th>Status</th>
                        <th>Created At</th>
                        <th>Actions</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('plugin-scripts'); ?>
<script src="<?php echo e(asset('theme/vendors/jquery/jquery.min.js')); ?>"></script>
<script src="<?php echo e(asset('theme/vendors/datatables.net/dataTables.js')); ?>"></script>
<script src="<?php echo e(asset('theme/vendors/datatables.net-bs5/dataTables.bootstrap5.js')); ?>"></script>
<script src="<?php echo e(asset('theme/vendors/flatpickr/flatpickr.min.js')); ?>"></script>
<script src="<?php echo e(asset('theme/vendors/sweetalert2/sweetalert2.min.js')); ?>"></script>
<script src="<?php echo e(asset('theme/vendors/moment/moment.min.js')); ?>"></script>

<script>
window.SKIP_ERROR_HANDLING = true;
document.addEventListener('DOMContentLoaded', function () {
    const fp = flatpickr('#filterDateRange', { mode: 'range', dateFormat: 'Y-m-d' });

    const table = new DataTable('#gate-passes-table', {
        processing: true,
        serverSide: true,
        ajax: {
            url: '<?php echo e(route("gatepasses.index")); ?>',
            data: function(d) {
                d.status = $('#filterStatus').val() || '';
                const dr = document.getElementById('filterDateRange').value;
                if (dr && dr.includes(' to ')) {
                    const parts = dr.split(' to ');
                    d.date_from = parts[0];
                    d.date_to = parts[1];
                }
            },
            error: function(xhr, error, thrown) {
                console.error('DataTables error:', error, thrown);
            }
        },
        order: [[0, 'desc']],
        columns: [
            { data: 'id', name: 'id' },
            { data: 'gp_number', name: 'gp_number' },
            { data: 'po_number', name: 'purchaseOrder.po_number' },
            { data: 'vehicle_no', name: 'vehicle_no' },
            { data: 'driver_name', name: 'driver_name' },
            { data: 'status', name: 'status' },
            {
                data: 'created_at',
                name: 'created_at',
                render: function(data) {
                    return moment(data).format('MM/DD/YYYY h:mm A');
                }
            },
            { data: 'actions', name: 'actions', orderable: false, searchable: false }
        ]
    });

    $('#btnApplyFilters, #filterStatus').on('click change', function() {
        table.draw();
    });

    $('#btnResetFilters').on('click', function() {
        $('#filterStatus').val('');
        document.getElementById('filterDateRange').value = '';
        table.draw();
    });
});
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\habibcables-ERP\resources\views\gate_passes copy\index.blade.php ENDPATH**/ ?>