<?php $fieldTransaction = $editingTransaction ?? []; $defaultTransactionDate = $month === date('Y-m') ? date('Y-m-d') : $month . '-01'; ?>
<div class="form-grid">
    <label class="span-2">Description<input type="text" name="merchant" required placeholder="Payment or merchant" value="<?= h($fieldTransaction['merchant'] ?? '') ?>"></label>
    <label>Amount<div class="money-input"><span><?= h($symbol) ?></span><input type="number" name="amount" min="0.01" step="0.01" required value="<?= h((string) ($fieldTransaction['amount'] ?? '')) ?>"></div></label>
    <label>Date<input type="date" name="transacted_on" value="<?= h((string) ($fieldTransaction['transacted_on'] ?? $defaultTransactionDate)) ?>" min="<?= h($month . '-01') ?>" max="<?= h($month . '-' . date('t', strtotime($month . '-01'))) ?>" required></label>
    <label>Budget target<select name="budget_item_id"><option value="">General expense</option><?php foreach ($items as $item): ?><option value="<?= (int) $item['id'] ?>" <?= (int) ($fieldTransaction['budget_item_id'] ?? 0) === (int) $item['id'] ? 'selected' : '' ?>><?= h($item['name']) ?> · <?= h(Support::money($item['remaining_amount'], $symbol)) ?> left</option><?php endforeach; ?></select></label>
    <label>Category<select name="category_id"><option value="">Use target / uncategorized</option><?php foreach ($categories as $category): ?><option value="<?= (int) $category['id'] ?>" <?= (int) ($fieldTransaction['category_id'] ?? 0) === (int) $category['id'] ? 'selected' : '' ?>><?= h($category['name']) ?></option><?php endforeach; ?></select></label>
    <label class="span-2">Notes<textarea name="notes" rows="2" placeholder="Optional details"><?= h($fieldTransaction['notes'] ?? '') ?></textarea></label>
</div>
