

<?php $__env->startSection('title', 'KYC Timeline - ' . $seller->company_name); ?>

<?php $__env->startSection('admin-content'); ?>
<style>
    .timeline { position: relative; padding-left: 2rem; }
    .timeline::before { content: ''; position: absolute; left: 15px; top: 0; bottom: 0; width: 2px; background: #e5e7eb; }
    .timeline-item { position: relative; padding-bottom: 1.5rem; }
    .timeline-item:last-child { padding-bottom: 0; }
    .timeline-icon { position: absolute; left: -2rem; width: 32px; height: 32px; border-radius: 50%; background: #fff; border: 2px solid #e5e7eb; display: flex; align-items: center; justify-content: center; font-size: 0.9rem; }
    .timeline-content { background: #fff; border-radius: 12px; padding: 1rem 1.25rem; box-shadow: 0 2px 8px rgba(0,0,0,0.05); margin-left: 0.5rem; }
    
    .seller-header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #fff; border-radius: 16px; padding: 2rem; }
    .seller-avatar { width: 80px; height: 80px; border-radius: 16px; object-fit: cover; border: 4px solid rgba(255,255,255,0.3); }
    .seller-initials-lg { width: 80px; height: 80px; border-radius: 16px; background: rgba(255,255,255,0.2); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 700; }
    
    .doc-card { background: #fff; border-radius: 12px; padding: 1rem; box-shadow: 0 2px 8px rgba(0,0,0,0.05); transition: all 0.2s; }
    .doc-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.1); }
    .doc-preview { width: 80px; height: 80px; border-radius: 8px; object-fit: cover; }
</style>

<div class="kyc-detail-page">
    <!-- Back Button -->
    <div class="mb-4">
        <a href="<?php echo e(route('admin.kyc.index')); ?>" class="btn btn-outline-secondary btn-sm">
            <i class="bi bi-arrow-left me-1"></i>Back to KYC List
        </a>
    </div>

    <!-- Seller Header -->
    <div class="seller-header mb-4">
        <div class="d-flex align-items-center gap-4">
            <?php if($seller->photo): ?>
                <img src="<?php echo e(asset('storage/' . $seller->photo)); ?>" class="seller-avatar" alt="Seller Photo">
            <?php else: ?>
                <div class="seller-initials-lg"><?php echo e(strtoupper(substr($seller->company_name ?? 'S', 0, 2))); ?></div>
            <?php endif; ?>
            <div>
                <h3 class="fw-bold mb-1"><?php echo e($seller->company_name); ?></h3>
                <p class="mb-2 opacity-75"><?php echo e($seller->user->name ?? 'N/A'); ?> • <?php echo e($seller->user->email ?? ''); ?></p>
                <div class="d-flex gap-2">
                    <span class="badge bg-white bg-opacity-20 text-white">
                        <i class="bi bi-<?php echo e($seller->subscription_id ? 'gem' : 'person'); ?> me-1"></i>
                        <?php echo e($seller->plan->name ?? 'Free Plan'); ?>

                    </span>
                    <?php if($seller->is_verified): ?>
                        <span class="badge bg-success"><i class="bi bi-patch-check-fill me-1"></i>KYC Verified</span>
                    <?php else: ?>
                        <span class="badge bg-warning text-dark"><i class="bi bi-clock me-1"></i>Pending Verification</span>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>

    <div class="row g-4">
        <!-- Left: Documents -->
        <div class="col-lg-6">
            <div class="card border-0 shadow-sm rounded-4">
                <div class="card-header bg-white border-0 pt-4 px-4">
                    <h5 class="fw-bold mb-0"><i class="bi bi-file-earmark-text me-2 text-primary"></i>Uploaded Documents</h5>
                </div>
                <div class="card-body p-4">
                    <?php $__empty_1 = true; $__currentLoopData = $documents; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $doc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            $isImage = preg_match('/\.(jpg|jpeg|png|webp)$/i', $doc->file_path);
                            $docLabels = [
                                'gst' => 'GST Certificate',
                                'pan' => 'PAN Card',
                                'aadhar' => 'Aadhar Card',
                                'incorporation' => 'Incorporation Certificate',
                                'photo' => 'Seller Photo',
                                'udyam' => 'Udyam Registration',
                                'iec' => 'IEC Certificate',
                                'other' => 'Additional Document'
                            ];
                            
                            $docValue = null;
                            if($doc->document_type == 'pan') $docValue = $seller->pan_number;
                            elseif($doc->document_type == 'gst') $docValue = $seller->gst;
                            elseif($doc->document_type == 'udyam') $docValue = $seller->udyam_number;
                            elseif($doc->document_type == 'iec') $docValue = $seller->iec_code;
                        ?>
                        <div class="doc-card mb-3 d-flex align-items-center gap-3">
                            <?php if($isImage): ?>
                                <img src="<?php echo e(asset('storage/' . $doc->file_path)); ?>" class="doc-preview" alt="Document" style="cursor: pointer" onclick="showPreview('<?php echo e(asset('storage/' . $doc->file_path)); ?>', 'image')">
                            <?php else: ?>
                                <div class="doc-preview bg-light d-flex align-items-center justify-content-center" style="cursor: pointer" onclick="showPreview('<?php echo e(asset('storage/' . $doc->file_path)); ?>', 'pdf')">
                                    <i class="bi bi-file-earmark-pdf fs-2 text-danger"></i>
                                </div>
                            <?php endif; ?>
                            <div class="flex-grow-1">
                                <h6 class="fw-bold mb-1">
                                    <?php echo e($docLabels[$doc->document_type] ?? ucfirst($doc->document_type)); ?>

                                    <?php if($docValue): ?>
                                        <span class="text-primary fs-6 ms-1">(<?php echo e($docValue); ?>)</span>
                                    <?php endif; ?>
                                </h6>
                                <small class="text-muted">Uploaded <?php echo e($doc->created_at->format('d M Y, h:i A')); ?></small>
                                <div class="mt-2">
                                    <?php if($doc->status == 'pending'): ?>
                                        <span class="badge bg-warning text-dark"><i class="bi bi-clock me-1"></i>Pending</span>
                                    <?php elseif($doc->status == 'approved'): ?>
                                        <span class="badge bg-success"><i class="bi bi-check-circle me-1"></i>Approved</span>
                                    <?php else: ?>
                                        <span class="badge bg-danger"><i class="bi bi-x-circle me-1"></i>Rejected</span>
                                        <?php if($doc->rejection_reason): ?>
                                            <div class="small text-danger mt-1">Reason: <?php echo e($doc->rejection_reason); ?></div>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <div class="d-flex gap-1">
                                <?php if($doc->status == 'pending'): ?>
                                    <form action="<?php echo e(route('admin.kyc.approve', $doc->id)); ?>" method="POST" class="d-inline">
                                        <?php echo csrf_field(); ?>
                                        <button type="submit" class="btn btn-success btn-sm rounded-3" title="Approve" onclick="return confirm('Approve this document?')">
                                            <i class="bi bi-check-lg"></i>
                                        </button>
                                    </form>
                                    <button type="button" class="btn btn-danger btn-sm rounded-3" title="Reject" 
                                            data-bs-toggle="modal" data-bs-target="#rejectModal" 
                                            data-url="<?php echo e(route('admin.kyc.reject', $doc->id)); ?>">
                                        <i class="bi bi-x-lg"></i>
                                    </button>
                                <?php else: ?>
                                    <form action="<?php echo e(route('admin.kyc.reset', $doc->id)); ?>" method="POST" class="d-inline">
                                        <?php echo csrf_field(); ?>
                                        <button type="submit" class="btn btn-warning btn-sm rounded-3" title="Reset to Pending" onclick="return confirm('Reset this document status to Pending?')">
                                            <i class="bi bi-arrow-counterclockwise"></i>
                                        </button>
                                    </form>
                                <?php endif; ?>
                                <a href="<?php echo e(asset('storage/' . $doc->file_path)); ?>" target="_blank" class="btn btn-outline-primary btn-sm rounded-3">
                                    <i class="bi bi-eye-fill"></i>
                                </a>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <div class="text-center py-4 text-muted">
                            <i class="bi bi-inbox fs-1 opacity-50 d-block mb-2"></i>
                            No documents uploaded yet.
                        </div>
                    <?php endif; ?>
                </div>
            </div>

            <!-- Seller Details -->
            <div class="card border-0 shadow-sm rounded-4 mt-4">
                <div class="card-header bg-white border-0 pt-4 px-4">
                    <h5 class="fw-bold mb-0"><i class="bi bi-person-lines-fill me-2 text-primary"></i>Seller Details</h5>
                </div>
                <div class="card-body p-4">
                    <table class="table table-borderless small mb-0">
                        <tr>
                            <td class="text-muted" style="width: 40%;">PAN Number</td>
                            <td class="fw-medium"><?php echo e($seller->pan_number ?? '—'); ?></td>
                        </tr>
                        <tr>
                            <td class="text-muted">GST Number</td>
                            <td class="fw-medium"><?php echo e($seller->gst ?? '—'); ?></td>
                        </tr>
                        <tr>
                            <td class="text-muted">Udyam Number</td>
                            <td class="fw-medium"><?php echo e($seller->udyam_number ?? '—'); ?></td>
                        </tr>
                        <tr>
                            <td class="text-muted">City</td>
                            <td class="fw-medium"><?php echo e($seller->city ?? '—'); ?></td>
                        </tr>
                        <tr>
                            <td class="text-muted">State</td>
                            <td class="fw-medium"><?php echo e($seller->state ?? '—'); ?></td>
                        </tr>
                        <tr>
                            <td class="text-muted">Joined</td>
                            <td class="fw-medium"><?php echo e($seller->created_at->format('d M Y')); ?></td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>

        <!-- Right: Timeline -->
        <div class="col-lg-6">
            <div class="card border-0 shadow-sm rounded-4">
                <div class="card-header bg-white border-0 pt-4 px-4">
                    <h5 class="fw-bold mb-0"><i class="bi bi-clock-history me-2 text-primary"></i>Activity Timeline</h5>
                </div>
                <div class="card-body p-4">
                    <?php if($activities->count() > 0): ?>
                        <div class="timeline">
                            <?php $__currentLoopData = $activities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $activity): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="timeline-item">
                                    <div class="timeline-icon">
                                        <i class="bi <?php echo e($activity->action_icon); ?>"></i>
                                    </div>
                                    <div class="timeline-content">
                                        <div class="d-flex justify-content-between align-items-start mb-1">
                                            <h6 class="fw-bold mb-0"><?php echo e($activity->action_label); ?></h6>
                                            <small class="text-muted"><?php echo e($activity->created_at->diffForHumans()); ?></small>
                                        </div>
                                        <p class="text-muted small mb-1">
                                            <?php if($activity->document): ?>
                                                <?php echo e(ucfirst($activity->document->document_type)); ?> document
                                            <?php endif; ?>
                                        </p>
                                        <?php if($activity->notes): ?>
                                            <div class="bg-light rounded-2 p-2 small">
                                                <i class="bi bi-quote me-1 text-muted"></i><?php echo e($activity->notes); ?>

                                            </div>
                                        <?php endif; ?>
                                        <div class="mt-2 small">
                                            <span class="badge bg-<?php echo e($activity->actor_type == 'admin' ? 'primary' : 'secondary'); ?> bg-opacity-10 text-<?php echo e($activity->actor_type == 'admin' ? 'primary' : 'secondary'); ?>">
                                                <i class="bi bi-<?php echo e($activity->actor_type == 'admin' ? 'shield-check' : 'person'); ?> me-1"></i>
                                                <?php echo e($activity->actor->name ?? 'System'); ?>

                                            </span>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    <?php else: ?>
                        <div class="text-center py-4 text-muted">
                            <i class="bi bi-clock-history fs-1 opacity-50 d-block mb-2"></i>
                            No activity recorded yet.
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<!-- 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>

<!-- 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>
    document.addEventListener('DOMContentLoaded', function() {
        // Single reject modal
        const rejectModal = document.getElementById('rejectModal');
        if (rejectModal) {
            rejectModal.addEventListener('show.bs.modal', function (event) {
                var button = event.relatedTarget;
                var url = button.getAttribute('data-url');
                document.getElementById('rejectForm').action = url;
            });
        }
    });

    // 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 shadow-sm" alt="Document" style="max-height: 70vh;">`;
        } else {
            container.innerHTML = `<embed src="${url}" type="application/pdf" width="100%" height="600px" class="rounded">`;
        }
        
        new bootstrap.Modal(document.getElementById('previewModal')).show();
    }
</script>
<?php $__env->stopPush(); ?>

<?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/show.blade.php ENDPATH**/ ?>