<?php $__env->startSection('title', 'Demandes'); ?>
<?php $__env->startSection('content'); ?>
<h3 class="mb-4">Toutes les demandes</h3>

<form method="GET" class="row g-2 mb-3">
    <div class="col-md-3">
        <select name="type" class="form-select" onchange="this.form.submit()">
            <option value="">Tous types</option>
            <?php $__currentLoopData = $types; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <option value="<?php echo e($key); ?>" <?php if(request('type') === $key): echo 'selected'; endif; ?>><?php echo e($label); ?></option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </select>
    </div>
    <div class="col-md-3">
        <select name="status" class="form-select" onchange="this.form.submit()">
            <option value="">Tous statuts</option>
            <?php $__currentLoopData = $statuses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <option value="<?php echo e($key); ?>" <?php if(request('status') === $key): echo 'selected'; endif; ?>><?php echo e($label); ?></option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </select>
    </div>
    <div class="col-md-3">
        <a href="<?php echo e(route('admin.requests.index')); ?>" class="btn btn-outline-secondary">Reinitialiser</a>
    </div>
</form>

<div class="card p-3">
    <div class="table-responsive">
        <table class="table align-middle">
            <thead>
                <tr>
                    <th>#</th>
                    <th>Partenaire</th>
                    <th>Type</th>
                    <th>Urgence</th>
                    <th>Qte demandee</th>
                    <th>Qte collectee</th>
                    <th>Statut</th>
                    <th>Coursier</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $requests; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $r): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr class="<?php echo e($r->status === 'ecart' ? 'table-danger' : ''); ?>">
                    <td><?php echo e($r->id); ?></td>
                    <td><?php echo e($r->partner->name); ?></td>
                    <td><?php echo e($types[$r->type]); ?></td>
                    <td>
                        <?php if($r->urgency === 'urgent'): ?>
                            <span class="badge badge-urgent">Urgent</span>
                        <?php else: ?>
                            <span class="text-muted small">Normal</span>
                        <?php endif; ?>
                    </td>
                    <td><?php echo e($r->requested_quantity ?? '-'); ?></td>
                    <td><?php echo e($r->collected_quantity ?? '-'); ?></td>
                    <td><span class="badge <?php echo e($r->status === 'ecart' ? 'badge-ecart' : 'bg-secondary'); ?>"><?php echo e($statuses[$r->status]); ?></span></td>
                    <td>
                        <?php if($r->courier): ?>
                            <?php echo e($r->courier->name); ?>

                        <?php else: ?>
                            <form action="<?php echo e(route('admin.requests.assign', $r)); ?>" method="POST" class="d-flex gap-1">
                                <?php echo csrf_field(); ?>
                                <select name="assigned_courier_id" class="form-select form-select-sm" required>
                                    <option value="">Assigner...</option>
                                    <?php $__currentLoopData = $couriers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($c->id); ?>"><?php echo e($c->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <button class="btn btn-sm btn-primary">OK</button>
                            </form>
                        <?php endif; ?>
                    </td>
                    <td><a href="<?php echo e(route('admin.requests.show', $r)); ?>" class="btn btn-sm btn-outline-primary">Detail</a></td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="9" class="text-center text-muted">Aucune demande trouvee.</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
    <?php echo e($requests->links()); ?>

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

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/smartch/capara/resources/views/admin/requests/index.blade.php ENDPATH**/ ?>