

<?php $__env->startSection('title', 'Manage Sellers'); ?>

<?php $__env->startSection('admin-content'); ?>
<style>
    /* Specific Seller Styles */
    .seller-page .company-logo {
        width: 50px;
        height: 50px;
        border-radius: 12px;
        background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
        border: 2px solid #fff;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    }
    .seller-page .company-logo img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
    
    .seller-page .status-badge.verified {
        background: #dcfce7;
        color: #166534;
    }

    .seller-page .plan-badge {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 6px 14px;
        border-radius: 8px;
        font-size: 0.8rem;
        font-weight: 600;
        background: #e3f2fd;
        color: #1565c0;
    }
    .seller-page .plan-badge.free {
        background: #f5f5f5;
        color: #616161;
    }
</style>

<div class="seller-page">
    <!-- Page Header -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="fw-bold mb-1">Seller Management</h4>
            <p class="text-muted mb-0 small">Review KYC documents and manage seller accounts</p>
        </div>
        <div class="d-flex gap-2">
            <button class="btn btn-light border shadow-sm">
                <i class="bi bi-download me-1"></i> Export
            </button>
            <button class="btn btn-primary shadow-sm">
                <i class="bi bi-plus-lg me-1"></i> Add Seller
            </button>
        </div>
    </div>

    <!-- Stats Cards -->
    <div class="row g-4 mb-4">
        <div class="col-lg-3 col-md-6">
            <div class="stat-card stat-card-primary d-flex align-items-center gap-3">
                <div class="stat-icon primary">
                    <i class="bi bi-shop"></i>
                </div>
                <div>
                    <div class="stat-value"><?php echo e($totalSellers); ?></div>
                    <div class="stat-label">Total Sellers</div>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-6">
            <div class="stat-card stat-card-success d-flex align-items-center gap-3">
                <div class="stat-icon success">
                    <i class="bi bi-patch-check-fill"></i>
                </div>
                <div>
                    <div class="stat-value"><?php echo e($verifiedSellers); ?></div>
                    <div class="stat-label">Verified Sellers</div>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-6">
            <div class="stat-card stat-card-warning d-flex align-items-center gap-3">
                <div class="stat-icon warning">
                    <i class="bi bi-hourglass-split"></i>
                </div>
                <div>
                    <div class="stat-value"><?php echo e($pendingSellers); ?></div>
                    <div class="stat-label">Pending KYC</div>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-6">
            <div class="stat-card stat-card-info d-flex align-items-center gap-3">
                <div class="stat-icon info">
                    <i class="bi bi-graph-up-arrow"></i>
                </div>
                <div>
                    <div class="stat-value"><?php echo e($newSellersToday); ?></div>
                    <div class="stat-label">New Today</div>
                </div>
            </div>
        </div>
    </div>

    <!-- Filters -->
    <div class="filter-card mb-4">
        <form action="<?php echo e(route('admin.sellers')); ?>" method="GET" class="row g-3 align-items-end">
            <div class="col-lg-4 col-md-6">
                <label class="form-label small fw-bold text-muted mb-1">
                    <i class="bi bi-search me-1"></i> Search
                </label>
                <input type="text" name="q" class="form-control form-control-lg" 
                       placeholder="Company name, email, phone..." 
                       value="<?php echo e(request('q')); ?>"
                       style="border-radius: 10px;">
            </div>
            <div class="col-lg-3 col-md-6">
                <label class="form-label small fw-bold text-muted mb-1">
                    <i class="bi bi-shield-check me-1"></i> KYC Status
                </label>
                <select name="status" class="form-select form-select-lg" style="border-radius: 10px;">
                    <option value="all">All Status</option>
                    <option value="verified" <?php echo e(request('status') == 'verified' ? 'selected' : ''); ?>>✓ Verified Only</option>
                    <option value="pending" <?php echo e(request('status') == 'pending' ? 'selected' : ''); ?>>⏳ Pending Only</option>
                </select>
            </div>
            <div class="col-lg-3 col-md-6">
                <label class="form-label small fw-bold text-muted mb-1">
                    <i class="bi bi-credit-card me-1"></i> Subscription
                </label>
                <select name="plan" class="form-select form-select-lg" style="border-radius: 10px;">
                    <option value="all">All Plans</option>
                    <option value="free" <?php echo e(request('plan') == 'free' ? 'selected' : ''); ?>>Free Tier</option>
                    <?php $__currentLoopData = $plans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $plan): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($plan->id); ?>" <?php echo e(request('plan') == $plan->id ? 'selected' : ''); ?>><?php echo e($plan->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="col-lg-2 col-md-6">
                <button type="submit" class="btn btn-primary btn-lg w-100" style="border-radius: 10px;">
                    <i class="bi bi-funnel me-1"></i> Filter
                </button>
            </div>
        </form>
    </div>

    <!-- Sellers Table -->
    <div class="data-table">
        <div class="table-responsive">
            <table class="table mb-0">
                <thead>
                    <tr>
                        <th class="ps-4">Company Information</th>
                        <th>Owner / Contact</th>
                        <th class="text-center">Status</th>
                        <th class="text-center">KYC Status</th>
                        <th class="text-center">Subscription</th>
                        <th class="text-center">Products</th>
                        <th class="text-center">Joined</th>
                        <th class="text-end pe-4">Quick 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; ?>
                        <tr>
                            <td class="ps-4">
                                <div class="d-flex align-items-center gap-3">
                                    <div class="company-logo">
                                        <?php if($seller->logo): ?>
                                            <img src="<?php echo e(asset('storage/' . $seller->logo)); ?>" alt="Logo">
                                        <?php else: ?>
                                            <i class="bi bi-building text-secondary fs-5"></i>
                                        <?php endif; ?>
                                    </div>
                                    <div>
                                        <h6 class="fw-bold mb-0 text-dark"><?php echo e($seller->company_name); ?></h6>
                                        <small class="text-muted">
                                            <i class="bi bi-geo-alt"></i> <?php echo e($seller->city ?? 'N/A'); ?>, <?php echo e($seller->country ?? 'India'); ?>

                                        </small>
                                    </div>
                                </div>
                            </td>
                            <td>
                                <div class="fw-medium text-dark"><?php echo e($seller->user->name); ?></div>
                                <small class="text-muted"><?php echo e($seller->user->email); ?></small>
                                <?php if($seller->mobile): ?>
                                    <br><small class="text-muted"><i class="bi bi-phone"></i> <?php echo e($seller->mobile); ?></small>
                                <?php endif; ?>
                            </td>
                            <td class="text-center">
                                <?php if($seller->is_active): ?>
                                    <span class="badge bg-success bg-opacity-10 text-success px-3 py-2">
                                        <i class="bi bi-check-circle-fill me-1"></i>Active
                                    </span>
                                <?php else: ?>
                                    <span class="badge bg-secondary bg-opacity-10 text-secondary px-3 py-2">
                                        <i class="bi bi-pause-circle-fill me-1"></i>Inactive
                                    </span>
                                <?php endif; ?>
                            </td>
                            <td class="text-center">
                                <?php if($seller->is_verified): ?>
                                    <span class="status-badge verified">
                                        <i class="bi bi-check-circle-fill"></i> Verified
                                    </span>
                                <?php else: ?>
                                    <span class="status-badge pending">
                                        <i class="bi bi-clock-fill"></i> Pending
                                    </span>
                                <?php endif; ?>
                            </td>
                            <td class="text-center">
                                <?php if($seller->subscription && $seller->subscription->plan): ?>
                                    <span class="plan-badge">
                                        <i class="bi bi-gem"></i> <?php echo e($seller->subscription->plan->name ?? 'Plan'); ?>

                                    </span>
                                <?php else: ?>
                                    <span class="plan-badge free">
                                        <i class="bi bi-person"></i> Free
                                    </span>
                                <?php endif; ?>
                            </td>
                            <td class="text-center">
                                <span class="fw-bold text-dark"><?php echo e($seller->products_count ?? $seller->products()->count()); ?></span>
                                <small class="text-muted d-block">products</small>
                            </td>
                            <td class="text-center">
                                <span class="text-dark"><?php echo e($seller->created_at->format('d M Y')); ?></span>
                                <small class="text-muted d-block"><?php echo e($seller->created_at->diffForHumans()); ?></small>
                            </td>
                            <td class="text-end pe-4">
                                <div class="d-flex gap-1 justify-content-end">
                                    <?php if($seller->slug): ?>
                                        <a href="<?php echo e(route('seller.public.profile', $seller->slug)); ?>" target="_blank" 
                                           class="action-btn" title="View Profile" data-bs-toggle="tooltip">
                                            <i class="bi bi-eye"></i>
                                        </a>
                                    <?php endif; ?>
                                    
                                    <a href="<?php echo e(route('admin.sellers.edit', $seller->id)); ?>" 
                                       class="action-btn primary" title="Edit Seller" data-bs-toggle="tooltip">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                    
                                    <?php if(!$seller->is_verified): ?>
                                        <button type="button" class="action-btn success" title="Verify KYC" 
                                                data-bs-toggle="modal" data-bs-target="#kycModal<?php echo e($seller->id); ?>">
                                            <i class="bi bi-shield-check"></i>
                                        </button>
                                    <?php else: ?>
                                        <form action="<?php echo e(route('admin.sellers.revoke', $seller->id)); ?>" method="POST" class="d-inline">
                                            <?php echo csrf_field(); ?>
                                            <button type="submit" class="action-btn warning" title="Revoke Verification"
                                                    onclick="return confirm('Revoke verification for this seller?')">
                                                <i class="bi bi-shield-x"></i>
                                            </button>
                                        </form>
                                    <?php endif; ?>
                                    
                                    <form action="<?php echo e(route('admin.users.toggle-status', $seller->user->id)); ?>" method="POST" class="d-inline">
                                        <?php echo csrf_field(); ?>
                                        <button type="submit" class="action-btn <?php echo e($seller->user->is_active ? 'danger' : 'success'); ?>" 
                                                title="<?php echo e($seller->user->is_active ? 'Block Login' : 'Unblock Login'); ?>"
                                                data-bs-toggle="tooltip">
                                            <i class="bi bi-<?php echo e($seller->user->is_active ? 'person-x' : 'person-check'); ?>"></i>
                                        </button>
                                    </form>
                                    
                                    <form action="<?php echo e(route('admin.sellers.toggle-status', $seller->id)); ?>" method="POST" class="d-inline">
                                        <?php echo csrf_field(); ?>
                                        <button type="submit" class="action-btn <?php echo e($seller->is_active ? 'warning' : 'success'); ?>" 
                                                title="<?php echo e($seller->is_active ? 'Hide from Frontend' : 'Show on Frontend'); ?>"
                                                data-bs-toggle="tooltip">
                                            <i class="bi bi-<?php echo e($seller->is_active ? 'eye-slash' : 'eye'); ?>"></i>
                                        </button>
                                    </form>
                                    
                                    <?php if($seller->delete_requested_at): ?>
                                        <form action="<?php echo e(route('admin.sellers.restore', $seller->id)); ?>" method="POST" class="d-inline">
                                            <?php echo csrf_field(); ?>
                                            <button type="submit" class="action-btn success" title="Restore Account (Cancel Deletion)" 
                                                    data-bs-toggle="tooltip">
                                                <i class="bi bi-arrow-counterclockwise"></i>
                                            </button>
                                        </form>
                                        <span class="badge bg-danger bg-opacity-10 text-danger ms-1" title="Scheduled for deletion on <?php echo e($seller->delete_requested_at->addMonths(\App\Models\Setting::getValue('seller_retention_period', 3))->format('d M Y')); ?>" data-bs-toggle="tooltip">
                                            <i class="bi bi-clock-history"></i> Deleting
                                        </span>
                                    <?php else: ?>
                                        <button type="button" class="action-btn danger" title="Schedule Deletion"
                                                data-bs-toggle="modal" data-bs-target="#deleteModal<?php echo e($seller->id); ?>">
                                            <i class="bi bi-trash3"></i>
                                        </button>
                                    <?php endif; ?>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="8" class="text-center py-5">
                                <div class="py-4">
                                    <i class="bi bi-search 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">Try adjusting your search or filter criteria</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;">
                <div class="d-flex justify-content-between align-items-center">
                    <small class="text-muted">
                        Showing <?php echo e($sellers->firstItem()); ?> to <?php echo e($sellers->lastItem()); ?> of <?php echo e($sellers->total()); ?> sellers
                    </small>
                    <?php echo e($sellers->appends(request()->query())->links()); ?>

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

