@extends('layouts.verifier')

@section('title', 'Verification KYC')
@section('page-title', 'Verification KYC des Vendeurs')

@section('content')
<div class="card mb-4">
    <div class="card-body">
        <form action="{{ route('verifier.kyc.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' : '' }}>Tous les statuts</option>
                    <option value="submitted" {{ request('status') == 'submitted' ? 'selected' : '' }}>Documents soumis (à vérifier)</option>
                    <option value="pending" {{ request('status') == 'pending' ? 'selected' : '' }}>En attente de documents</option>
                    <option value="approved" {{ request('status') == 'approved' ? 'selected' : '' }}>Approuvés</option>
                    <option value="rejected" {{ request('status') == 'rejected' ? 'selected' : '' }}>Rejetés</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>Vendeur</th>
                        <th>Boutique</th>
                        <th>Email</th>
                        <th>Documents</th>
                        <th>Statut KYC</th>
                        <th>Date</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($sellers as $seller)
                    <tr class="{{ $seller->kyc_status === 'submitted' ? 'table-info' : '' }}">
                        <td>{{ $seller->user->name ?? 'N/A' }}</td>
                        <td><strong>{{ $seller->shop_name }}</strong></td>
                        <td>{{ $seller->user->email ?? 'N/A' }}</td>
                        <td>
                            @php
                                $docCount = 0;
                                if($seller->id_document) $docCount++;
                                if($seller->address_proof) $docCount++;
                                if($seller->business_document) $docCount++;
                                if($seller->business_photo) $docCount++;
                            @endphp
                            @if($docCount > 0)
                                <span class="badge bg-primary">{{ $docCount }} doc(s)</span>
                            @else
                                <span class="badge bg-secondary">Aucun</span>
                            @endif
                        </td>
                        <td>
                            @switch($seller->kyc_status)
                                @case('submitted')
                                    <span class="badge bg-info">À vérifier</span>
                                    @break
                                @case('pending')
                                    <span class="badge bg-warning text-dark">En attente</span>
                                    @break
                                @case('approved')
                                    <span class="badge bg-success">Approuvé</span>
                                    @break
                                @case('rejected')
                                    <span class="badge bg-danger">Rejeté</span>
                                    @break
                            @endswitch
                        </td>
                        <td>{{ $seller->updated_at->format('d/m/Y') }}</td>
                        <td>
                            <a href="{{ route('verifier.kyc.show', $seller) }}" class="btn btn-sm btn-{{ $seller->kyc_status === 'submitted' ? 'primary' : 'outline-primary' }}">
                                <i class="bi bi-eye"></i> Examiner
                            </a>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="7" class="text-center py-4 text-muted">Aucun vendeur trouvé</td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>

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