

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

<?php $__env->startSection('admin-content'); ?>
<style>
    /* Specific RFQ Styles */
    .rfqs-page .buyer-avatar {
        width: 40px;
        height: 40px;
        border-radius: 10px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-weight: 700;
        font-size: 0.9rem;
    }
    .rfqs-page .budget-tag { font-weight: 700; color: #2e7d32; }
    .rfqs-page .budget-negotiable { color: #888; font-style: italic; font-size: 0.85rem; }
    .rfqs-page .rfq-title { font-weight: 600; color: #1a1a2e; max-width: 280px; }
    .rfqs-page .rfq-id { font-size: 0.75rem; color: #888; }
    .rfqs-page .category-badge { display: inline-flex; align-items: center; gap: 4px; padding: 5px 12px; border-radius: 8px; font-size: 0.78rem; font-weight: 500; background: #f0f4ff; color: #3b5998; }
</style>

<div class="rfqs-page">
    <!-- Page Header -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="fw-bold mb-1">RFQ Management</h4>
            <p class="text-muted mb-0 small">Monitor and respond to buyer requests for quotations</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>
        </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-file-earmark-text"></i>
                </div>
                <div>
                    <div class="stat-value"><?php echo e($totalRfqs); ?></div>
                    <div class="stat-label">Total RFQs</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-check-circle-fill"></i>
                </div>
                <div>
                    <div class="stat-value"><?php echo e($openRfqs); ?></div>
                    <div class="stat-label">Open Requests</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 secondary">
                    <i class="bi bi-archive-fill"></i>
                </div>
                <div>
                    <div class="stat-value"><?php echo e($closedRfqs); ?></div>
                    <div class="stat-label">Closed</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-clock-history"></i>
                </div>
                <div>
                    <div class="stat-value"><?php echo e($newRfqsToday); ?></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.rfqs')); ?>" method="GET" class="row g-3 align-items-end">
            <div class="col-lg-5 col-md-6">
                <label class="form-label small fw-bold text-muted mb-1">
                    <i class="bi bi-search me-1"></i> Search RFQs
                </label>
                <input type="text" name="q" class="form-control form-control-lg" 
                       placeholder="RFQ title, buyer name, description..." 
                       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-folder me-1"></i> Category
                </label>
                <select name="category" class="form-select form-select-lg" style="border-radius: 10px;">
                    <option value="all">All Categories</option>
                    <?php if(isset($categories)): ?>
                        <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($category->id); ?>" <?php echo e(request('category') == $category->id ? 'selected' : ''); ?>>
                                <?php echo e($category->name); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php endif; ?>
                </select>
            </div>
            <div class="col-lg-2 col-md-6">
                <label class="form-label small fw-bold text-muted mb-1">
                    <i class="bi bi-filter me-1"></i> Status
                </label>
                <select name="status" class="form-select form-select-lg" style="border-radius: 10px;">
                    <option value="all">All Status</option>
                    <option value="open" <?php echo e(request('status') == 'open' ? 'selected' : ''); ?>>✓ Open</option>
                    <option value="closed" <?php echo e(request('status') == 'closed' ? 'selected' : ''); ?>>Closed</option>
                </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>

    <!-- RFQs Table -->
    <div class="data-table">
        <div class="table-responsive">
            <table class="table mb-0">
                <thead>
                    <tr>
                        <th class="ps-4">RFQ Details</th>
                        <th>Buyer</th>
                        <th>Category</th>
                        <th>Budget</th>
                        <th>Quantity</th>
                        <th class="text-center">Status</th>
                        <th>Posted</th>
                        <th class="text-end pe-4">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $rfqs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rfq): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td class="ps-4">
                                <div class="rfq-title text-truncate"><?php echo e($rfq->title); ?></div>
                                <div class="rfq-id">ID: #<?php echo e($rfq->id); ?></div>
                            </td>
                            <td>
                                <?php if($rfq->buyer && $rfq->buyer->user): ?>
                                    <div class="d-flex align-items-center gap-2">
                                        <div class="buyer-avatar">
                                            <?php echo e(strtoupper(substr($rfq->buyer->user->name, 0, 1))); ?>

                                        </div>
                                        <div>
                                            <div class="fw-medium small"><?php echo e($rfq->buyer->user->name); ?></div>
                                            <small class="text-muted"><?php echo e($rfq->buyer->user->email); ?></small>
                                        </div>
                                    </div>
                                <?php else: ?>
                                    <span class="text-muted">Unknown Buyer</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <span class="category-badge">
                                    <i class="bi bi-tag"></i>
                                    <?php echo e($rfq->category->name ?? 'Uncategorized'); ?>

                                </span>
                            </td>
                            <td>
                                <?php if($rfq->budget): ?>
                                    <div class="budget-tag">₹<?php echo e(number_format($rfq->budget, 0)); ?></div>
                                <?php else: ?>
                                    <span class="budget-negotiable">Negotiable</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <?php if($rfq->quantity): ?>
                                    <span class="fw-medium"><?php echo e($rfq->quantity); ?> <?php echo e($rfq->unit ?? 'units'); ?></span>
                                <?php else: ?>
                                    <span class="text-muted">-</span>
                                <?php endif; ?>
                            </td>
                            <td class="text-center">
                                <?php if($rfq->status == 'open'): ?>
                                    <span class="status-badge open">
                                        <i class="bi bi-circle-fill" style="font-size: 0.5rem;"></i> Open
                                    </span>
                                <?php else: ?>
                                    <span class="status-badge closed">
                                        <i class="bi bi-check-circle"></i> Closed
                                    </span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <div class="text-dark small"><?php echo e($rfq->created_at->format('d M Y')); ?></div>
                                <small class="text-muted"><?php echo e($rfq->created_at->diffForHumans()); ?></small>
                            </td>
                            <td class="text-end pe-4">
                                <div class="d-flex gap-1 justify-content-end">
                                    <button type="button" class="action-btn primary" title="View Details" 
                                            data-bs-toggle="modal" data-bs-target="#rfqModal<?php echo e($rfq->id); ?>">
                                        <i class="bi bi-eye"></i>
                                    </button>
                                    

                                    
                                    <form action="<?php echo e(route('admin.rfqs.delete', $rfq->id)); ?>" method="POST" class="d-inline" 
                                          onsubmit="return confirm('Delete this RFQ permanently?')">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                        <button type="submit" class="action-btn danger" title="Delete" 
                                                data-bs-toggle="tooltip">
                                            <i class="bi bi-trash"></i>
                                        </button>
                                    </form>
                                </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-file-earmark-text fs-1 text-muted opacity-50 d-block mb-3"></i>
                                    <h5 class="fw-bold text-muted">No RFQs Found</h5>
                                    <p class="text-muted small mb-0">No buyer requests match your criteria</p>
                                </div>
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        
        <?php if($rfqs->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($rfqs->firstItem()); ?> to <?php echo e($rfqs->lastItem()); ?> of <?php echo e($rfqs->total()); ?> RFQs
                    </small>
                    <?php echo e($rfqs->appends(request()->query())->links()); ?>

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

<!-- RFQ Details Modals -->
<?php $__currentLoopData = $rfqs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rfq): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <div class="modal fade" id="rfqModal<?php echo e($rfq->id); ?>" 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: 20px;">
                <div class="modal-header border-0 pb-0">
                    <div>
                        <h5 class="modal-title fw-bold">RFQ Details</h5>
                        <p class="text-muted small mb-0">Request #<?php echo e($rfq->id); ?></p>
                    </div>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="bg-light rounded-4 p-4 mb-4">
                        <h5 class="fw-bold mb-3"><?php echo e($rfq->title); ?></h5>
                        <p class="text-muted mb-0"><?php echo e($rfq->description ?? 'No description provided.'); ?></p>
                    </div>
                    
                    <div class="row g-4">
                        <div class="col-md-6">
                            <div class="p-3 border rounded-3">
                                <div class="d-flex align-items-center gap-3 mb-3">
                                    <div class="buyer-avatar" style="width: 48px; height: 48px;">
                                        <?php echo e(strtoupper(substr($rfq->buyer->user->name ?? 'U', 0, 1))); ?>

                                    </div>
                                    <div>
                                        <div class="fw-bold"><?php echo e($rfq->buyer->user->name ?? 'Unknown'); ?></div>
                                        <small class="text-muted"><?php echo e($rfq->buyer->user->email ?? ''); ?></small>
                                    </div>
                                </div>
                                <?php if($rfq->buyer && $rfq->buyer->user && $rfq->buyer->user->phone): ?>
                                    <div class="small text-muted">
                                        <i class="bi bi-telephone me-1"></i> <?php echo e($rfq->buyer->user->phone); ?>

                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="row g-3">
                                <div class="col-6">
                                    <div class="p-3 bg-light rounded-3">
                                        <small class="text-muted d-block mb-1">Category</small>
                                        <span class="fw-bold"><?php echo e($rfq->category->name ?? 'N/A'); ?></span>
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="p-3 bg-light rounded-3">
                                        <small class="text-muted d-block mb-1">Budget</small>
                                        <span class="fw-bold text-success">
                                            <?php echo e($rfq->budget ? '₹' . number_format($rfq->budget, 0) : 'Negotiable'); ?>

                                        </span>
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="p-3 bg-light rounded-3">
                                        <small class="text-muted d-block mb-1">Quantity</small>
                                        <span class="fw-bold"><?php echo e($rfq->quantity ?? 'Not specified'); ?></span>
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="p-3 bg-light rounded-3">
                                        <small class="text-muted d-block mb-1">Status</small>
                                        <span class="badge <?php echo e($rfq->status == 'open' ? 'bg-success' : 'bg-secondary'); ?>">
                                            <?php echo e(ucfirst($rfq->status)); ?>

                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer border-0 pt-0">
                    <button type="button" class="btn btn-light rounded-3" data-bs-dismiss="modal">Close</button>

                </div>
            </div>
        </div>
    </div>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

<script>
    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/rfqs/index.blade.php ENDPATH**/ ?>