<?php 
$pageTitle = 'Forex Trades';
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>Forex Trades</h2>
    <div class="d-flex gap-2">
        <a href="<?= $this->baseUrl('/forex/profit-loss') ?>" class="btn btn-outline-info">
            <i class="bi bi-pie-chart"></i> Profit/Loss Report
        </a>
        <a href="<?= $this->baseUrl('/forex/trades/create') ?>" class="btn btn-primary">
            <i class="bi bi-plus-circle"></i> New Trade
        </a>
    </div>
</div>

<div class="card">
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead class="table-light">
                    <tr>
                        <th>Date</th>
                        <th>Currency</th>
                        <th>Type</th>
                        <th>Amount</th>
                        <th>Rate</th>
                        <th>KES Amount</th>
                        <th>Counterparty</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (empty($trades)): ?>
                        <tr>
                            <td colspan="7" class="text-center py-4 text-muted">
                                <i class="bi bi-currency-exchange fs-1 d-block mb-2"></i>
                                No forex trades recorded. <a href="<?= $this->baseUrl('/forex/trades/create') ?>">Add your first trade</a>.
                            </td>
                        </tr>
                    <?php else: ?>
                        <?php foreach ($trades as $t): ?>
                        <tr>
                            <td><?= date('Y-m-d H:i', strtotime($t['trade_date'])) ?></td>
                            <td><span class="badge bg-secondary"><?= htmlspecialchars($t['currency_code']) ?></span></td>
                            <td>
                                <span class="badge bg-<?= $t['trade_type'] === 'buy' ? 'success' : 'danger' ?>">
                                    <?= strtoupper($t['trade_type']) ?>
                                </span>
                            </td>
                            <td><?= number_format($t['amount'], 2) ?></td>
                            <td><?= number_format($t['rate'], 4) ?></td>
                            <td class="fw-bold"><?= number_format($t['kes_amount'], 2) ?></td>
                            <td><?= htmlspecialchars($t['counterparty'] ?: '—') ?></td>
                        </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

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