<div class="d-flex justify-content-between align-items-center mb-3">
    <h5 class="fw-bold mb-0"><i class="fas fa-receipt me-2 text-primary"></i><?= e($expense['code'] ?? '#' . $expense['expense_id']) ?> · <?= e($expense['title']) ?></h5>
    <div class="d-flex gap-2">
        <a class="btn btn-sm btn-outline-primary" href="<?= url('/Expenses/edit/' . (int) $expense['expense_id']) ?>"><i class="fas fa-pen me-1"></i>Edit</a>
        <a class="btn btn-sm btn-outline-secondary" href="<?= url('/Expenses/pdf/' . (int) $expense['expense_id']) ?>" target="_blank"><i class="fas fa-file-pdf me-1"></i>PDF</a>
        <a class="btn btn-sm btn-outline-secondary" href="<?= url('/Expenses') ?>"><i class="fas fa-arrow-left me-1"></i>Back</a>
    </div>
</div>

<?php if (!empty($flash)): ?><div class="alert alert-info py-2 small"><?= e($flash) ?></div><?php endif; ?>

<div class="rs-card p-3 mb-3">
    <dl class="rs-def row g-2 mb-0">
        <div class="col-md-3"><dt>Date</dt><dd><?= e($expense['expense_date'] ?? '—') ?></dd></div>
        <div class="col-md-3"><dt>Category</dt><dd><?= e($expense['category_name'] ?? '—') ?></dd></div>
        <div class="col-md-3"><dt>Amount</dt><dd><strong><?= e($expense['currency']) ?> <?= number_format((float) $expense['amount'], 2) ?></strong></dd></div>
        <div class="col-md-3"><dt>Status</dt><dd><span class="badge bg-secondary text-uppercase"><?= e($expense['status']) ?></span></dd></div>
        <div class="col-md-3"><dt>Vendor</dt><dd><?= e($expense['vendor'] ?? '—') ?></dd></div>
        <div class="col-md-3"><dt>Receipt Ref</dt><dd><?= e($expense['receipt_ref'] ?? '—') ?></dd></div>
        <div class="col-md-3"><dt>Payment</dt><dd><?= e($expense['payment_method'] ?? '—') ?></dd></div>
        <div class="col-md-3"><dt>Submitter</dt><dd><?= e($expense['submitter_username'] ?? '—') ?></dd></div>
        <div class="col-md-3"><dt>Approver</dt><dd><?= e($expense['approver_username'] ?? '—') ?></dd></div>
        <div class="col-md-3"><dt>Work Order</dt><dd><?= e($expense['wo_title'] ?? '—') ?></dd></div>
        <div class="col-md-3"><dt>Site</dt><dd><?= e($expense['site_name'] ?? '—') ?></dd></div>
        <div class="col-md-3"><dt>Asset</dt><dd><?= e($expense['asset_name'] ?? '—') ?></dd></div>
    </dl>
</div>

<?php if (!empty($expense['description'])): ?><div class="rs-card p-3 mb-3"><h6 class="fw-bold mb-2">Description</h6><p class="mb-0 small"><?= nl2br(e($expense['description'])) ?></p></div><?php endif; ?>
<?php if (!empty($expense['approval_note'])): ?><div class="rs-card p-3 mb-3"><h6 class="fw-bold mb-2">Approval Note</h6><p class="mb-0 small"><?= nl2br(e($expense['approval_note'])) ?></p></div><?php endif; ?>

<div class="rs-card p-3">
    <h6 class="fw-bold mb-2">Change Status</h6>
    <form method="post" action="<?= url('/Expenses/transition/' . (int) $expense['expense_id']) ?>">
        <input type="hidden" name="_csrf" value="<?= e($csrf) ?>">
        <div class="row g-2">
            <div class="col-md-3"><label class="form-label">Status</label><select name="status" class="form-select form-select-sm"><?php foreach (['draft','submitted','approved','rejected','paid','cancelled'] as $s): ?><option value="<?= $s ?>"><?= $s ?></option><?php endforeach; ?></select></div>
            <div class="col-md-9"><label class="form-label">Approval / Rejection Note</label><textarea class="form-control form-control-sm" name="approval_note" rows="2"></textarea></div>
        </div>
        <div class="mt-3"><button type="submit" class="btn btn-sm btn-primary"><i class="fas fa-check me-1"></i>Update Status</button></div>
    </form>
</div>

<?php require ROOT . '/app/Views/partials/_attachments.php'; ?>
