<?php use App\Helpers\Helper; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
  <h1 class="admin-page-title">Payment Receipt</h1>
  <div class="d-flex gap-2">
    <button onclick="window.print()" class="btn btn-outline-primary"><i class="bi bi-printer me-1"></i>Print</button>
    <a href="<?= APP_URL ?>/admin/payments" class="btn btn-outline-secondary"><i class="bi bi-arrow-left me-1"></i>Back</a>
  </div>
</div>

<div class="row justify-content-center">
  <div class="col-lg-7">
    <div class="form-card" id="receiptCard">
      <!-- Header -->
      <div class="text-center border-bottom pb-4 mb-4">
        <i class="bi bi-buildings-fill text-primary" style="font-size:2.5rem"></i>
        <h4 class="fw-800 text-primary mt-1 mb-0"><?= $settingsMap['company_name'] ?? APP_NAME ?></h4>
        <p class="text-muted small mb-0"><?= $settingsMap['company_address'] ?? '' ?></p>
        <p class="text-muted small"><?= $settingsMap['company_phone'] ?? '' ?> | <?= $settingsMap['company_email'] ?? '' ?></p>
        <div class="badge bg-success px-4 py-2 fs-6 mt-2">PAYMENT RECEIPT</div>
      </div>

      <!-- Receipt Details -->
      <div class="row g-3 mb-4">
        <div class="col-6">
          <div class="small text-muted">Receipt Number</div>
          <div class="fw-700"><?= Helper::e($payment['receipt_number'] ?? $payment['payment_ref']) ?></div>
        </div>
        <div class="col-6 text-end">
          <div class="small text-muted">Payment Date</div>
          <div class="fw-700"><?= Helper::date($payment['payment_date']) ?></div>
        </div>
        <div class="col-6">
          <div class="small text-muted">Paid By</div>
          <div class="fw-700"><?= Helper::e($payment['tenant_name']) ?></div>
          <div class="small text-muted"><?= Helper::e($payment['tenant_phone']) ?></div>
        </div>
        <div class="col-6 text-end">
          <div class="small text-muted">Unit</div>
          <div class="fw-700"><?= Helper::e($payment['unit_number'] ?? '—') ?></div>
          <div class="small text-muted"><?= Helper::e($payment['property_name'] ?? '') ?></div>
        </div>
      </div>

      <!-- Amount Box -->
      <div class="bg-primary text-white rounded-3 p-4 text-center mb-4">
        <div class="small opacity-75">Payment For: <?= ucfirst(str_replace('_',' ',$payment['payment_for'])) ?></div>
        <div class="fw-800 mt-1" style="font-size:2.2rem"><?= Helper::money($payment['amount']) ?></div>
        <?php if ($payment['period_from']): ?>
        <div class="small opacity-75 mt-1">Period: <?= Helper::date($payment['period_from']) ?> — <?= Helper::date($payment['period_to']) ?></div>
        <?php endif; ?>
      </div>

      <!-- Payment Method -->
      <div class="row g-3 mb-4">
        <div class="col-6">
          <div class="small text-muted">Payment Method</div>
          <div class="fw-600"><?= Helper::e($payment['method_name'] ?? 'Cash') ?></div>
        </div>
        <?php if ($payment['transaction_id']): ?>
        <div class="col-6 text-end">
          <div class="small text-muted">Transaction ID</div>
          <div class="fw-600 font-monospace small"><?= Helper::e($payment['transaction_id']) ?></div>
        </div>
        <?php endif; ?>
        <div class="col-6">
          <div class="small text-muted">Status</div>
          <?= Helper::statusBadge($payment['status']) ?>
        </div>
        <div class="col-6 text-end">
          <div class="small text-muted">Received By</div>
          <div class="fw-600 small"><?= Helper::e($payment['received_by_name'] ?? 'System') ?></div>
        </div>
      </div>

      <?php if ($payment['notes']): ?>
      <div class="bg-light rounded-2 p-3 mb-4 small text-muted">
        <strong>Notes:</strong> <?= Helper::e($payment['notes']) ?>
      </div>
      <?php endif; ?>

      <!-- QR Code -->
      <div class="text-center border-top pt-4">
        <img src="<?= Helper::qrCode($payment['receipt_number'].'|'.$payment['amount'].'|'.$payment['payment_date']) ?>" alt="QR" width="100">
        <p class="text-muted small mt-2">Scan to verify receipt</p>
        <p class="text-muted" style="font-size:0.7rem">This is a computer-generated receipt. No signature required.</p>
      </div>
    </div>
  </div>
</div>
<style>@media print { .admin-topbar, .admin-sidebar, .d-flex.mb-4 { display:none!important; } .admin-main { margin:0; } .admin-content { padding:0; } }</style>
