<?php $this->start('body');
    $stat     = $this->v('status');
    $statuses = ['DRAFT','OPEN','EVALUATING','AWARDED','CLOSED','CANCELLED'];
?>

<div class="d-flex align-items-center justify-content-between mb-3">
    <h5 class="mb-0" style="font-weight:600;"><i class="fas fa-file-signature me-2 text-muted"></i>Sourcing · RFQs</h5>
    <a href="<?= PROOT; ?>GoodsClientPos" class="btn btn-sm btn-outline-secondary"><i class="fas fa-file-contract me-1"></i> Client POs</a>
</div>

<div class="mb-2 d-flex flex-wrap gap-1">
    <a href="<?= PROOT; ?>GoodsRfq" class="badge <?= $stat===''?'bg-dark':'bg-light text-muted'; ?>" style="text-decoration:none;padding:.35em .6em;">All</a>
    <?php foreach ($statuses as $s): ?>
        <a href="<?= PROOT; ?>GoodsRfq?status=<?= $s; ?>" class="badge <?= $stat===$s?'bg-dark':'bg-light text-muted'; ?>" style="text-decoration:none;padding:.35em .6em;text-transform:capitalize;">
            <?= htmlspecialchars(strtolower($s)); ?>
        </a>
    <?php endforeach; ?>
</div>

<div class="card border-0 shadow-sm">
    <div class="table-responsive">
        <table class="table table-sm mb-0 align-middle">
            <thead class="table-light">
                <tr>
                    <th>RFQ #</th><th>Client PO</th><th>Customer</th><th>Project</th>
                    <th class="text-end">Contract</th><th>Suppliers</th><th>Awarded lines</th><th>Status</th><th></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($this->data['rows'] as $r):
                    $sc = ['DRAFT'=>'bg-light text-muted','OPEN'=>'bg-info text-white','EVALUATING'=>'bg-warning text-dark','AWARDED'=>'bg-success','CLOSED'=>'bg-secondary','CANCELLED'=>'bg-secondary'][$r['status']] ?? 'bg-light text-muted';
                ?>
                    <tr>
                        <td><a href="<?= PROOT; ?>GoodsRfq/view/<?= (int)$r['c0d']; ?>" class="text-decoration-none"><strong><?= htmlspecialchars($r['rfq_no']); ?></strong></a></td>
                        <td class="text-muted small"><?= htmlspecialchars($r['client_po_no']); ?></td>
                        <td><?= htmlspecialchars($r['customer_name']); ?></td>
                        <td class="text-muted small"><?= htmlspecialchars($r['project_no']); ?></td>
                        <td class="text-end"><?= htmlspecialchars($r['currency']); ?> <?= number_format((float)$r['cpo_total']); ?></td>
                        <td class="text-muted"><?= (int)$r['quote_count']; ?></td>
                        <td class="text-muted"><?= (int)$r['awarded_count']; ?></td>
                        <td><span class="badge <?= $sc; ?>" style="text-transform:capitalize;"><?= htmlspecialchars(strtolower($r['status'])); ?></span></td>
                        <td class="text-end"><a href="<?= PROOT; ?>GoodsRfq/view/<?= (int)$r['c0d']; ?>" class="btn btn-sm btn-outline-secondary"><i class="fas fa-arrow-right"></i></a></td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($this->data['rows'])): ?>
                    <tr><td colspan="9" class="text-center text-muted py-4">No RFQs yet. Start one from a <a href="<?= PROOT; ?>GoodsClientPos">Client PO</a>.</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

<?php $this->end(); ?>
