<div class="row justify-content-center"><div class="col-lg-8"><div class="card">
    <div class="card-header"><h6 class="mb-0"><?= e($refund['refund_number']) ?></h6></div>
    <div class="card-body">
        <table class="table table-sm">
            <tr><th>Member</th><td><?= e($refund['member_name']) ?> (<?= e($refund['membership_number']) ?>)</td></tr>
            <tr><th>Amount</th><td class="fw-bold"><?= format_money($refund['refund_amount']) ?></td></tr>
            <tr><th>Date</th><td><?= format_date($refund['refund_date']) ?></td></tr>
            <tr><th>Method</th><td><?= e($refund['method_name']) ?></td></tr>
            <tr><th>Status</th><td><?= status_badge($refund['status']) ?></td></tr>
            <tr><th>Reason</th><td><?= e($refund['reason']) ?></td></tr>
            <?php if($refund['original_payment_number']): ?><tr><th>Orig. Payment</th><td><?= e($refund['original_payment_number']) ?></td></tr><?php endif; ?>
            <?php if($refund['original_invoice_number']): ?><tr><th>Orig. Invoice</th><td><?= e($refund['original_invoice_number']) ?></td></tr><?php endif; ?>
            <?php if($refund['reference_number']): ?><tr><th>Ref #</th><td><?= e($refund['reference_number']) ?></td></tr><?php endif; ?>
            <?php if($refund['rejection_reason']): ?><tr><th>Rejection</th><td class="text-danger"><?= e($refund['rejection_reason']) ?></td></tr><?php endif; ?>
        </table>
        <div class="d-flex gap-2 mt-3">
            <?php if($refund['status'] === 'pending' && auth_can('refunds.approve')): ?>
            <form method="POST" action="/advanced-finance/refunds/<?= $refund['id'] ?>/approve" data-ajax="true"><?= csrf_field() ?><button class="btn btn-success btn-sm"><i class="fas fa-check me-1"></i><?= lang('adv_finance.approve') ?></button></form>
            <button class="btn btn-danger btn-sm" data-bs-toggle="modal" data-bs-target="#rejectModal"><i class="fas fa-times me-1"></i><?= lang('adv_finance.reject') ?></button>
            <?php endif; ?>
            <?php if($refund['status'] === 'approved' && auth_can('refunds.approve')): ?>
            <button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#processModal"><i class="fas fa-cog me-1"></i><?= lang('adv_finance.process') ?></button>
            <?php endif; ?>
        </div>
    </div>
</div></div></div>

<?php if($refund['status'] === 'pending'): ?>
<div class="modal fade" id="rejectModal" tabindex="-1"><div class="modal-dialog"><div class="modal-content">
    <form method="POST" action="/advanced-finance/refunds/<?= $refund['id'] ?>/reject" data-ajax="true"><?= csrf_field() ?>
        <div class="modal-header"><h5 class="modal-title"><?= lang('adv_finance.reject') ?></h5><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div>
        <div class="modal-body"><label class="form-label">Reason</label><textarea name="rejection_reason" class="form-control" rows="3" required></textarea></div>
        <div class="modal-footer"><button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?= lang('common.cancel') ?></button><button type="submit" class="btn btn-danger"><?= lang('adv_finance.reject') ?></button></div>
    </form>
</div></div></div>
<?php endif; ?>

<?php if($refund['status'] === 'approved'): ?>
<div class="modal fade" id="processModal" tabindex="-1"><div class="modal-dialog"><div class="modal-content">
    <form method="POST" action="/advanced-finance/refunds/<?= $refund['id'] ?>/process" data-ajax="true"><?= csrf_field() ?>
        <div class="modal-header"><h5 class="modal-title"><?= lang('adv_finance.process') ?></h5><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div>
        <div class="modal-body"><label class="form-label">Reference Number</label><input type="text" name="reference_number" class="form-control"></div>
        <div class="modal-footer"><button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?= lang('common.cancel') ?></button><button type="submit" class="btn btn-primary"><?= lang('adv_finance.process') ?></button></div>
    </form>
</div></div></div>
<?php endif; ?>