<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>عروض الأسعار<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>

<?php
$statusColors = [
    'requested' => '#2563EB', 'received' => '#059669', 'accepted' => '#047857',
    'rejected' => '#DC2626', 'expired' => '#6B7280',
];
$statusBgs = [
    'requested' => '#EFF6FF', 'received' => '#ECFDF5', 'accepted' => '#D1FAE5',
    'rejected' => '#FEE2E2', 'expired' => '#F3F4F6',
];
$statusLabels = [
    'requested' => 'مطلوب', 'received' => 'مستلم', 'accepted' => 'مقبول',
    'rejected' => 'مرفوض', 'expired' => 'منتهي',
];
?>

<!-- Filters -->
<div class="card" style="margin-bottom:20px;padding:15px;">
    <form method="GET" action="/procurement/quotes" style="display:flex;gap:10px;flex-wrap:wrap;align-items:end;">
        <div style="min-width:140px;">
            <label class="form-label" style="font-size:12px;">الحالة</label>
            <select name="status" class="form-select">
                <option value="">الكل</option>
                <?php foreach ($statusLabels as $val => $label): ?>
                <option value="<?= e($val) ?>" <?= ($status ?? '') === $val ? 'selected' : '' ?>><?= e($label) ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <button type="submit" class="btn btn-outline"><i data-lucide="search" style="width:16px;height:16px;vertical-align:middle;"></i> بحث</button>
        <a href="/procurement/quotes" class="btn btn-sm btn-outline" style="color:#6B7280;">مسح</a>
    </form>
</div>

<!-- Quotes Table -->
<?php if (!empty($quotes)): ?>
<div class="card">
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>رقم العرض</th>
                    <th>المورد</th>
                    <th>تاريخ الطلب</th>
                    <th>تاريخ الرد</th>
                    <th>المبلغ الإجمالي</th>
                    <th>الحالة</th>
                    <th>الإجراءات</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($quotes as $q): ?>
                <?php
                $st = $q['status'] ?? 'requested';
                $stColor = $statusColors[$st] ?? '#6B7280';
                $stBg = $statusBgs[$st] ?? '#F3F4F6';
                $stLabel = $statusLabels[$st] ?? $st;
                ?>
                <tr>
                    <td style="font-weight:600;">
                        <code style="font-size:12px;background:#F3F4F6;padding:2px 8px;border-radius:4px;"><?= e($q['quote_number'] ?? '') ?></code>
                    </td>
                    <td style="font-weight:600;"><?= e($q['supplier_name'] ?? '—') ?></td>
                    <td style="font-size:13px;"><?= e($q['request_date'] ?? '—') ?></td>
                    <td style="font-size:13px;"><?= e($q['response_date'] ?? '—') ?></td>
                    <td style="font-weight:700;direction:ltr;text-align:left;"><?= money($q['total_amount'] ?? 0) ?></td>
                    <td>
                        <span style="display:inline-block;padding:3px 10px;border-radius:10px;font-size:12px;font-weight:600;background:<?= $stBg ?>;color:<?= $stColor ?>;">
                            <?= e($stLabel) ?>
                        </span>
                    </td>
                    <td>
                        <a href="/procurement/quotes/<?= (int) $q['id'] ?>" class="btn btn-sm btn-outline" style="font-size:12px;padding:4px 10px;">
                            <i data-lucide="eye" style="width:13px;height:13px;vertical-align:middle;"></i> عرض
                        </a>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
<?php else: ?>
<div class="card" style="padding:60px 20px;text-align:center;">
    <div style="margin-bottom:15px;">
        <i data-lucide="file-text" style="width:48px;height:48px;color:#D1D5DB;"></i>
    </div>
    <h3 style="color:#6B7280;margin:0 0 8px;">لا توجد عروض أسعار</h3>
    <p style="color:#9CA3AF;font-size:14px;margin:0;">لم يتم العثور على عروض أسعار مطابقة.</p>
</div>
<?php endif; ?>

<script>document.addEventListener('DOMContentLoaded', function() { if (typeof lucide !== 'undefined') lucide.createIcons(); });</script>
<?php $__template->endSection(); ?>
