<?php $__env->startSection('title', 'Customers'); ?>

<?php $__env->startSection('content'); ?>
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2 class="fw-bold">Customers</h2>
    <a href="<?php echo e(route('customers.create')); ?>" class="btn btn-primary"><i class="fas fa-plus"></i> Add Customer</a>
</div>

<div class="card-table-wrapper">
    <div class="table-responsive">
        <table id="customersTable" class="table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Customer Name</th>
                    <th>Mobile</th>
                    <th>City</th>
                    <th>GST Number</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $customers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $customer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td><span class="text-muted fw-bold">#<?php echo e($customer->id); ?></span></td>
                    <td class="fw-bold text-primary"><?php echo e($customer->customer_name); ?></td>
                    <td><span class="badge bg-light text-dark border"><?php echo e($customer->mobile); ?></span></td>
                    <td><?php echo e($customer->city ?? '-'); ?></td>
                    <td><?php echo e($customer->gst_number ?? '-'); ?></td>
                    <td>
                        <div class="action-buttons">
                            <a href="<?php echo e(route('customers.edit', $customer->id)); ?>" class="btn btn-warning action-btn text-white" title="Edit Customer"><i class="fas fa-edit"></i></a>
                            <button class="btn btn-danger action-btn delete-btn" data-id="<?php echo e($customer->id); ?>" title="Delete Customer"><i class="fas fa-trash"></i></button>
                        </div>
                    </td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
$(document).ready(function() {
    $('#customersTable').DataTable();

    $('.delete-btn').click(function() {
        let id = $(this).data('id');
        let url = `<?php echo e(url('customers')); ?>/${id}`;

        Swal.fire({
            title: 'Are you sure?',
            text: "You won't be able to revert this!",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#d33',
            cancelButtonColor: '#3085d6',
            confirmButtonText: 'Yes, delete it!'
        }).then((result) => {
            if (result.isConfirmed) {
                $.ajax({
                    url: url,
                    type: 'DELETE',
                    success: function(response) {
                        if(response.success) {
                            Swal.fire('Deleted!', response.message, 'success')
                            .then(() => location.reload());
                        }
                    },
                    error: function(xhr) {
                        Swal.fire('Error!', xhr.responseJSON.message || 'Something went wrong.', 'error');
                    }
                });
            }
        })
    });
});
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH E:\xampp\htdocs\riya\billing\resources\views/customers/index.blade.php ENDPATH**/ ?>