

<?php $__env->startSection('title', 'KYC Verification'); ?>

<?php $__env->startSection('admin-content'); ?>
<style>
    /* KYC Page Styles */
    .kyc-page .stat-card { background: #fff; border-radius: 12px; padding: 1.25rem; box-shadow: 0 2px 8px rgba(0,0,0,0.05); transition: all 0.2s; cursor: pointer; border: 2px solid transparent; }
    .kyc-page .stat-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.1); transform: translateY(-2px); }
    .kyc-page .stat-card.active { border-color: var(--primary-color); background: linear-gradient(135deg, #f8f9ff 0%, #fff 100%); }
    .kyc-page .stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; }
    .kyc-page .stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
    
    .kyc-page .filter-bar { background: #fff; border-radius: 12px; padding: 1rem 1.25rem; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
    
    .kyc-page .doc-thumbnail { width: 60px; height: 60px; border-radius: 8px; object-fit: cover; cursor: pointer; transition: all 0.2s; border: 2px solid #e5e7eb; }
    .kyc-page .doc-thumbnail:hover { transform: scale(1.05); border-color: var(--primary-color); }
    
    .kyc-page .seller-photo { width: 42px; height: 42px; border-radius: 10px; object-fit: cover; }
    .kyc-page .seller-initials { width: 42px; height: 42px; border-radius: 10px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9rem; }
    
    .kyc-page .plan-badge { font-size: 0.7rem; padding: 0.25rem 0.6rem; border-radius: 50px; font-weight: 600; }
    .kyc-page .plan-badge.free { background: #f3f4f6; color: #6b7280; }
    .kyc-page .plan-badge.premium { background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%); color: #fff; }
    
    .kyc-page .bulk-bar { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 12px; padding: 0.75rem 1.25rem; color: #fff; }
    
    .kyc-page .doc-type-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1rem; }
    
    /* Preview Modal */
    .preview-container { max-height: 70vh; overflow: auto; }
    .preview-container img { max-width: 100%; height: auto; }
    .preview-container embed { width: 100%; height: 70vh; }
</style>

<div class="kyc-page">
    <!-- Page Header -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="fw-bold mb-1">KYC Verification</h4>
            <p class="text-muted mb-0 small">Review and manage seller verification documents</p>
        </div>
    </div>

    <?php if(session('success')): ?>
        <div class="alert alert-success border-0 shadow-sm rounded-3 mb-4 d-flex align-items-center">
            <i class="bi bi-check-circle-fill me-2 fs-5"></i>
            <?php echo e(session('success')); ?>

            <button type="button" class="btn-close ms-auto" data-bs-dismiss="alert"></button>
        </div>
    <?php endif; ?>

    <!-- Stats Cards -->
    <div class="row g-3 mb-4">
        <div class="col-md-4">
            <a href="<?php echo e(route('admin.kyc.index', ['status' => 'pending'])); ?>" class="text-decoration-none">
                <div class="stat-card <?php echo e($status == 'pending' ? 'active' : ''); ?>">
                    <div class="d-flex align-items-center gap-3">
                        <div class="stat-icon bg-warning bg-opacity-10 text-warning">
                            <i class="bi bi-clock-fill"></i>
                        </div>
                        <div>
                            <div class="stat-value text-dark"><?php echo e($stats['pending']); ?></div>
                            <div class="text-muted small">Pending Review</div>
                        </div>
                    </div>
                </div>
            </a>
        </div>
        <div class="col-md-4">
            <a href="<?php echo e(route('admin.kyc.index', ['status' => 'approved'])); ?>" class="text-decoration-none">
                <div class="stat-card <?php echo e($status == 'approved' ? 'active' : ''); ?>">
                    <div class="d-flex align-items-center gap-3">
                        <div class="stat-icon bg-success bg-opacity-10 text-success">
                            <i class="bi bi-check-circle-fill"></i>
                        </div>
                        <div>
                            <div class="stat-value text-dark"><?php echo e($stats['approved']); ?></div>
                            <div class="text-muted small">Approved</div>
                        </div>
                    </div>
                </div>
            </a>
        </div>
        <div class="col-md-4">
            <a href="<?php echo e(route('admin.kyc.index', ['status' => 'rejected'])); ?>" class="text-decoration-none">
                <div class="stat-card <?php echo e($status == 'rejected' ? 'active' : ''); ?>">
                    <div class="d-flex align-items-center gap-3">
                        <div class="stat-icon bg-danger bg-opacity-10 text-danger">
                            <i class="bi bi-x-circle-fill"></i>
                        </div>
                        <div>
                            <div class="stat-value text-dark"><?php echo e($stats['rejected']); ?></div>
                            <div class="text-muted small">Rejected</div>
                        </div>
                    </div>
                </div>
            </a>
        </div>
    </div>

    <!-- Filter Bar -->
    <div class="filter-bar mb-4">
        <form method="GET" class="row g-3 align-items-end">
            <div class="col-md-3">
                <label class="form-label small fw-bold text-muted">Status</label>
                <select name="status" class="form-select form-select-sm" onchange="this.form.submit()">
                    <option value="all" <?php echo e(request('status') == 'all' ? 'selected' : ''); ?>>All Status</option>
                    <option value="pending" <?php echo e(request('status', 'pending') == 'pending' ? 'selected' : ''); ?>>Pending</option>
                    <option value="approved" <?php echo e(request('status') == 'approved' ? 'selected' : ''); ?>>Approved</option>
                    <option value="rejected" <?php echo e(request('status') == 'rejected' ? 'selected' : ''); ?>>Rejected</option>
                </select>
            </div>
            <div class="col-md-3">
                <label class="form-label small fw-bold text-muted">Seller Type</label>
                <select name="seller_type" class="form-select form-select-sm" onchange="this.form.submit()">
                    <option value="">All Sellers</option>
                    <option value="paid" <?php echo e(request('seller_type') == 'paid' ? 'selected' : ''); ?>>Paid (Subscribed)</option>
                    <option value="free" <?php echo e(request('seller_type') == 'free' ? 'selected' : ''); ?>>Free</option>
                </select>
            </div>
            <div class="col-md-4">
                <label class="form-label small fw-bold text-muted">Search</label>
                <div class="input-group input-group-sm">
                    <input type="text" name="search" class="form-control" placeholder="Company or seller name..." value="<?php echo e(request('search')); ?>">
                    <button class="btn btn-primary" type="submit"><i class="bi bi-search"></i></button>
                </div>
            </div>
            <div class="col-md-2">
                <a href="<?php echo e(route('admin.kyc.index')); ?>" class="btn btn-outline-secondary btn-sm w-100">
                    <i class="bi bi-x-lg me-1"></i>Clear
                </a>
            </div>
        </form>
    </div>

    <!-- Bulk Actions Bar (Hidden by default, shown when items selected) -->
    <div class="bulk-bar mb-4 d-none" id="bulkActionsBar">
        <div class="d-flex justify-content-between align-items-center">
            <div class="d-flex align-items-center gap-3">
                <span class="fw-bold"><span id="selectedCount">0</span> selected</span>
            </div>
            <div class="d-flex gap-2">
                <form action="<?php echo e(route('admin.kyc.bulk-approve')); ?>" method="POST" id="bulkApproveForm">
                    <?php echo csrf_field(); ?>
                    <div id="approveIdsContainer"></div>
                    <button type="submit" class="btn btn-success btn-sm" onclick="return confirm('Approve all selected documents?')">
                        <i class="bi bi-check-lg me-1"></i>Approve Selected
                    </button>
                </form>
                <button type="button" class="btn btn-danger btn-sm" data-bs-toggle="modal" data-bs-target="#bulkRejectModal">
                    <i class="bi bi-x-lg me-1"></i>Reject Selected
                </button>
            </div>
        </div>
    </div>

    <!-- Sellers Table -->
    <div class="data-table">
        <div class="table-responsive">
            <table class="table mb-0 align-middle">
                <thead>
                    <tr>
                        <th style="width: 250px;">Seller</th>
                        <th>Documents Status</th>
                        <th>Profile Stats</th>
                        <th>Last Activity</th>
                        <th class="text-end">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $sellers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $seller): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            $isPaid = $seller->subscription_id ? true : false;
                            $docs = $seller->kycDocuments; // Correct relationship
                        ?>
                        <tr>
                            <td>
                                <div class="d-flex align-items-center gap-3">
                                    <?php if($seller->photo): ?>
                                        <img src="<?php echo e(asset('storage/' . $seller->photo)); ?>" class="seller-photo" alt="Photo">
                                    <?php else: ?>
                                        <div class="seller-initials"><?php echo e(strtoupper(substr($seller->company_name ?? 'S', 0, 2))); ?></div>
                                    <?php endif; ?>
                                    <div>
                                        <div class="fw-bold text-dark"><?php echo e(Str::limit($seller->company_name, 25)); ?></div>
                                        <div class="small text-muted"><?php echo e($seller->user->name ?? 'N/A'); ?></div>
                                        <span class="plan-badge <?php echo e($isPaid ? 'premium' : 'free'); ?> mt-1">
                                            <i class="bi bi-<?php echo e($isPaid ? 'gem' : 'person'); ?> me-1"></i><?php echo e($seller->plan->name ?? 'Free'); ?>

                                        </span>
                                    </div>
                                </div>
                            </td>
                            <td>
                                <div class="d-flex flex-wrap gap-2">
                                    <?php $__currentLoopData = $docs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $doc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php
                                            $docTypes = [
                                                'photo' => ['Photo', 'bi-camera'],
                                                'pan' => ['PAN', 'bi-credit-card'],
                                                'gst' => ['GST', 'bi-building'],
                                                'udyam' => ['Udyam', 'bi-file-earmark-text'],
                                                'iec' => ['IEC', 'bi-globe'],
                                                'other' => ['Other', 'bi-file-earmark']
                                            ];
                                            $type = $docTypes[$doc->document_type] ?? ['Doc', 'bi-file'];
                                            $statusClass = $doc->status == 'approved' ? 'bg-success' : ($doc->status == 'rejected' ? 'bg-danger' : 'bg-warning text-dark');
                                        ?>
                                        <span class="badge <?php echo e($statusClass); ?> py-2 px-3 rounded-3 shadow-sm d-flex align-items-center gap-1" title="<?php echo e(ucfirst($doc->status)); ?>">
                                            <i class="bi <?php echo e($type[1]); ?>"></i>
                                            <?php echo e($type[0]); ?>

                                            <i class="bi bi-<?php echo e($doc->status == 'approved' ? 'check-circle' : ($doc->status == 'rejected' ? 'x-circle' : 'clock')); ?> ms-1" style="font-size: 0.8em;"></i>
                                        </span>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php if($docs->isEmpty()): ?>
                                        <span class="text-muted small italic">No documents uploaded</span>
                                    <?php endif; ?>
                                </div>
                            </td>
                            <td>
                                <div class="small text-muted mb-1">PAN: <span class="text-dark fw-medium"><?php echo e($seller->pan_number ?: '—'); ?></span></div>
                                <div class="small text-muted mb-1">GST: <span class="text-dark fw-medium"><?php echo e($seller->gst ?: '—'); ?></span></div>
                                <div class="small text-muted mb-1">Udyam: <span class="text-dark fw-medium"><?php echo e($seller->udyam_number ?: '—'); ?></span></div>
                                <div class="small text-muted">IEC: <span class="text-dark fw-medium"><?php echo e($seller->iec_code ?: '—'); ?></span></div>
                            </td>
                            <td>
                                <div class="text-dark small"><?php echo e($seller->updated_at->format('d M Y')); ?></div>
                                <small class="text-muted"><?php echo e($seller->updated_at->diffForHumans()); ?></small>
                            </td>
                            <td>
                                <div class="d-flex gap-2 justify-content-end">
                                    <a href="<?php echo e(route('admin.kyc.show', $seller->id)); ?>" class="btn btn-primary btn-sm rounded-pill px-3 shadow-sm">
                                        <i class="bi bi-eye-fill me-1"></i> Review Docs
                                    </a>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="5" class="text-center py-5">
                                <div class="py-4">
                                    <i class="bi bi-inbox fs-1 text-muted opacity-50 d-block mb-3"></i>
                                    <h5 class="fw-bold text-muted">No Sellers Found</h5>
                                    <p class="text-muted small mb-0">No sellers match your current filters.</p>
                                </div>
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        
        <?php if($sellers->hasPages()): ?>
            <div class="p-3 border-top bg-light" style="border-radius: 0 0 16px 16px;">
                <?php echo e($sellers->links()); ?>

            </div>
        <?php endif; ?>
    </div>
</div>

<!-- Single Reject Modal -->
<div class="modal fade" id="rejectModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content border-0 shadow-lg" style="border-radius: 16px;">
            <form id="rejectForm" method="POST">
                <?php echo csrf_field(); ?>
                <div class="modal-header border-0 pb-0">
                    <div>
                        <h5 class="modal-title fw-bold">Reject Document</h5>
                        <p class="text-muted small mb-0">Please provide a reason for rejection</p>
                    </div>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body p-4">
                    <div class="mb-3">
                        <label class="form-label fw-bold small">Rejection Reason <span class="text-danger">*</span></label>
                        <textarea name="rejection_reason" class="form-control" required rows="4" 
                                  placeholder="e.g. Document is blurry, expired, or doesn't match..."></textarea>
                    </div>
                </div>
                <div class="modal-footer border-0 pt-0">
                    <button type="button" class="btn btn-light rounded-3" data-bs-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-danger rounded-3 px-4">
                        <i class="bi bi-x-circle me-2"></i>Reject Document
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Bulk Reject Modal -->
<div class="modal fade" id="bulkRejectModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content border-0 shadow-lg" style="border-radius: 16px;">
            <form action="<?php echo e(route('admin.kyc.bulk-reject')); ?>" method="POST" id="bulkRejectForm">
                <?php echo csrf_field(); ?>
                <div id="rejectIdsContainer"></div>
                <div class="modal-header border-0 pb-0">
                    <div>
                        <h5 class="modal-title fw-bold">Bulk Reject Documents</h5>
                        <p class="text-muted small mb-0">This will reject all selected documents</p>
                    </div>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body p-4">
                    <div class="mb-3">
                        <label class="form-label fw-bold small">Rejection Reason <span class="text-danger">*</span></label>
                        <textarea name="rejection_reason" class="form-control" required rows="4" 
                                  placeholder="e.g. Documents do not meet verification standards..."></textarea>
                    </div>
                </div>
                <div class="modal-footer border-0 pt-0">
                    <button type="button" class="btn btn-light rounded-3" data-bs-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-danger rounded-3 px-4">
                        <i class="bi bi-x-circle me-2"></i>Reject All Selected
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Document Preview Modal -->
<div class="modal fade" id="previewModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered modal-lg">
        <div class="modal-content border-0 shadow-lg" style="border-radius: 16px;">
            <div class="modal-header border-0">
                <h5 class="modal-title fw-bold">Document Preview</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body p-4">
                <div class="preview-container text-center" id="previewContainer">
                    <!-- Content loaded dynamically -->
                </div>
            </div>
            <div class="modal-footer border-0 pt-0">
                <a href="#" id="downloadBtn" class="btn btn-primary" download>
                    <i class="bi bi-download me-2"></i>Download
                </a>
            </div>
        </div>
    </div>
</div>

<script>
    // Single reject modal
    document.getElementById('rejectModal').addEventListener('show.bs.modal', function (event) {
        var button = event.relatedTarget;
        var url = button.getAttribute('data-url');
        document.getElementById('rejectForm').action = url;
    });
    
    // Select all toggle
    function toggleSelectAll(el) {
        document.querySelectorAll('.doc-checkbox').forEach(cb => cb.checked = el.checked);
        updateBulkBar();
    }
    
    // Update bulk actions bar
    function updateBulkBar() {
        const checkboxes = document.querySelectorAll('.doc-checkbox:checked');
        const bar = document.getElementById('bulkActionsBar');
        const count = document.getElementById('selectedCount');
        
        if (checkboxes.length > 0) {
            bar.classList.remove('d-none');
            count.textContent = checkboxes.length;
            
            // Update form hidden inputs
            const approveContainer = document.getElementById('approveIdsContainer');
            const rejectContainer = document.getElementById('rejectIdsContainer');
            approveContainer.innerHTML = '';
            rejectContainer.innerHTML = '';
            
            checkboxes.forEach(cb => {
                approveContainer.innerHTML += `<input type="hidden" name="document_ids[]" value="${cb.value}">`;
                rejectContainer.innerHTML += `<input type="hidden" name="document_ids[]" value="${cb.value}">`;
            });
        } else {
            bar.classList.add('d-none');
        }
    }
    
    // Document preview
    function showPreview(url, type) {
        const container = document.getElementById('previewContainer');
        const downloadBtn = document.getElementById('downloadBtn');
        downloadBtn.href = url;
        
        if (type === 'image') {
            container.innerHTML = `<img src="${url}" class="img-fluid rounded" alt="Document">`;
        } else {
            container.innerHTML = `<embed src="${url}" type="application/pdf" width="100%" height="500px">`;
        }
        
        new bootstrap.Modal(document.getElementById('previewModal')).show();
    }
    
    // Tooltips
    document.querySelectorAll('[data-bs-toggle="tooltip"]').forEach(el => new bootstrap.Tooltip(el));
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/u281583269/domains/theminiport.com/public_html/resources/views/admin/kyc/index.blade.php ENDPATH**/ ?>