<div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="mb-0"><?= lang('finance.payment') ?> #<?= e($payment['payment_number']) ?></h4>
    <div class="d-flex gap-2">
        <?php if ($receipt): ?>
        <a href="/finance/receipts/<?= $receipt['id'] ?>/print" target="_blank" class="btn btn-outline-info"><i class="fas fa-print me-1"></i><?= lang('finance.print_receipt') ?></a>
        <?php endif; ?>
        <a href="/finance/payments" class="btn btn-outline-secondary"><?= lang('common.back') ?></a>
    </div>
</div>

<div class="row g-4">
    <div class="col-md-6">
        <div class="card">
            <div class="card-header"><h6 class="mb-0"><?= lang('finance.payment_details') ?></h6></div>
            <div class="card-body">
                <table class="table table-borderless mb-0">
                    <tr><th width="40%"><?= lang('finance.payment_no') ?></th><td><?= e($payment['payment_number']) ?></td></tr>
                    <tr><th><?= lang('finance.amount') ?></th><td><strong class="text-success"><?= money($payment['amount']) ?></strong></td></tr>
                    <tr><th><?= lang('finance.method') ?></th><td><?= e($payment['method_name']) ?></td></tr>
                    <tr><th><?= lang('finance.date') ?></th><td><?= format_date($payment['payment_date']) ?></td></tr>
                    <tr><th><?= lang('common.status') ?></th><td><?= status_badge($payment['status']) ?></td></tr>
                    <?php if ($payment['reference_number']): ?>
                    <tr><th><?= lang('finance.reference') ?></th><td><?= e($payment['reference_number']) ?></td></tr>
                    <?php endif; ?>
                    <?php if ($payment['notes']): ?>
                    <tr><th><?= lang('finance.notes') ?></th><td><?= e($payment['notes']) ?></td></tr>
                    <?php endif; ?>
                </table>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="card">
            <div class="card-header"><h6 class="mb-0"><?= lang('finance.member') ?></h6></div>
            <div class="card-body">
                <table class="table table-borderless mb-0">
                    <tr><th width="40%"><?= lang('finance.name') ?></th><td><?= e($payment['member_name']) ?></td></tr>
                    <tr><th><?= lang('finance.membership_no') ?></th><td><?= e($payment['membership_number']) ?></td></tr>
                </table>
            </div>
        </div>

        <?php if (!empty($allocations)): ?>
        <div class="card mt-3">
            <div class="card-header"><h6 class="mb-0"><?= lang('finance.allocated_to') ?></h6></div>
            <div class="card-body">
                <table class="table table-sm mb-0">
                    <thead><tr><th><?= lang('finance.invoice') ?></th><th class="text-end"><?= lang('finance.allocated') ?></th></tr></thead>
                    <tbody>
                    <?php foreach ($allocations as $a): ?>
                    <tr><td><?= e($a['invoice_number']) ?></td><td class="text-end"><?= money($a['allocated_amount']) ?></td></tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
        <?php endif; ?>

        <?php if ($receipt): ?>
        <div class="card mt-3">
            <div class="card-header"><h6 class="mb-0"><?= lang('finance.receipt') ?></h6></div>
            <div class="card-body">
                <p class="mb-0"><?= lang('finance.receipt_no') ?>: <a href="/finance/receipts/<?= $receipt['id'] ?>">#<?= e($receipt['receipt_number']) ?></a></p>
            </div>
        </div>
        <?php endif; ?>
    </div>
</div>