<?php

/**
 * @var array $statusTiket
 * @var array $daftarPrioritas
 * @var array $categories
 * @var array $daftarSla
 */
?>
<div class="card shadow-sm mb-4">
  <div class="card-header bg-white">
    <h5 class="mb-0">
      <i class="bi bi-funnel"></i>
      Filter Tiket
    </h5>
  </div>
  <div class="card-body">
    <form method="GET" action="<?= url('DAFTAR_TIKET') ?>">
      <div class="row g-3">
        <!-- Keyword -->
        <div class="col-md-4">
          <label class="form-label">
            Cari Tiket
          </label>
          <div class="input-group">
            <span class="input-group-text">
              <i class="bi bi-search"></i>
            </span>
            <input
              type="text"
              class="form-control"
              name="keyword"
              autocomplete="off"
              placeholder="No tiket / judul / requester"
              value="<?= htmlspecialchars($_GET['keyword'] ?? '') ?>">
          </div>
        </div>
        <!-- Status -->
        <div class="col-md-2">
          <label class="form-label">
            Status
          </label>
          <select
            class="form-select"
            name="id_status"
            id="statusFilter">
            <option value="">
              Semua Status
            </option>
            <?php foreach ($statusTiket as $status): ?>
              <option
                value="<?= $status->getId() ?>"
                <?=
                (($_GET['id_status'] ?? '') == $status->getId())
                  ? 'selected'
                  : ''
                ?>>
                <?= htmlspecialchars($status->getNamaStatus()) ?>
              </option>
            <?php endforeach; ?>
          </select>
        </div>
        <!-- Priority -->
        <div class="col-md-2">
          <label class="form-label">
            Prioritas
          </label>
          <select
            class="form-select"
            name="id_prioritas"
            id="priorityFilter">
            <option value="">
              Semua
            </option>
            <?php foreach ($daftarPrioritas as $priority): ?>
              <option
                value="<?= $priority->getId() ?>"
                <?=
                (($_GET['id_prioritas'] ?? '') == $priority->getId())
                  ? 'selected'
                  : ''
                ?>>
                <?= htmlspecialchars($priority->getNamaPrioritas()) ?>
              </option>
            <?php endforeach; ?>
          </select>
        </div>
        <!-- Category -->
        <div class="col-md-2">
          <label class="form-label">
            Kategori
          </label>
          <select
            class="form-select"
            name="id_kategori"
            id="categoryFilter">
            <option value="">
              Semua Kategori
            </option>
            <?php foreach ($categories as $category): ?>
              <option
                value="<?= $category->getId() ?>"
                <?=
                (($_GET['id_kategori'] ?? '') == $category->getId())
                  ? 'selected'
                  : ''
                ?>>
                <?= htmlspecialchars($category->getNamaKategori()) ?>
              </option>
            <?php endforeach; ?>
          </select>
        </div>

        <!-- SLA -->
        <div class="col-md-2">
          <label class="form-label">
            SLA
          </label>
          <select
            class="form-select"
            name="id_sla"
            id="slaFilter">
            <option value="">
              Semua SLA
            </option>
            <?php foreach ($daftarSla as $sla): ?>
              <option
                value="<?= $sla->getId() ?>"
                <?=
                (($_GET['id_sla'] ?? '') == $sla->getId())
                  ? 'selected'
                  : ''
                ?>>
                <?= htmlspecialchars($sla->getNamaSla()) ?>
              </option>
            <?php endforeach; ?>
          </select>
        </div>
      </div>
      <hr>
      <div class="d-flex justify-content-between align-items-center">
        <small class="text-muted">
          Gunakan filter untuk mempersempit daftar tiket
        </small>
        <div class="d-flex gap-2">
          <a
            href="<?= url('DAFTAR_TIKET') ?>"
            class="btn btn-light border">
            <i class="bi bi-arrow-counterclockwise"></i>
            Reset
          </a>
          <button
            type="submit"
            class="btn btn-primary">
            <i class="bi bi-filter"></i>
            Terapkan Filter
          </button>
        </div>
      </div>
    </form>
  </div>
</div>