<!-- KYC Modals -->
<?php $__currentLoopData = $sellers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $seller): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <?php if(!$seller->is_verified): ?>
    <div class="modal fade" id="kycModal<?php echo e($seller->id); ?>" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content border-0 shadow-lg" style="border-radius: 20px;">
                <div class="modal-header border-0 pb-0">
                    <div>
                        <h5 class="modal-title fw-bold">KYC Verification</h5>
                        <p class="text-muted small mb-0"><?php echo e($seller->company_name); ?></p>
                    </div>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="row g-4">
                        <div class="col-md-6">
                            <div class="p-4 bg-light rounded-4">
                                <div class="d-flex align-items-center gap-2 mb-3">
                                    <i class="bi bi-file-earmark-text text-primary fs-4"></i>
                                    <h6 class="fw-bold mb-0">GST Document</h6>
                                </div>
                                <?php if($seller->gst_doc): ?>
                                    <div class="ratio ratio-4x3 bg-white border rounded-3 mb-3">
                                        <iframe src="<?php echo e(asset('storage/' . $seller->gst_doc)); ?>"></iframe>
                                    </div>
                                    <a href="<?php echo e(asset('storage/' . $seller->gst_doc)); ?>" target="_blank" 
                                       class="btn btn-outline-primary btn-sm w-100 rounded-3">
                                        <i class="bi bi-box-arrow-up-right me-1"></i> Open Full Size
                                    </a>
                                <?php else: ?>
                                    <div class="text-center py-5 text-muted bg-white rounded-3">
                                        <i class="bi bi-file-earmark-x fs-1 d-block mb-2 opacity-50"></i>
                                        <p class="mb-0">Not Uploaded</p>
                                    </div>
                                <?php endif; ?>
                                <div class="mt-3 p-3 bg-white rounded-3">
                                    <small class="text-muted d-block">GST Number</small>
                                    <span class="fw-bold font-monospace"><?php echo e($seller->gst ?? 'Not Provided'); ?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="p-4 bg-light rounded-4">
                                <div class="d-flex align-items-center gap-2 mb-3">
                                    <i class="bi bi-file-earmark-text text-info fs-4"></i>
                                    <h6 class="fw-bold mb-0">IEC Document</h6>
                                </div>
                                <?php if($seller->iec_doc): ?>
                                    <div class="ratio ratio-4x3 bg-white border rounded-3 mb-3">
                                        <iframe src="<?php echo e(asset('storage/' . $seller->iec_doc)); ?>"></iframe>
                                    </div>
                                    <a href="<?php echo e(asset('storage/' . $seller->iec_doc)); ?>" target="_blank" 
                                       class="btn btn-outline-info btn-sm w-100 rounded-3">
                                        <i class="bi bi-box-arrow-up-right me-1"></i> Open Full Size
                                    </a>
                                <?php else: ?>
                                    <div class="text-center py-5 text-muted bg-white rounded-3">
                                        <i class="bi bi-file-earmark-x fs-1 d-block mb-2 opacity-50"></i>
                                        <p class="mb-0">Not Uploaded</p>
                                    </div>
                                <?php endif; ?>
                                <div class="mt-3 p-3 bg-white rounded-3">
                                    <small class="text-muted d-block">IEC Number</small>
                                    <span class="fw-bold font-monospace"><?php echo e($seller->iec ?? 'Not Provided'); ?></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer border-0 pt-0">
                    <form action="<?php echo e(route('admin.sellers.reject', $seller->id)); ?>" method="POST">
                        <?php echo csrf_field(); ?>
                        <button type="submit" class="btn btn-outline-danger rounded-3 px-4" 
                                onclick="return confirm('Reject this seller\'s KYC?')">
                            <i class="bi bi-x-lg me-1"></i> Reject
                        </button>
                    </form>
                    <form action="<?php echo e(route('admin.sellers.verify', $seller->id)); ?>" method="POST">
                        <?php echo csrf_field(); ?>
                        <button type="submit" class="btn btn-success rounded-3 px-4">
                            <i class="bi bi-check-lg me-1"></i> Approve & Verify
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <?php endif; ?>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


