<?php
require_once __DIR__ . "/../config/db.php";
include __DIR__ . "/../partials/header.php";
include __DIR__ . "/../partials/sidebar.php";

$id = (int)($_GET["id"] ?? 0);

$stmt = $conn->prepare("SELECT * FROM resi WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$res = $stmt->get_result();
$data = $res->fetch_assoc();
?>

<div class="card-glass p-4 mb-3">
  <div class="d-flex justify-content-between align-items-center flex-wrap gap-2">
    <div>
      <h3 class="mb-1">Detail Resi</h3>
      <div class="text-muted">Informasi detail data resi paket.</div>
    </div>

    <a class="btn btn-outline-light" href="/smart-drop-point/public/resi.php">
      <i class="bi bi-arrow-left me-2"></i>Kembali
    </a>
  </div>
</div>

<?php if ($data): ?>
  <div class="card-glass p-4">
    <table class="table table-dark table-bordered align-middle mb-0">
      <tr>
        <th width="220">Nomor Resi</th>
        <td><?= htmlspecialchars($data["nomor_resi"] ?? "-") ?></td>
      </tr>

      <tr>
        <th>Nama Paket</th>
        <td><?= htmlspecialchars($data["nama_paket"] ?? "-") ?></td>
      </tr>

      <tr>
        <th>Status</th>
        <td>
          <?php if (($data["status"] ?? "") === "valid"): ?>
            <span class="badge text-bg-success">VALID</span>
          <?php else: ?>
            <span class="badge text-bg-secondary">INVALID</span>
          <?php endif; ?>
        </td>
      </tr>

      <tr>
        <th>Dibuat</th>
        <td><?= htmlspecialchars($data["created_at"] ?? "-") ?></td>
      </tr>
    </table>
  </div>
<?php else: ?>
  <div class="alert alert-danger">
    Data resi tidak ditemukan.
  </div>
<?php endif; ?>

<?php include __DIR__ . "/../partials/footer.php"; ?>