<?php use App\Helpers\Helper; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
  <h1 class="admin-page-title">Booking: <?= Helper::e($booking['booking_ref']) ?></h1>
  <a href="<?= APP_URL ?>/admin/bookings" class="btn btn-outline-secondary"><i class="bi bi-arrow-left me-1"></i>Back</a>
</div>

<div class="row g-4">
  <div class="col-lg-8">
    <div class="form-card mb-4">
      <div class="form-section-title">Visitor Information</div>
      <div class="row g-3">
        <div class="col-md-6"><div class="small text-muted">Full Name</div><div class="fw-600"><?= Helper::e($booking['visitor_name']) ?></div></div>
        <div class="col-md-6"><div class="small text-muted">Phone</div><div class="fw-600"><?= Helper::e($booking['visitor_phone']) ?></div></div>
        <div class="col-md-6"><div class="small text-muted">Email</div><div class="fw-600"><?= Helper::e($booking['visitor_email'] ?? '—') ?></div></div>
        <div class="col-md-6"><div class="small text-muted">Desired Move-in</div><div class="fw-600"><?= Helper::date($booking['desired_move_in'] ?? '') ?></div></div>
        <div class="col-md-6"><div class="small text-muted">Lease Period</div><div class="fw-600"><?= $booking['desired_lease_period'] ?> months</div></div>
        <?php if ($booking['notes']): ?>
        <div class="col-12"><div class="small text-muted">Notes</div><div class="small"><?= Helper::e($booking['notes']) ?></div></div>
        <?php endif; ?>
      </div>
    </div>
    <div class="form-card">
      <div class="form-section-title">Property Details</div>
      <div class="row g-3">
        <div class="col-md-6"><div class="small text-muted">Property</div><div class="fw-600"><?= Helper::e($booking['property_name']) ?></div></div>
        <div class="col-md-6"><div class="small text-muted">Unit</div><div class="fw-600"><?= Helper::e($booking['unit_number']) ?></div></div>
        <div class="col-md-6"><div class="small text-muted">Monthly Rent</div><div class="fw-600 text-primary"><?= Helper::money($booking['monthly_rent']) ?></div></div>
        <div class="col-md-6"><div class="small text-muted">Booking Fee</div><div class="fw-600"><?= Helper::money($booking['booking_fee']) ?></div></div>
        <div class="col-md-6"><div class="small text-muted">Bedrooms</div><div class="fw-600"><?= $booking['bedrooms'] ?></div></div>
        <div class="col-md-6"><div class="small text-muted">Bathrooms</div><div class="fw-600"><?= $booking['bathrooms'] ?></div></div>
      </div>
    </div>
  </div>
  <div class="col-lg-4">
    <div class="form-card mb-4">
      <div class="form-section-title">Status</div>
      <div class="mb-3"><?= Helper::statusBadge($booking['status']) ?> <?= Helper::statusBadge($booking['payment_status']) ?></div>
      <form method="POST" action="<?= APP_URL ?>/admin/bookings/<?= $booking['id'] ?>/status">
        <?= Helper::csrf() ?>
        <label class="form-label">Update Status</label>
        <select name="status" class="form-select mb-3">
          <?php foreach (['pending','approved','rejected','cancelled','checked_in','checked_out'] as $s): ?>
          <option value="<?= $s ?>" <?= $booking['status']===$s?'selected':'' ?>><?= ucfirst(str_replace('_',' ',$s)) ?></option>
          <?php endforeach; ?>
        </select>
        <button class="btn btn-primary w-100">Update Status</button>
      </form>
    </div>
    <?php if ($booking['status'] === 'approved'): ?>
    <div class="form-card">
      <div class="form-section-title">Convert to Lease</div>
      <p class="small text-muted mb-3">Booking is approved. Create a formal lease contract for this tenant.</p>
      <a href="<?= APP_URL ?>/admin/leases/create?unit_id=<?= $booking['unit_id'] ?>&visitor=<?= urlencode($booking['visitor_name']) ?>" class="btn btn-success w-100">
        <i class="bi bi-file-earmark-plus me-2"></i>Create Lease
      </a>
    </div>
    <?php endif; ?>
  </div>
</div>
