<?php $this->start('body');
    $rows  = $this->data['rows']  ?? [];
    $types = $this->data['types'] ?? [];
    $statusChip = [
        'DRAFT'      => ['#F1F5F9','#334155','Draft'],
        'SUBMITTED'  => ['#E8EEF3','#7A8BA1','Submitted'],
        'APPROVED'   => ['#EAF2E8','#3F5C43','Approved'],
        'ISSUED'     => ['#EDE7DC','#5B4F3C','Issued'],
        'PV_DRAFTED' => ['#FEF3E7','#8B6914','PV drafted'],
        'SCHEDULED'  => ['#E8EEF3','#7A8BA1','Scheduled'],
        'PAID'       => ['#EAF2E8','#3F5C43','Paid'],
        'DECLINED'   => ['#F5EAE1','#C48579','Declined'],
    ];
?>

<div class="d-flex align-items-center justify-content-between mb-3">
    <div>
        <h5 class="mb-0" style="font-weight:600;"><i class="fas fa-list me-2 text-muted"></i>My cash requests</h5>
        <div class="text-muted small mt-1" style="font-size:.72rem;">
            Everything you've raised — pending approval, approved awaiting cash, paid, or retired.
        </div>
    </div>
    <a href="<?= PROOT; ?>CashRequests/new" class="btn btn-sm" style="background:#7A9E7E;border-color:#7A9E7E;color:#fff;font-weight:600;">
        <i class="fas fa-plus me-1"></i>New cash request
    </a>
</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>LPO #</th>
                    <th>Type</th>
                    <th>Project</th>
                    <th class="text-end">Amount</th>
                    <th>Purpose</th>
                    <th>Status</th>
                    <th class="text-end">When</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($rows as $r):
                    $lbl = $types[$r['lpo_type']]['label'] ?? $r['lpo_type'];
                    $ico = $types[$r['lpo_type']]['icon']  ?? 'fas fa-wallet';
                    $sc  = $statusChip[$r['cash_out_status']] ?? ['#F1F5F9','#334155', htmlspecialchars(strtolower(str_replace('_',' ', $r['cash_out_status'])))];
                ?>
                    <tr>
                        <td><a href="<?= PROOT; ?>Lpos/view/<?= (int)$r['c0d']; ?>" class="text-decoration-none"><strong style="color:#7A8BA1;"><?= htmlspecialchars($r['lpo_no']); ?></strong></a></td>
                        <td class="small"><i class="<?= $ico; ?> me-1" style="color:#94A3B8;"></i><?= htmlspecialchars($lbl); ?></td>
                        <td class="small text-muted">
                            <?php if (!empty($r['project_no'])): ?>
                                <?= htmlspecialchars($r['project_no']); ?>
                            <?php else: ?>
                                <span class="text-muted"><em>Central</em></span>
                            <?php endif; ?>
                        </td>
                        <td class="text-end" style="font-weight:600;color:#334155;"><?= htmlspecialchars($r['currency']); ?> <?= number_format((float)$r['amount']); ?></td>
                        <td class="small text-muted" style="max-width:280px;color:#64748B;"><?= htmlspecialchars($r['purpose']); ?></td>
                        <td><span class="badge" style="background:<?= $sc[0]; ?>;color:<?= $sc[1]; ?>;border:1px solid <?= $sc[1]; ?>;font-size:.62rem;text-transform:capitalize;"><?= htmlspecialchars($sc[2]); ?></span></td>
                        <td class="text-end small text-muted"><?= htmlspecialchars(date('d M', strtotime((string)$r['requested_on']))); ?></td>
                        <td class="text-end">
                            <a href="<?= PROOT; ?>Lpos/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($rows)): ?>
                    <tr><td colspan="8" class="text-center text-muted py-4">
                        You haven't raised any cash requests. <a href="<?= PROOT; ?>CashRequests/new">Raise one</a>.
                    </td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

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