

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

<?php $__env->startSection('content'); ?>
<div x-data="customerBulkDelete()">
    <div class="mb-6 flex flex-col md:flex-row md:items-center md:justify-between gap-4">
        <div>
            <h3 class="text-xl font-semibold text-gray-800">All Customers</h3>
            <p class="text-gray-600">Manage customer records and information</p>
        </div>
        <div class="flex flex-col md:flex-row gap-3">
            <form action="<?php echo e(route('customers.index')); ?>" method="GET" class="flex items-center">
                <div class="relative">
                    <input type="text" name="search" value="<?php echo e(request('search')); ?>" placeholder="Search customers..." class="pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:ring-indigo-500 focus:border-indigo-500 w-full md:w-64">
                    <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                        <i class="fas fa-search text-gray-400"></i>
                    </div>
                </div>
                <button type="submit" class="ml-2 px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 border border-gray-300 transition-colors">
                    Search
                </button>
            </form>
            
            <!-- Bulk Delete Button -->
            <button @click="bulkDelete()" x-show="selectedCustomers.length > 0" x-cloak
                    class="bg-red-600 text-white px-6 py-2 rounded-lg hover:bg-red-700 transition flex items-center justify-center shadow-md">
                <i class="fas fa-trash mr-2"></i>Delete Selected (<span x-text="selectedCustomers.length"></span>)
            </button>
            
            <a href="<?php echo e(route('customers.create')); ?>" class="bg-gradient-to-r from-purple-600 to-indigo-600 text-white px-6 py-2 rounded-lg hover:shadow-lg transition flex items-center justify-center">
                <i class="fas fa-plus mr-2"></i>New Customer
            </a>
        </div>
    </div>

    <div class="bg-white rounded-lg shadow-md overflow-hidden overflow-x-auto">
        <table class="min-w-full divide-y divide-gray-200">
            <thead class="bg-gray-50">
                <tr>
                    <th class="px-6 py-3 text-left">
                        <input type="checkbox" 
                               @change="toggleSelectAll()"
                               :checked="selectAll"
                               class="w-4 h-4 text-indigo-600 border-gray-300 rounded focus:ring-indigo-500">
                    </th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Name</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Email</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Phone</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Total Due</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Company</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">City</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Actions</th>
                </tr>
            </thead>
            <tbody class="bg-white divide-y divide-gray-200">
                <?php $__currentLoopData = $customers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $customer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr class="hover:bg-gray-50" :class="{ 'bg-indigo-50': selectedCustomers.includes(<?php echo e($customer->id); ?>) }">
                    <td class="px-6 py-4 whitespace-nowrap">
                        <input type="checkbox" 
                               value="<?php echo e($customer->id); ?>"
                               @change="toggleCustomer(<?php echo e($customer->id); ?>)"
                               :checked="selectedCustomers.includes(<?php echo e($customer->id); ?>)"
                               class="w-4 h-4 text-indigo-600 border-gray-300 rounded focus:ring-indigo-500">
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">
                        <a href="<?php echo e(route('customers.show', $customer)); ?>" class="hover:text-indigo-600 hover:underline">
                            <?php echo e($customer->name); ?>

                        </a>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-gray-700"><?php echo e($customer->email); ?></td>
                    <td class="px-6 py-4 whitespace-nowrap text-gray-700"><?php echo e($customer->phone); ?></td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <span class="<?php echo e($customer->bookings_sum_due_payment > 0 ? 'text-red-600 font-bold' : 'text-green-600'); ?>">
                            <?php echo e(number_format($customer->bookings_sum_due_payment ?? 0, 2)); ?>

                        </span>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-gray-700"><?php echo e($customer->company_name ?? 'N/A'); ?></td>
                    <td class="px-6 py-4 whitespace-nowrap text-gray-700"><?php echo e($customer->city); ?></td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <span class="px-3 py-1 rounded-full text-xs font-semibold <?php echo e($customer->is_active ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'); ?>">
                            <?php echo e($customer->is_active ? 'Active' : 'Inactive'); ?>

                        </span>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                        <div class="flex items-center gap-2">
                            <a href="<?php echo e(route('customers.show', $customer)); ?>" class="inline-flex items-center px-3 py-1.5 bg-indigo-600 text-white hover:bg-indigo-700 rounded-md text-xs transition-colors shadow-sm">
                                <i class="fas fa-eye mr-1.5"></i> View
                            </a>
                            <a href="<?php echo e(route('customers.edit', $customer)); ?>" class="inline-flex items-center px-3 py-1.5 bg-white text-gray-700 hover:bg-gray-50 rounded-md text-xs transition-colors border border-gray-300 shadow-sm">
                                <i class="fas fa-edit mr-1.5"></i> Edit
                            </a>
                            <form action="<?php echo e(route('customers.destroy', $customer)); ?>" method="POST" class="inline">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                                <button type="submit" onclick="return confirm('Are you sure?')" class="inline-flex items-center px-3 py-1.5 bg-white text-red-600 hover:bg-red-50 rounded-md text-xs transition-colors border border-gray-300 shadow-sm">
                                    <i class="fas fa-trash mr-1.5"></i> Delete
                                </button>
                            </form>
                        </div>
                    </td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
        
        <!-- Bulk Delete Form -->
        <form id="bulkDeleteForm" action="<?php echo e(route('customers.bulk-delete')); ?>" method="POST" style="display: none;">
            <?php echo csrf_field(); ?>
            <?php echo method_field('DELETE'); ?>
            <input type="hidden" name="customer_ids" id="customerIdsInput">
        </form>
    </div>

    <div class="mt-6">
        <?php echo e($customers->links()); ?>

    </div>
</div>

<script>
function customerBulkDelete() {
    return {
        selectedCustomers: [],
        selectAll: false,
        allCustomerIds: [<?php echo e($customers->pluck('id')->join(',')); ?>],
        
        toggleSelectAll() {
            this.selectAll = !this.selectAll;
            this.selectedCustomers = this.selectAll ? [...this.allCustomerIds] : [];
        },
        
        toggleCustomer(customerId) {
            const index = this.selectedCustomers.indexOf(customerId);
            if (index > -1) {
                this.selectedCustomers.splice(index, 1);
            } else {
                this.selectedCustomers.push(customerId);
            }
            this.selectAll = this.selectedCustomers.length === this.allCustomerIds.length;
        },
        
        bulkDelete() {
            if (this.selectedCustomers.length === 0) {
                alert('Please select at least one customer to delete.');
                return;
            }
            
            if (confirm(`Are you sure you want to delete ${this.selectedCustomers.length} customer(s)? This action cannot be undone.`)) {
                document.getElementById('customerIdsInput').value = JSON.stringify(this.selectedCustomers);
                document.getElementById('bulkDeleteForm').submit();
            }
        }
    }
}
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\al-wasi\Downloads\cargomanagement-system\cargo-management-system\resources\views/customers/index.blade.php ENDPATH**/ ?>