<?php 
$pageTitle = 'Record Forex Trade';
include __DIR__ . '/../layouts/header.php'; 
?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="bi bi-currency-exchange me-2"></i>Record Forex Trade</h2>
    <a href="<?= $this->baseUrl('/forex/trades') ?>" class="btn btn-outline-secondary">
        <i class="bi bi-arrow-left"></i> Back to Trades
    </a>
</div>

<div class="row">
    <div class="col-lg-6">
        <div class="card">
            <div class="card-body">
                <form method="post" action="<?= $this->baseUrl('/forex/trades') ?>">
                    <div class="mb-3">
                        <label class="form-label">Currency <span class="text-danger">*</span></label>
                        <select name="currency_id" class="form-select" required>
                            <option value="">-- Select Currency --</option>
                            <?php foreach ($currencies as $c): ?>
                                <option value="<?= $c['id'] ?>"><?= $c['code'] ?> - <?= $c['name'] ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Trade Type <span class="text-danger">*</span></label>
                        <select name="trade_type" class="form-select" required>
                            <option value="buy">Buy</option>
                            <option value="sell">Sell</option>
                        </select>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Amount (in foreign currency) <span class="text-danger">*</span></label>
                        <input type="number" step="0.01" name="amount" class="form-control" required autofocus>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Exchange Rate (KES per 1 unit) <span class="text-danger">*</span></label>
                        <input type="number" step="0.000001" name="rate" class="form-control" required>
                        <small class="text-muted">Current market rate in KES</small>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Counterparty</label>
                        <input type="text" name="counterparty" class="form-control" placeholder="e.g., Bank, Exchange Bureau">
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Notes</label>
                        <textarea name="notes" class="form-control" rows="2" placeholder="Additional information..."></textarea>
                    </div>
                    <hr>
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-save"></i> Save Trade
                        </button>
                        <a href="<?= $this->baseUrl('/forex/trades') ?>" class="btn btn-outline-secondary">
                            <i class="bi bi-x-circle"></i> Cancel
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="col-lg-6">
        <div class="card">
            <div class="card-body">
                <h5 class="card-title"><i class="bi bi-info-circle me-2"></i>Quick Reference</h5>
                <table class="table table-sm table-borderless">
                    <tr><th>Buy:</th><td>You acquire foreign currency by spending KES.</td></tr>
                    <tr><th>Sell:</th><td>You sell foreign currency to receive KES.</td></tr>
                    <tr><th>Rate:</th><td>How many KES per 1 unit of foreign currency.</td></tr>
                </table>
                <hr>
                <p class="text-muted small">The KES equivalent will be calculated automatically.</p>
            </div>
        </div>
    </div>
</div>

<?php include __DIR__ . '/../layouts/footer.php'; ?>