<?php $__env->startSection('title', 'KYC BO · LineUp France'); ?>

<?php $__env->startSection('content'); ?>
    <div class="bg-body-light bo-page-top">
        <div class="content content-full bo-page-top-content">
            <div class="d-flex flex-column flex-sm-row justify-content-sm-between align-items-sm-center py-2 bo-page-head">
                <div class="flex-grow-1">
                    <h1 class="h3 fw-bold mb-1 bo-page-title">KYC BO</h1>
                    <h2 class="fs-base lh-base fw-medium text-muted mb-0 bo-page-subtitle">Moderation centralisee des dossiers KYC liners.</h2>
                </div>
                <nav class="flex-shrink-0 mt-3 mt-sm-0 ms-sm-3" aria-label="breadcrumb">
                    <ol class="breadcrumb breadcrumb-alt bo-breadcrumb">
                        <li class="breadcrumb-item">LineUp France</li>
                        <li class="breadcrumb-item" aria-current="page">KYC</li>
                    </ol>
                </nav>
            </div>
            <div class="bo-hero-actions">
                <a href="<?php echo e(route('bo.dashboard')); ?>" class="btn btn-sm btn-alt-secondary">
                    <i class="si si-speedometer me-1"></i> Tableau de bord
                </a>
                <a href="<?php echo e(route('bo.users.index')); ?>" class="btn btn-sm btn-alt-secondary">
                    <i class="si si-users me-1"></i> Utilisateurs
                </a>
                <a href="<?php echo e(route('bo.missions.index')); ?>" class="btn btn-sm btn-alt-secondary">
                    <i class="si si-briefcase me-1"></i> Missions
                </a>
            </div>
        </div>
    </div>

    <div class="content bo-page-content">
        <div class="block block-rounded">
            <div class="block-header block-header-default">
                <h3 class="block-title"><i class="si si-equalizer me-1"></i>Filtres avances</h3>
                <div class="block-options">
                    <a href="<?php echo e(route('bo.kyc.index')); ?>" class="btn btn-sm btn-alt-secondary">
                        <i class="fa fa-rotate-left opacity-50 me-1"></i> Reinitialiser
                    </a>
                </div>
            </div>
            <div class="block-content">
                <form method="GET" action="<?php echo e(route('bo.kyc.index')); ?>" class="row g-3 align-items-end bo-filter-form">
                    <div class="col-md-4">
                        <label class="form-label" for="q">Recherche user</label>
                        <div class="input-group">
                            <span class="input-group-text bg-body-light border-0"><i class="fa fa-search text-muted"></i></span>
                            <input id="q" type="text" name="q" class="form-control form-control-alt" value="<?php echo e($search); ?>" placeholder="Nom ou email">
                        </div>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label" for="status">Statut</label>
                        <select id="status" name="status" class="form-select">
                            <option value="">Tous</option>
                            <?php $__currentLoopData = ['pending', 'approved', 'rejected']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $statusOption): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                    $statusLabel = match ($statusOption) {
                                        'pending' => 'En attente',
                                        'approved' => 'Approuve',
                                        'rejected' => 'Rejete',
                                        default => ucfirst(str_replace('_', ' ', $statusOption)),
                                    };
                                ?>
                                <option value="<?php echo e($statusOption); ?>" <?php if($status === $statusOption): echo 'selected'; endif; ?>><?php echo e($statusLabel); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label" for="document_type">Type doc</label>
                        <select id="document_type" name="document_type" class="form-select">
                            <option value="">Tous</option>
                            <?php $__currentLoopData = $documentTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($type); ?>" <?php if($documentType === $type): echo 'selected'; endif; ?>><?php echo e(strtoupper($type)); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-md-3">
                        <label class="form-label" for="date_from">Date de creation</label>
                        <div class="input-group">
                            <input id="date_from" type="date" name="date_from" class="form-control form-control-alt" value="<?php echo e($dateFrom); ?>">
                            <input id="date_to" type="date" name="date_to" class="form-control form-control-alt" value="<?php echo e($dateTo); ?>">
                        </div>
                    </div>
                    <div class="col-md-1 d-flex gap-2 bo-filter-actions">
                        <button type="submit" class="btn btn-alt-primary w-100">
                            <i class="fa fa-filter opacity-50"></i>
                        </button>
                    </div>
                </form>
            </div>
        </div>

        <div class="block block-rounded mb-0">
            <div class="block-header block-header-default">
                <h3 class="block-title"><i class="si si-shield me-1"></i>Dossiers KYC</h3>
                <div class="block-options">
                    <span class="badge bg-primary"><?php echo e($kycDocuments->total()); ?> resultat(s)</span>
                </div>
            </div>
            <div class="block-content p-0">
                <div class="table-responsive">
                    <table class="table table-vcenter table-striped table-hover fs-sm mb-0 bo-table">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>Liner</th>
                            <th>Document</th>
                            <th>Statut</th>
                            <th>Validation</th>
                            <th style="width: 300px;">Actions</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $kycDocuments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $doc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td>#<?php echo e($doc->id); ?></td>
                                <td>
                                    <div class="fw-semibold"><?php echo e($doc->user?->name ?? '-'); ?></div>
                                    <div class="text-muted"><?php echo e($doc->user?->email ?? '-'); ?></div>
                                </td>
                                <td>
                                    <?php
                                        $documentUrl = (string) ($doc->document_url ?? '');
                                        $documentPath = strtolower(parse_url($documentUrl, PHP_URL_PATH) ?? '');
                                        $isImageDocument = str_ends_with($documentPath, '.jpg')
                                            || str_ends_with($documentPath, '.jpeg')
                                            || str_ends_with($documentPath, '.png')
                                            || str_ends_with($documentPath, '.webp');
                                        $isPdfDocument = str_ends_with($documentPath, '.pdf');
                                    ?>
                                    <div class="fw-semibold"><?php echo e(strtoupper($doc->document_type)); ?></div>
                                    <div class="text-muted"><?php echo e($doc->document_number ?: '-'); ?></div>
                                    <div class="small text-muted">Depose le <?php echo e($doc->created_at?->format('d/m/Y H:i') ?? '-'); ?></div>
                                    <?php if($documentUrl !== ''): ?>
                                        <div class="mt-2">
                                            <?php if($isImageDocument): ?>
                                                <a href="<?php echo e($documentUrl); ?>" target="_blank" rel="noopener">
                                                    <img
                                                        src="<?php echo e($documentUrl); ?>"
                                                        alt="Document KYC #<?php echo e($doc->id); ?>"
                                                        style="width: 90px; height: 90px; object-fit: cover; border-radius: 12px; border: 1px solid #E5E7EB;"
                                                    >
                                                </a>
                                            <?php else: ?>
                                                <div class="d-inline-flex align-items-center gap-2 px-3 py-2 rounded border bg-body-light">
                                                    <i class="fa <?php echo e($isPdfDocument ? 'fa-file-pdf text-danger' : 'fa-file-lines text-primary'); ?>"></i>
                                                    <span class="small"><?php echo e($isPdfDocument ? 'Document PDF' : 'Document joint'); ?></span>
                                                </div>
                                            <?php endif; ?>
                                        </div>
                                        <div class="d-flex gap-2 mt-2">
                                            <a href="<?php echo e($documentUrl); ?>" target="_blank" rel="noopener" class="btn btn-sm btn-alt-primary">
                                                <i class="fa fa-up-right-from-square me-1"></i>Ouvrir
                                            </a>
                                            <a href="<?php echo e($documentUrl); ?>" target="_blank" rel="noopener" download class="btn btn-sm btn-alt-secondary">
                                                <i class="fa fa-download me-1"></i>Telecharger
                                            </a>
                                        </div>
                                    <?php else: ?>
                                        <div class="small text-danger mt-2">Aucun document exploitable sur ce dossier.</div>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <?php
                                        $badgeClass = match($doc->status) {
                                            'approved' => 'bg-success',
                                            'rejected' => 'bg-danger',
                                            default => 'bg-warning text-dark',
                                        };
                                    ?>
                                    <?php
                                        $docStatusLabel = match ($doc->status) {
                                            'pending' => 'En attente',
                                            'approved' => 'Approuve',
                                            'rejected' => 'Rejete',
                                            default => ucfirst(str_replace('_', ' ', (string) $doc->status)),
                                        };
                                    ?>
                                    <span class="badge <?php echo e($badgeClass); ?>"><?php echo e($docStatusLabel); ?></span>
                                    <?php if($doc->notes): ?>
                                        <small class="d-block text-muted mt-1"><?php echo e($doc->notes); ?></small>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <div><?php echo e($doc->validator?->name ?? '-'); ?></div>
                                    <small class="text-muted d-block"><?php echo e($doc->validated_at?->format('d/m/Y H:i') ?? '-'); ?></small>
                                    <?php if($doc->status === 'pending'): ?>
                                        <small class="text-muted d-block mt-1">En attente de moderation</small>
                                    <?php elseif($doc->notes): ?>
                                        <small class="text-muted d-block mt-1">Motif / note: <?php echo e($doc->notes); ?></small>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <div class="bo-table-actions">
                                        <form method="POST" action="<?php echo e(route('bo.kyc.approve', $doc)); ?>">
                                            <?php echo csrf_field(); ?>
                                            <button class="btn btn-sm btn-success" type="submit">
                                                <i class="fa fa-check me-1"></i>Approuver
                                            </button>
                                        </form>
                                        <form method="POST" action="<?php echo e(route('bo.kyc.reject', $doc)); ?>" class="d-flex gap-2">
                                            <?php echo csrf_field(); ?>
                                            <input class="form-control form-control-sm" type="text" name="reason" placeholder="Motif rejet">
                                            <button class="btn btn-sm btn-danger" type="submit">
                                                <i class="fa fa-xmark me-1"></i>Rejeter
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="6" class="text-center text-muted">Aucun dossier KYC.</td>
                            </tr>
                        <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="block-content">
                <?php echo e($kycDocuments->links()); ?>

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

<?php echo $__env->make('bo.layouts.backend', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/lineupfrance/public_html/resources/views/bo/kyc/index.blade.php ENDPATH**/ ?>