<?php $__env->startSection('title', 'Demande #'.$serviceRequest->id); ?>
<?php $__env->startSection('content'); ?>
<a href="<?php echo e(route('admin.requests.index')); ?>" class="mb-3 d-inline-block">&laquo; Retour a la liste</a>

<div class="row g-3">
    <div class="col-md-7">
        <div class="card p-4">
            <h4>Demande #<?php echo e($serviceRequest->id); ?> — <?php echo e(\App\Models\ServiceRequest::types()[$serviceRequest->type]); ?></h4>
            <p class="mb-1"><strong>Partenaire :</strong> <?php echo e($serviceRequest->partner->name); ?> (<?php echo e($serviceRequest->partner->type); ?>)</p>
            <p class="mb-1"><strong>Statut :</strong>
                <span class="badge <?php echo e($serviceRequest->status === 'ecart' ? 'badge-ecart' : 'bg-secondary'); ?>">
                    <?php echo e(\App\Models\ServiceRequest::statuses()[$serviceRequest->status]); ?>

                </span>
            </p>
            <p class="mb-1"><strong>Urgence :</strong> <?php echo e($serviceRequest->urgency); ?></p>
            <p class="mb-1"><strong>Qte demandee :</strong> <?php echo e($serviceRequest->requested_quantity ?? '-'); ?></p>
            <p class="mb-1"><strong>Qte collectee :</strong> <?php echo e($serviceRequest->collected_quantity ?? '-'); ?></p>

            <?php if($serviceRequest->hasDiscrepancy()): ?>
                <div class="alert alert-danger mt-2 mb-2">
                    Ecart detecte entre la quantite demandee et la quantite reellement collectee par le coursier.
                </div>
            <?php endif; ?>

            <?php if($serviceRequest->unavailable_reason): ?>
                <p class="mb-1"><strong>Motif non-disponible :</strong> <?php echo e($serviceRequest->unavailable_reason); ?></p>
            <?php endif; ?>

            <?php if($serviceRequest->photo_path): ?>
                <div class="mt-3">
                    <strong>Photo de la collecte :</strong><br>
                    <img src="<?php echo e(asset('storage/'.$serviceRequest->photo_path)); ?>" class="img-fluid rounded mt-2" style="max-height:300px;">
                </div>
            <?php endif; ?>

            <hr>
            <h6>Details de la demande</h6>
            <ul class="small">
                <?php $__currentLoopData = $serviceRequest->details ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li><strong><?php echo e(ucfirst(str_replace('_', ' ', $key))); ?> :</strong> <?php echo e($value); ?></li>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </ul>

            <?php if(! $serviceRequest->courier): ?>
            <hr>
            <form action="<?php echo e(route('admin.requests.assign', $serviceRequest)); ?>" method="POST" class="d-flex gap-2">
                <?php echo csrf_field(); ?>
                <select name="assigned_courier_id" class="form-select" required>
                    <option value="">Assigner a un coursier...</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-primary">Assigner</button>
            </form>
            <?php else: ?>
                <p class="mt-2"><strong>Coursier assigne :</strong> <?php echo e($serviceRequest->courier->name); ?></p>
            <?php endif; ?>
        </div>
    </div>

    <div class="col-md-5">
        <div class="card p-4">
            <h5>Historique</h5>
            <ul class="list-group list-group-flush">
                <?php $__currentLoopData = $serviceRequest->statusHistories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $h): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li class="list-group-item">
                        <div class="fw-bold"><?php echo e(\App\Models\ServiceRequest::statuses()[$h->status] ?? $h->status); ?></div>
                        <div class="small text-muted"><?php echo e($h->created_at->format('d/m/Y H:i')); ?> — <?php echo e($h->author->name ?? 'Systeme'); ?></div>
                        <?php if($h->comment): ?><div class="small"><?php echo e($h->comment); ?></div><?php endif; ?>
                    </li>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </ul>
        </div>
    </div>
</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/show.blade.php ENDPATH**/ ?>