<?php
// "Edit income" modal — mirrors includes/layout/edit_modal.php, but for
// incomes (no payment method, income-type categories). Required by
// income.php. The including page must have $incomeCategories in scope.
?>
<div class="modal fade" id="editIncomeModal" tabindex="-1" aria-labelledby="editIncomeModalLabel" 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);">
      <form id="editIncomeForm" action="api/income_save.php" method="post" novalidate>
        <div class="modal-header">
          <h5 class="modal-title fw-bold" id="editIncomeModalLabel">Edit income</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <?= csrf_field() ?>
          <input type="hidden" name="id" id="editIncomeId">
          <input type="hidden" name="viewed_month" value="<?= e($month ?? '') ?>">

          <label class="visually-hidden" for="editIncomeAmount">Amount</label>
          <div class="amount-wrap" id="editIncomeAmountWrap">
            <span class="amount-cur"><?= e(get_setting('currency_symbol', '¥')) ?></span>
            <input class="amount-in tnum" id="editIncomeAmount" name="amount" type="text" inputmode="decimal" autocomplete="off">
          </div>

          <div class="field-label">Category</div>
          <?php render_category_grid($incomeCategories, [], 0, 'editIncomeCategoryId', 'category_id', 'editIncomeCatGrid', 'editIncomeMoreCats'); ?>

          <label class="field-label" for="editIncomeDesc">Description <span class="fw-normal text-secondary">(optional)</span></label>
          <input class="form-control" id="editIncomeDesc" name="description" type="text" maxlength="255">

          <label class="field-label" for="editIncomeDate">Date</label>
          <input class="form-control tnum" id="editIncomeDate" name="income_date" type="date">
        </div>
        <div class="modal-footer justify-content-between">
          <button type="button" class="btn btn-outline-danger" id="deleteIncomeBtn"><i class="bi bi-trash3 me-1"></i>Delete</button>
          <button type="submit" class="btn-save" style="width:auto;margin-top:0;" id="editIncomeSaveBtn">Save changes</button>
        </div>
      </form>
    </div>
  </div>
</div>
