<?php $this->start('body');
    $rows = $this->data['rows'] ?? [];
    $statusColor = ['DRAFT' => '#94A3B8', 'ACTIVE' => '#7A9E7E', 'CLOSED' => '#64748B'];
?>

<div class="d-flex align-items-center justify-content-between mb-3">
    <h5 class="mb-0" style="font-weight:600;color:#334155;"><i class="fas fa-map-signs me-2" style="color:#7A8BA1;"></i>BDM Plans</h5>
    <?php if (UserGroups::can('BdmPlans','add')): ?><a href="<?= PROOT; ?>BdmPlans/add" class="btn btn-sm" style="background:#7A8BA1;border-color:#7A8BA1;color:#fff;font-weight:600;"><i class="fas fa-plus me-1"></i>New plan</a><?php endif; ?>
</div>

<div class="card border-0 shadow-sm">
    <div class="table-responsive">
        <table class="table table-sm mb-0 align-middle">
            <thead style="background:#F1F5F9;">
                <tr>
                    <th style="color:#334155;">Plan</th>
                    <th style="color:#334155;">Year</th>
                    <th class="text-end" style="color:#334155;">Target</th>
                    <th class="text-end" style="color:#334155;">Objectives</th>
                    <th style="color:#334155;">Status</th>
                    <th style="color:#334155;">Owner</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($rows as $r):
                    $col = $statusColor[$r['status']] ?? '#94A3B8';
                ?>
                    <tr>
                        <td style="color:#334155;font-weight:500;"><?= htmlspecialchars($r['plan_name']); ?></td>
                        <td class="text-muted small" style="color:#64748B;"><?= (int)$r['plan_year']; ?></td>
                        <td class="text-end" style="color:#334155;"><?= number_format((float)$r['target_amount']); ?></td>
                        <td class="text-end text-muted small" style="color:#64748B;"><?= (int)$r['objectives']; ?></td>
                        <td><span class="badge" style="background:<?= $col; ?>;color:#fff;font-size:.62rem;"><?= $r['status']; ?></span></td>
                        <td class="text-muted small" style="color:#64748B;"><?= htmlspecialchars((string)($r['owner_name'] ?? '')); ?></td>
                        <td class="text-end"><a href="<?= PROOT; ?>BdmPlans/view/<?= (int)$r['c0d']; ?>" class="btn btn-sm" style="background:#F8FAFC;border:1px solid #E2E8F0;color:#334155;"><i class="fas fa-eye me-1" style="color:#7A8BA1;"></i>View</a></td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($rows)): ?><tr><td colspan="7" class="text-center py-4" style="color:#94A3B8;">No plans yet. <?php if (UserGroups::can('BdmPlans','add')): ?><a href="<?= PROOT; ?>BdmPlans/add" style="color:#7A8BA1;font-weight:600;">Add the first one</a>.<?php endif; ?></td></tr><?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

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