<?php $this->start('body');
    $p = $this->data['plan'] ?? null;
    $isEdit = $p !== null;
    $action = $isEdit ? PROOT . 'BdmPlans/edit/' . (int)$p['c0d'] : PROOT . 'BdmPlans/add';
?>

<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-<?= $isEdit ? 'edit' : 'plus-circle'; ?> me-2" style="color:#7A8BA1;"></i><?= $isEdit ? 'Edit BDM plan' : 'New BDM plan'; ?></h5>
    <a href="<?= PROOT; ?>BdmPlans" class="btn btn-sm" style="background:#F8FAFC;border:1px solid #E2E8F0;color:#334155;"><i class="fas fa-arrow-left me-1"></i>Back</a>
</div>

<form method="post" action="<?= $action; ?>" class="card border-0 shadow-sm" style="background:#F8FAFC;">
    <div class="card-body p-3">
        <div class="row g-2">
            <div class="col-md-6"><label class="form-label" style="color:#334155;">Plan name *</label>
                <input type="text" name="plan_name" required value="<?= htmlspecialchars((string)($p['plan_name'] ?? '')); ?>" class="form-control form-control-sm"></div>
            <div class="col-md-2"><label class="form-label" style="color:#334155;">Year</label>
                <input type="number" name="plan_year" value="<?= (int)($p['plan_year'] ?? date('Y')); ?>" class="form-control form-control-sm"></div>
            <div class="col-md-2"><label class="form-label" style="color:#334155;">Target (TZS)</label>
                <input type="number" step="0.01" name="target_amount" value="<?= (float)($p['target_amount'] ?? 0); ?>" class="form-control form-control-sm"></div>
            <?php if ($isEdit): ?>
            <div class="col-md-2"><label class="form-label" style="color:#334155;">Status</label>
                <select name="status" class="form-select form-select-sm">
                    <?php foreach (['DRAFT','ACTIVE','CLOSED'] as $s): ?>
                        <option value="<?= $s; ?>" <?= (($p['status'] ?? 'DRAFT') === $s) ? 'selected' : ''; ?>><?= $s; ?></option>
                    <?php endforeach; ?>
                </select></div>
            <?php endif; ?>
        </div>
    </div>
    <div class="card-footer bg-white d-flex justify-content-end gap-2" style="border-top:1px solid #E2E8F0;">
        <a href="<?= PROOT; ?>BdmPlans" class="btn btn-sm" style="background:#F8FAFC;border:1px solid #E2E8F0;color:#334155;">Cancel</a>
        <button type="submit" class="btn btn-sm" style="background:#7A8BA1;border-color:#7A8BA1;color:#fff;font-weight:600;"><i class="fas fa-save me-1"></i><?= $isEdit ? 'Save' : 'Create'; ?></button>
    </div>
</form>

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