<?= $this->extend('admin/layout/main') ?>
<?= $this->section('content') ?>
<h3 class="mb-3"><?= $expense ? lang('App.edit') : lang('App.add_new') ?> - <?= lang('App.expenses') ?></h3>
<div class="card p-4" style="max-width:500px;">
<form method="post" action="<?= $expense ? '/admin/expenses/' . $expense['id'] : '/admin/expenses' ?>">
    <?= csrf_field() ?>
    <div class="mb-3">
        <label class="form-label">التصنيف</label>
        <input type="text" name="category" class="form-control" placeholder="سيرفرات، نطاقات بالجملة..." value="<?= esc($expense['category'] ?? '') ?>" required>
    </div>
    <div class="mb-3">
        <label class="form-label">الوصف</label>
        <input type="text" name="description" class="form-control" value="<?= esc($expense['description'] ?? '') ?>">
    </div>
    <div class="row">
        <div class="col-6 mb-3">
            <label class="form-label"><?= lang('App.amount') ?></label>
            <input type="number" step="0.01" name="amount" class="form-control" value="<?= esc($expense['amount'] ?? '') ?>" required>
        </div>
        <div class="col-6 mb-3">
            <label class="form-label"><?= lang('App.currency') ?></label>
            <select name="currency" class="form-select">
                <?php foreach ($currencies as $curr): $cur = $curr['code']; ?>
                    <option <?= ($expense['currency'] ?? $currencies[0]['code']) === $cur ? 'selected' : '' ?>><?= $cur ?><?= !empty($curr['name']) ? ' - ' . esc($curr['name']) : '' ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    </div>
    <div class="mb-3">
        <label class="form-label">التاريخ</label>
        <input type="date" name="date" class="form-control" value="<?= esc($expense['date'] ?? date('Y-m-d')) ?>" required>
    </div>
    <button class="btn btn-dark"><?= lang('App.save') ?></button>
    <a href="/admin/expenses" class="btn btn-light"><?= lang('App.cancel') ?></a>
</form>
</div>
<?= $this->endSection() ?>
