@extends('layouts.verifier')

@section('title', 'Preuves de Livraison')
@section('page-title', 'Verification des Preuves de Livraison')

@section('content')
<div class="card mb-4">
    <div class="card-body">
        <form action="{{ route('verifier.delivery.index') }}" method="GET" class="row g-3">
            <div class="col-md-4">
                <select name="status" class="form-select" onchange="this.form.submit()">
                    <option value="all" {{ request('status') == 'all' ? 'selected' : '' }}>Toutes les commandes</option>
                    <option value="pending" {{ request('status') == 'pending' ? 'selected' : '' }}>A verifier</option>
                    <option value="approved" {{ request('status') == 'approved' ? 'selected' : '' }}>Approuvees</option>
                    <option value="rejected" {{ request('status') == 'rejected' ? 'selected' : '' }}>Rejetees</option>
                </select>
            </div>
        </form>
    </div>
</div>

<div class="card">
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead class="table-light">
                    <tr>
                        <th>Commande</th>
                        <th>Client</th>
                        <th>Vendeur</th>
                        <th>Statut</th>
                        <th>Preuve</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($orders as $order)
                    <tr>
                        <td>
                            <strong>#{{ $order->id }}</strong><br>
                            <small class="text-muted">{{ number_format($order->total) }} XOF</small>
                        </td>
                        <td>{{ $order->user->name ?? 'N/A' }}</td>
                        <td>{{ $order->seller->store_name ?? 'N/A' }}</td>
                        <td>
                            @php
                                $proofBadges = [
                                    'none' => 'bg-secondary',
                                    'submitted' => 'bg-warning text-dark',
                                    'approved' => 'bg-success',
                                    'rejected' => 'bg-danger'
                                ];
                                $proofLabels = [
                                    'none' => 'Non soumise',
                                    'submitted' => 'A verifier',
                                    'approved' => 'Approuvee',
                                    'rejected' => 'Rejetee'
                                ];
                            @endphp
                            <span class="badge {{ $proofBadges[$order->delivery_proof_status ?? 'none'] }}">
                                {{ $proofLabels[$order->delivery_proof_status ?? 'none'] }}
                            </span>
                        </td>
                        <td>
                            @if($order->delivery_proof)
                                <a href="{{ asset('storage/' . $order->delivery_proof) }}" target="_blank" class="btn btn-sm btn-outline-primary">
                                    <i class="bi bi-file-image"></i> Voir
                                </a>
                            @else
                                <span class="text-muted">Aucune</span>
                            @endif
                        </td>
                        <td>
                            <a href="{{ route('verifier.delivery.show', $order) }}" class="btn btn-sm btn-primary">
                                <i class="bi bi-eye"></i> Details
                            </a>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="6" class="text-center py-4 text-muted">Aucune commande</td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="mt-4">
    {{ $orders->links() }}
</div>
@endsection
