<?php

use App\Models\UserRole;
use App\Models\DivisiModel;

/** 
 * @var DivisiModel $divisions
 * @var array $roles
 * @var array $status
 */


?>

<div class="container">
  <div class="card">
    <div class="card-body">

      <!-- Header -->
      <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
          <h5 class="mb-1">
            <i class="bi bi-person-plus"></i>
            Tambah User
          </h5>
          <small class="text-muted">
            Silahkan isi form dibawah ini untuk menambahkan user baru.
          </small>
        </div>
        <a
          href="<?= url('MANAJEMEN_USER') ?>"
          class="btn btn-link">
          <i class="bi bi-arrow-left"></i>
          Kembali
        </a>
      </div>

      <div class="alert alert-info">
        <i class="bi bi-info-circle"></i>
        Kolom dengan tanda <span class="text-danger">*</span> wajib diisi.
      </div>

      <form method="POST" action="<?= url('TAMBAH_USER') ?>">

        <div class="mb-3">
          <label class="form-label">
            Nama Lengkap <span class="text-danger">*</span>
          </label>
          <input
            type="text"
            class="form-control"
            name="nama"
            required>
        </div>

        <div class="mb-3">
          <label class="form-label">
            Username <span class="text-danger">*</span>
          </label>
          <input
            type="text"
            class="form-control"
            name="username"
            required>
          <div class="form-text">
            Minimal 4 karakter dan harus unik.
          </div>
        </div>

        <div class="mb-3">
          <label class="form-label">
            Password <span class="text-danger">*</span>
          </label>
          <input
            type="password"
            class="form-control"
            name="password"
            required>
          <div class="form-text">
            Minimal 6 karakter.
          </div>
        </div>

        <div class="mb-3">
          <label class="form-label">
            Email <span class="text-danger">*</span>
          </label>
          <input
            type="email"
            class="form-control"
            name="email"
            required>
          <div class="form-text">
            Contoh: user@perusahaan.com
          </div>
        </div>

        <div class="mb-3">
          <label class="form-label">No. Telepon</label>
          <input
            type="text"
            class="form-control"
            name="noTelepon">
          <div class="form-text">
            Format: diawali 08 dan terdiri dari 10-15 digit angka.
          </div>
        </div>

        <div class="mb-3">
          <label class="form-label">
            Role <span class="text-danger">*</span>
          </label>

          <select class="form-select" name="role" required>
            <option value="">-- Pilih Role --</option>

            <?php foreach (UserRole::cases() as $role): ?>
              <option value="<?= $role->value ?>">
                <?= ucfirst(strtolower($role->value)) ?>
              </option>
            <?php endforeach; ?>

          </select>
        </div>

        <div class="mb-3">
          <label class="form-label">Divisi</label>
          <select class="form-select" name="divisiId">
            <option value="">-- Pilih Divisi --</option>

            <?php foreach ($divisions as $division): ?>
              <option value="<?= $division->getId() ?>">
                <?= htmlspecialchars($division->getNamaDivisi()) ?>
              </option>
            <?php endforeach; ?>

          </select>
          <div class="form-text">
            Wajib dipilih apabila Role adalah <strong>Teknisi</strong>.
          </div>
        </div>

        <!-- Spesialisasi -->
        <div class="mb-3">
          <label class="form-label">Spesialisasi</label>
          <input
            type="text"
            class="form-control"
            name="spesialisasi">
          <div class="form-text">
            Wajib dipilih apabila Role adalah <strong>Teknisi</strong>.
          </div>
        </div>

        <div class="mb-3">
          <label class="form-label d-block">Status Akun</label>

          <div class="form-check form-check-inline">
            <input
              class="form-check-input"
              type="radio"
              name="statusAkun"
              id="statusAktif"
              value="AKTIF"
              checked>

            <label class="form-check-label" for="statusAktif">
              Aktif
            </label>
          </div>

          <div class="form-check form-check-inline">
            <input
              class="form-check-input"
              type="radio"
              name="statusAkun"
              id="statusNonaktif"
              value="NONAKTIF">

            <label class="form-check-label" for="statusNonaktif">
              Nonaktif
            </label>
          </div>
        </div>

        <div class="text-end">
          <button type="submit" class="btn btn-primary">
            <i class="bi bi-check-lg"></i>
            Simpan
          </button>
        </div>

      </form>
    </div>
  </div>
</div>