<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
     <?php $__env->slot('header', null, []); ?> 
        <div class="d-flex align-items-center justify-content-between">
            <div>
                <h2 class="h4 mb-0">Zone Management</h2>
            </div>
            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('zone.create')): ?>
                <button class="btn btn-primary" id="createZoneButton">New Zone</button>
            <?php endif; ?>
        </div>
     <?php $__env->endSlot(); ?>

    <div class="card shadow-sm border-0">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered table-hover" id="zonesTable" style="width:100%">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Name</th>
                            <th>Parent</th>
                            <th>Type</th>
                            <th>Status</th>
                            <th class="text-end">Actions</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>

    <?php echo $__env->make('admin.zones.partials.modal', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

    <?php $__env->startPush('scripts'); ?>
        <script>
            document.addEventListener('DOMContentLoaded', function () {
                const zoneModal = new bootstrap.Modal(document.getElementById('zoneModal'));
                const table = $('#zonesTable').DataTable({
                    processing: true,
                    serverSide: true,
                    responsive: true,
                    ajax: '<?php echo route('admin.zones.data'); ?>',
                    columns: [
                        { data: 'id', name: 'id' },
                        { data: 'name', name: 'name' },
                        { data: 'parent_name', name: 'parent.name', orderable: false, searchable: false },
                        { data: 'type_label', name: 'parent_id', orderable: false, searchable: false },
                        { data: 'status_label', name: 'status', orderable: false, searchable: false },
                        { data: 'actions', name: 'actions', orderable: false, searchable: false, className: 'text-end' },
                    ]
                });

                $('#createZoneButton').on('click', function () {
                    $('#zoneForm')[0].reset();
                    $('#zoneForm').attr('action', '<?php echo route('admin.zones.store'); ?>');
                    $('#zoneForm').find('input[name=_method]').remove();
                    $('#zoneModalLabel').text('Create Zone');
                    zoneModal.show();
                });

                $(document).on('submit', '#zoneForm', function (e) {
                    e.preventDefault();
                    const form = $(this);
                    const action = form.attr('action');
                    const method = form.find('input[name=_method]').val() || 'POST';
                    const data = form.serialize();

                    $.ajax({
                        url: action,
                        method: method,
                        data: data,
                        success: function () {
                            zoneModal.hide();
                            table.ajax.reload(null, false);
                            showToast('Zone saved successfully.', 'success');
                        },
                        error: function (xhr) {
                            handleFormErrors(xhr, form);
                        }
                    });
                });

                $(document).on('click', '.edit-zone', function () {
                    const url = $(this).data('url');
                    $.get(url, function (response) {
                        const data = response.data;
                        $('#zoneForm').attr('action', response.update_url);
                        if ($('#zoneForm').find('input[name=_method]').length === 0) {
                            $('#zoneForm').append('<input type="hidden" name="_method" value="PUT">');
                        }

                        $('#zoneModalLabel').text('Edit Zone');
                        $('#zoneForm input[name="name"]').val(data.name);
                        $('#zoneForm select[name="parent_id"]').val(data.parent_id || '');
                        $('#zoneForm select[name="status"]').val(data.status ? '1' : '0');
                        $('#zoneForm textarea[name="description"]').val(data.description);
                        zoneModal.show();
                    });
                });

                $(document).on('click', '.delete-zone', function () {
                    if (!confirm('Are you sure you want to remove this zone?')) {
                        return;
                    }

                    $.ajax({
                        url: $(this).data('url'),
                        method: 'DELETE',
                        success: function () {
                            table.ajax.reload(null, false);
                            showToast('Zone removed successfully.', 'success');
                        }
                    });
                });
            });
        </script>
    <?php $__env->stopPush(); ?>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php /**PATH D:\herd\billing\laravel-app\resources\views\admin\zones\index.blade.php ENDPATH**/ ?>