<div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="mb-0"><?= lang('cards.request_details') ?> - <?= e($req['request_number']) ?></h4>
    <a href="/card-requests" class="btn btn-secondary"><i class="fas fa-arrow-left me-1"></i><?= lang('common.back') ?></a>
</div>
<div class="row g-4">
<div class="col-md-6">
    <div class="card">
        <div class="card-header"><h6 class="mb-0">Request Info</h6></div>
        <div class="card-body">
            <table class="table table-borderless mb-0">
                <tr><th width="40%">Request #</th><td><?= e($req['request_number']) ?></td></tr>
                <tr><th>Status</th><td><?= status_badge($req['status']) ?></td></tr>
                <tr><th>Type</th><td><?= ucfirst($req['request_type']) ?></td></tr>
                <tr><th>Card Type</th><td><?= e($req['type_name']) ?></td></tr>
                <tr><th>Member</th><td><?= e($req['member_name']) ?> (<?= e($req['membership_number']) ?>)</td></tr>
                <?php if ($req['dependent_name']): ?><tr><th>Dependent</th><td><?= e($req['dependent_name']) ?></td></tr><?php endif; ?>
                <tr><th>Fee</th><td><?= money($req['fee_amount']) ?></td></tr>
                <tr><th>Fee Paid</th><td><?= $req['fee_paid'] ? '<span class="badge bg-success">Yes</span>' : '<span class="badge bg-warning">No</span>' ?></td></tr>
                <?php if ($req['reason']): ?><tr><th>Reason</th><td><?= e($req['reason']) ?></td></tr><?php endif; ?>
                <tr><th>Created</th><td><?= format_datetime($req['created_at']) ?></td></tr>
                <?php if ($req['approved_by_name']): ?><tr><th>Approved By</th><td><?= e($req['approved_by_name']) ?> at <?= format_datetime($req['approved_at']) ?></td></tr><?php endif; ?>
                <?php if ($req['resulting_card_id']): ?><tr><th>Card</th><td><a href="/cards/<?= $req['resulting_card_id'] ?>">View Card</a></td></tr><?php endif; ?>
            </table>
        </div>
    </div>
</div>
<div class="col-md-6">
    <div class="card">
        <div class="card-header"><h6 class="mb-0">Actions</h6></div>
        <div class="card-body d-flex flex-wrap gap-2">
            <?php if ($req['status'] === 'pending' && auth_can('cards.manage')): ?>
            <form method="POST" action="/card-requests/<?= $req['id'] ?>/approve" data-ajax="true"><?= csrf_field() ?>
                <button type="submit" class="btn btn-success"><i class="fas fa-check me-1"></i>Approve</button></form>
            <button class="btn btn-danger" onclick="rejectRequest(<?= $req['id'] ?>)"><i class="fas fa-times me-1"></i>Reject</button>
            <?php endif; ?>
            <?php if ($req['status'] === 'approved' && auth_can('cards.manage')): ?>
            <form method="POST" action="/card-requests/<?= $req['id'] ?>/produce" data-ajax="true"><?= csrf_field() ?>
                <button type="submit" class="btn btn-primary"><i class="fas fa-cog me-1"></i>Produce Card</button></form>
            <?php endif; ?>
            <?php if ($req['status'] === 'ready' && auth_can('cards.manage')): ?>
            <form method="POST" action="/card-requests/<?= $req['id'] ?>/deliver" data-ajax="true"><?= csrf_field() ?>
                <input type="hidden" name="delivered_to" value="Member">
                <button type="submit" class="btn btn-info"><i class="fas fa-hand-holding me-1"></i>Mark Delivered</button></form>
            <?php endif; ?>
        </div>
    </div>
</div>
</div>

<?php $__view->push('scripts') ?>
<script>
function rejectRequest(id) {
    Swal.fire({title:'Reject Reason',input:'textarea',showCancelButton:true,confirmButtonText:'Reject',confirmButtonColor:'#e53e3e'}).then(r=>{
        if(r.isConfirmed){$.ajax({url:'/card-requests/'+id+'/reject',type:'POST',data:{_token:'<?= csrf_token() ?>',reason:r.value},success:function(d){if(d.success){FormHelper.showToast('success',d.message);setTimeout(()=>location.reload(),800);}}})}
    });
}
</script>
<?php $__view->endPush() ?>