<div class="row justify-content-center">
    <div class="col-lg-7">
        <a href="<?= site_url('statements'); ?>" class="text-decoration-none text-muted small">
            <i class="bi bi-arrow-left"></i> Retour au relevé
        </a>

        <?php
            $type_map = [
                'advance'    => ['success', 'arrow-down-circle', 'Cash Advance'],
                'expense'    => ['danger',  'receipt',           'Dépense'],
                'adjustment' => ['warning', 'pencil-square',    'Ajustement'],
            ];
            $t = $type_map[$transaction->type] ?? ['secondary', 'circle', $transaction->type];
        ?>

        <div class="card shadow-sm mt-2">
            <div class="card-header bg-white d-flex justify-content-between align-items-center">
                <h5 class="mb-0">
                    <i class="bi bi-<?= $t[1]; ?> text-<?= $t[0]; ?>"></i>
                    <?= htmlspecialchars($transaction->reference); ?>
                </h5>
                <span class="badge bg-<?= $t[0]; ?> fs-6"><?= $t[2]; ?></span>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <table class="table table-sm table-borderless">
                            <tr>
                                <td class="text-muted" style="width:40%">Référence</td>
                                <td class="fw-semibold"><code><?= htmlspecialchars($transaction->reference); ?></code></td>
                            </tr>
                            <tr>
                                <td class="text-muted">Date</td>
                                <td><?= date('d/m/Y', strtotime($transaction->transaction_date)); ?></td>
                            </tr>
                            <tr>
                                <td class="text-muted">Description</td>
                                <td><?= htmlspecialchars($transaction->description); ?></td>
                            </tr>
                            <tr>
                                <td class="text-muted">Enregistré par</td>
                                <td><?= htmlspecialchars($transaction->created_by_name); ?></td>
                            </tr>
                            <tr>
                                <td class="text-muted">Date création</td>
                                <td class="small"><?= date('d/m/Y H:i', strtotime($transaction->created_at)); ?></td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <div class="card bg-light">
                            <div class="card-body py-3 text-center">
                                <?php if ($transaction->credit > 0): ?>
                                <div class="text-muted small">Crédit</div>
                                <div class="h2 fw-bold text-success mb-1">
                                    + <?= number_format($transaction->credit, 0, ',', ' '); ?> KMF
                                </div>
                                <?php endif; ?>

                                <?php if ($transaction->debit > 0): ?>
                                <div class="text-muted small">Débit</div>
                                <div class="h2 fw-bold text-danger mb-1">
                                    - <?= number_format($transaction->debit, 0, ',', ' '); ?> KMF
                                </div>
                                <?php endif; ?>

                                <div class="text-muted small mt-2">Solde après opération</div>
                                <div class="h4 fw-bold <?= $transaction->balance < 0 ? 'text-danger' : ''; ?>">
                                    <?= number_format($transaction->balance, 0, ',', ' '); ?> KMF
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
