<?= $this->extend('admin/layout/main') ?>
<?= $this->section('content') ?>
<h3 class="mb-3"><?= $rate ? lang('App.edit') : lang('App.add_new') ?> - <?= lang('App.exchange_rates') ?></h3>
<div class="card p-4" style="max-width:450px;">
<form method="post" action="<?= $rate ? '/admin/exchange-rates/' . $rate['id'] : '/admin/exchange-rates' ?>">
    <?= csrf_field() ?>
    <div class="row">
        <div class="col-6 mb-3">
            <label class="form-label">من عملة</label>
            <select name="currency_from" class="form-select">
                <?php foreach ($currencies as $curr): $cur = $curr['code']; ?>
                    <option <?= ($rate['currency_from'] ?? '') === $cur ? 'selected' : '' ?>><?= $cur ?><?= !empty($curr['name']) ? ' - ' . esc($curr['name']) : '' ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <div class="col-6 mb-3">
            <label class="form-label">إلى عملة</label>
            <select name="currency_to" class="form-select">
                <?php foreach ($currencies as $curr): $cur = $curr['code']; ?>
                    <option <?= ($rate['currency_to'] ?? '') === $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="number" step="0.000001" name="rate" class="form-control" value="<?= esc($rate['rate'] ?? '') ?>" required>
    </div>
    <div class="mb-3">
        <label class="form-label">التاريخ</label>
        <input type="date" name="date" class="form-control" value="<?= esc($rate['date'] ?? date('Y-m-d')) ?>" required>
    </div>
    <button class="btn btn-dark"><?= lang('App.save') ?></button>
    <a href="/admin/exchange-rates" class="btn btn-light"><?= lang('App.cancel') ?></a>
</form>
</div>
<?= $this->endSection() ?>
