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

<?php $__env->startSection('content'); ?>
<div class="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8">

    
    <div class="mb-6 flex items-center justify-between">
        <div>
            <h1 class="text-2xl font-bold text-gray-900">Customers</h1>
            <p class="mt-1 text-sm text-gray-500">Buyers and fish purchase clients</p>
        </div>
        <a href="<?php echo e(route('customers.create')); ?>"
           class="inline-flex items-center gap-2 rounded-lg bg-green-600 px-4 py-2 text-sm font-medium text-white hover:bg-green-700">
            <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
            </svg>
            Add Customer
        </a>
    </div>

    
    <?php if(session('success')): ?>
        <div class="mb-4 rounded-lg border border-green-200 bg-green-50 p-4 text-sm text-green-800">
            <?php echo e(session('success')); ?>

        </div>
    <?php endif; ?>

    
    <?php
        $total    = $customers->count();
        $flagged  = $customers->where('is_flagged', true)->count();
        $active   = $customers->where('is_flagged', false)->count();
    ?>
    <div class="mb-6 grid grid-cols-1 gap-4 sm:grid-cols-3">
        <div class="rounded-lg border border-gray-200 bg-white p-4 shadow-sm">
            <p class="text-sm text-gray-500">Total Customers</p>
            <p class="mt-1 text-2xl font-bold text-gray-900"><?php echo e($total); ?></p>
        </div>
        <div class="rounded-lg border <?php echo e($flagged ? 'border-red-200 bg-red-50' : 'border-gray-200 bg-white'); ?> p-4 shadow-sm">
            <p class="text-sm <?php echo e($flagged ? 'text-red-600' : 'text-gray-500'); ?>">Flagged</p>
            <p class="mt-1 text-2xl font-bold <?php echo e($flagged ? 'text-red-700' : 'text-gray-900'); ?>"><?php echo e($flagged); ?></p>
        </div>
        <div class="rounded-lg border border-gray-200 bg-white p-4 shadow-sm">
            <p class="text-sm text-gray-500">Active</p>
            <p class="mt-1 text-2xl font-bold text-gray-900"><?php echo e($active); ?></p>
        </div>
    </div>

    
    <?php if($flagged > 0): ?>
        <div class="mb-4 rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-800">
            <strong>⚑ <?php echo e($flagged); ?> flagged <?php echo e(Str::plural('customer', $flagged)); ?></strong> — review before completing new sales.
        </div>
    <?php endif; ?>

    
    <div class="overflow-hidden rounded-lg border border-gray-200 bg-white shadow-sm">
        <?php if($customers->isEmpty()): ?>
            <div class="px-6 py-12 text-center text-sm text-gray-500">
                No customers yet.
                <a href="<?php echo e(route('customers.create')); ?>" class="ml-1 font-medium text-green-600 hover:underline">Add the first one.</a>
            </div>
        <?php else: ?>
            <table class="min-w-full divide-y divide-gray-200 text-sm">
                <thead class="bg-gray-50">
                    <tr>
                        <th class="px-4 py-3 text-left font-medium text-gray-600">Name / Business</th>
                        <th class="px-4 py-3 text-left font-medium text-gray-600">Phone</th>
                        <th class="px-4 py-3 text-right font-medium text-gray-600">Sales</th>
                        <th class="px-4 py-3 text-left font-medium text-gray-600">Status</th>
                        <th class="px-4 py-3"></th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-100">
                    <?php $__currentLoopData = $customers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $customer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr class="hover:bg-gray-50">
                            <td class="px-4 py-3">
                                <div class="font-medium text-gray-900">
                                    <a href="<?php echo e(route('customers.show', $customer)); ?>" class="hover:text-green-700">
                                        <?php echo e($customer->name); ?>

                                        <?php if($customer->nickname): ?>
                                            <span class="text-gray-400">(<?php echo e($customer->nickname); ?>)</span>
                                        <?php endif; ?>
                                    </a>
                                </div>
                                <?php if($customer->business_name): ?>
                                    <div class="text-xs text-gray-500"><?php echo e($customer->business_name); ?></div>
                                <?php endif; ?>
                            </td>
                            <td class="px-4 py-3 text-gray-600"><?php echo e($customer->phone ?? '—'); ?></td>
                            <td class="px-4 py-3 text-right text-gray-700"><?php echo e($customer->sales_count); ?></td>
                            <td class="px-4 py-3">
                                <?php if($customer->is_flagged): ?>
                                    <span class="inline-flex items-center gap-1 rounded-full bg-red-100 px-2 py-0.5 text-xs font-medium text-red-700">
                                        ⚑ Flagged
                                    </span>
                                <?php else: ?>
                                    <span class="inline-flex items-center rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700">
                                        Active
                                    </span>
                                <?php endif; ?>
                            </td>
                            <td class="px-4 py-3 text-right">
                                <a href="<?php echo e(route('customers.edit', $customer)); ?>"
                                   class="text-xs text-blue-600 hover:underline">Edit</a>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        <?php endif; ?>
    </div>

</div>
<?php $__env->stopSection(); ?>

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