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

<div class="d-flex justify-content-between mb-4">
    <h2><i class="bi bi-currency-exchange me-2"></i>Forex Summary</h2>
    <a href="<?= $this->baseUrl('/reports') ?>" class="btn btn-outline-secondary">Back to Reports</a>
</div>

<form class="row g-3 mb-4">
    <div class="col-md-3">
        <label class="form-label">From</label>
        <input type="date" name="from" class="form-control" value="<?= htmlspecialchars($fromDate) ?>">
    </div>
    <div class="col-md-3">
        <label class="form-label">To</label>
        <input type="date" name="to" class="form-control" value="<?= htmlspecialchars($toDate) ?>">
    </div>
    <div class="col-md-2 align-self-end">
        <button type="submit" class="btn btn-primary">Filter</button>
    </div>
</form>

<div class="card">
    <div class="card-body p-0">
        <table class="table table-hover mb-0">
            <thead class="table-light">
                <tr>
                    <th>Currency</th>
                    <th class="text-end">Total Bought</th>
                    <th class="text-end">Total Sold</th>
                    <th class="text-end">Avg Buy Rate</th>
                    <th class="text-end">Avg Sell Rate</th>
                    <th class="text-end">Net KES Flow</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($summary as $row): ?>
                <tr>
                    <td><?= htmlspecialchars($row['code']) ?></td>
                    <td class="text-end"><?= number_format($row['total_bought'], 2) ?></td>
                    <td class="text-end"><?= number_format($row['total_sold'], 2) ?></td>
                    <td class="text-end"><?= number_format($row['avg_buy_rate'], 4) ?></td>
                    <td class="text-end"><?= number_format($row['avg_sell_rate'], 4) ?></td>
                    <td class="text-end fw-bold <?= $row['net_kes_flow'] >= 0 ? 'text-success' : 'text-danger' ?>">
                        <?= number_format($row['net_kes_flow'], 2) ?>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

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