<?php $__currentLoopData = $sellers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $seller): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<div class="modal fade" id="deleteModal<?php echo e($seller->id); ?>" 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.sellers.delete', $seller->id)); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <?php echo method_field('DELETE'); ?>
                <div class="modal-header border-0 bg-danger bg-opacity-10">
                    <div class="d-flex align-items-center gap-2">
                        <div class="rounded-circle bg-danger bg-opacity-25 p-2">
                            <i class="bi bi-hourglass-split text-danger fs-5"></i>
                        </div>
                        <div>
                            <h5 class="modal-title fw-bold text-danger mb-0">Schedule Account Deletion</h5>
                            <small class="text-muted">Grace Period Applies</small>
                        </div>
                    </div>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body p-4">
                    <div class="alert alert-warning border-0 mb-4">
                        <strong class="d-block mb-2">⚠️ Account will be deleted in <?php echo e(\App\Models\Setting::getValue('seller_retention_period', 3)); ?> months.</strong>
                        <p class="mb-0 small">This action initiates the deletion process. You can restore the account within the grace period.</p>
                        <ul class="mb-0 ps-3 mt-2 small">
                            <li>Seller: <strong><?php echo e($seller->company_name); ?></strong></li>
                            <li>Products: <?php echo e($seller->products()->count()); ?></li>
                        </ul>
                    </div>
                    
                    <div class="bg-light rounded-3 p-3 mb-3">
                        <label class="form-label fw-bold small text-danger mb-2">
                            <i class="bi bi-shield-exclamation me-1"></i>
                            Type <code class="bg-danger text-white px-2 py-1 rounded">DELETE-<?php echo e($seller->id); ?></code> to confirm:
                        </label>
                        <input type="text" name="confirmation_code" class="form-control form-control-lg text-center font-monospace" 
                               placeholder="DELETE-<?php echo e($seller->id); ?>" required
                               autocomplete="off" spellcheck="false">
                    </div>
                </div>
                <div class="modal-footer border-0 pt-0">
                    <button type="button" class="btn btn-light rounded-3 px-4" data-bs-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-danger rounded-3 px-4">
                        <i class="bi bi-trash3-fill me-1"></i> Schedule Deletion
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

<script>
    // Initialize tooltips
    document.addEventListener('DOMContentLoaded', function() {
        var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
        tooltipTriggerList.map(function (el) {
            return 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/sellers/index.blade.php ENDPATH**/ ?>