<?php $this->start('body');
    $rows  = $this->data['rows']  ?? [];
    $types = $this->data['types'] ?? [];
?>

<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-inbox me-2 text-muted"></i>Retirements to review</h5>
        <div class="text-muted small mt-1" style="font-size:.72rem;">
            Requesters have closed out their cash advances — review the spend lines + receipts, then approve or bounce back.
        </div>
    </div>
</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>Requester</th>
                    <th>Project</th>
                    <th class="text-end">Advance</th>
                    <th class="text-end">Spent</th>
                    <th class="text-end">Returned</th>
                    <th class="text-end">Variance</th>
                    <th class="text-end">Submitted</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';
                    $bal = abs((float)$r['variance']) < 0.005;
                ?>
                    <tr>
                        <td><a href="<?= PROOT; ?>Retirements/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"><?= htmlspecialchars((string)$r['requested_by_name']); ?></td>
                        <td class="small text-muted"><?= !empty($r['project_no']) ? htmlspecialchars($r['project_no']) : '<em>Central</em>'; ?></td>
                        <td class="text-end small" style="font-weight:600;color:#334155;"><?= htmlspecialchars($r['currency']); ?> <?= number_format((float)$r['lpo_amount']); ?></td>
                        <td class="text-end small"><?= number_format((float)$r['total_spent']); ?></td>
                        <td class="text-end small"><?= number_format((float)$r['cash_returned']); ?></td>
                        <td class="text-end small">
                            <span class="badge" style="background:<?= $bal ? '#EAF2E8' : '#F5EAE1'; ?>;color:<?= $bal ? '#3F5C43' : '#C48579'; ?>;border:1px solid <?= $bal ? '#3F5C43' : '#C48579'; ?>;font-size:.62rem;">
                                <?= number_format((float)$r['variance']); ?>
                            </span>
                        </td>
                        <td class="text-end small text-muted"><?= htmlspecialchars(date('d M · H:i', strtotime((string)$r['submitted_on']))); ?></td>
                        <td class="text-end"><a href="<?= PROOT; ?>Retirements/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="10" class="text-center text-muted py-4" style="font-size:.72rem;">Queue is clear — no retirements waiting for you right now.</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

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