<?php
// Over-budget warning modal (dashboard-only): auto-shown on page load once
// the viewed month's spending has passed its budget, so going over is
// impossible to miss mid-month rather than something only noticed by
// glancing at the summary card's ring.
//
// Scoped to the current month only — the "spend less" advice below is only
// actionable for spending still ahead of you, so paging back through the
// archive to a past over-budget month (Section 8) never re-triggers it.
//
// Reuses the same $budgetSummary the summary card's ring and "Over by" line
// already render from (get_budget_summary(), includes/helpers.php), so the
// numbers here can never drift from what's on the card behind it.
//
// The including page (index.php) must have $budgetSummary, $isCurrentMonth,
// and $month already in scope before requiring this file.
if (!$budgetSummary || !$budgetSummary['over_budget'] || !$isCurrentMonth) {
    return;
}
?>
<div class="modal fade" id="budgetWarningModal" tabindex="-1" aria-labelledby="budgetWarningModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content" style="border-radius:var(--r-lg);border:1px solid var(--line);">
      <div class="modal-header">
        <h5 class="modal-title fw-bold" id="budgetWarningModalLabel">
          <i class="bi bi-exclamation-triangle-fill text-warning me-2"></i>Over budget for <?= e(month_name($month)) ?>
        </h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="alert alert-warning mb-3">
          You've spent <strong class="tnum"><?= e((string) $budgetSummary['percent_used']) ?>%</strong> of your <?= e(month_name($month)) ?> budget —
          <strong class="tnum"><?= e($budgetSummary['remaining_formatted']) ?></strong> over your planned <span class="tnum"><?= e($budgetSummary['planned_formatted']) ?></span>.
        </div>
        <p class="mb-0 text-secondary">Try to spend less for the rest of the month to help get back on track.</p>
      </div>
      <div class="modal-footer justify-content-between">
        <a class="link-quiet" href="reports.php?month=<?= e($month) ?>">See report <i class="bi bi-arrow-right"></i></a>
        <button type="button" class="btn-save" style="width:auto;margin-top:0;" data-bs-dismiss="modal">Got it</button>
      </div>
    </div>
  </div>
</div>