<?php
use App\Core\Flash;
$standalone = !empty($wajib);
$flashes = $standalone ? Flash::pull() : [];
if ($standalone): ?>
<!DOCTYPE html>
<html lang="id"><head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ganti Kata Sandi — <?= e(setting('umum.nama_aplikasi', 'SIPIUTANG')) ?></title>
<link href="<?= asset('vendor/bootstrap.min.css') ?>" rel="stylesheet">
<link href="<?= asset('vendor/bootstrap-icons.css') ?>" rel="stylesheet">
<link href="<?= asset('css/app.css') ?>" rel="stylesheet">
</head><body class="login-page">
<div class="login-card" style="max-width:470px">
  <div class="login-head">
    <div class="brand-mark">S</div>
    <h1>Ganti Kata Sandi</h1>
    <p>Demi keamanan, kata sandi awal wajib diganti sebelum menggunakan sistem.</p>
  </div>
  <div class="login-body">
    <?php foreach ($flashes as $f): ?>
      <div class="alert alert-<?= e($f['type']) ?> py-2 small"><?= e($f['message']) ?></div>
    <?php endforeach; ?>
<?php else: ?>
<div class="row justify-content-center">
  <div class="col-lg-6">
    <div class="card">
      <div class="card-header"><i class="bi bi-key me-1"></i>Ganti Kata Sandi</div>
      <div class="card-body">
<?php endif; ?>

    <form method="post" action="<?= url('/ganti-sandi') ?>" data-loading>
      <?= csrf() ?>
      <div class="mb-3">
        <label class="form-label required" for="sandi_lama">Kata Sandi Saat Ini</label>
        <input type="password" class="form-control" id="sandi_lama" name="sandi_lama" required autocomplete="current-password" autofocus>
      </div>
      <div class="mb-3">
        <label class="form-label required" for="sandi_baru">Kata Sandi Baru</label>
        <input type="password" class="form-control" id="sandi_baru" name="sandi_baru" required
               minlength="<?= (int)($min ?? 8) ?>" autocomplete="new-password">
        <div class="form-text">
          Minimal <?= (int)($min ?? 8) ?> karakter, memuat sedikitnya satu huruf dan satu angka.
          Tidak boleh sama dengan kata sandi lama.
        </div>
      </div>
      <div class="mb-3">
        <label class="form-label required" for="sandi_konfirmasi">Ulangi Kata Sandi Baru</label>
        <input type="password" class="form-control" id="sandi_konfirmasi" name="sandi_konfirmasi" required autocomplete="new-password">
      </div>
      <div class="d-flex gap-2">
        <button class="btn btn-primary" type="submit"><i class="bi bi-check-lg me-1"></i>Simpan Kata Sandi</button>
        <?php if ($standalone): ?>
          <form method="post" action="<?= url('/keluar') ?>" class="d-inline"><?= csrf() ?>
            <button class="btn btn-light" type="submit">Keluar</button>
          </form>
        <?php else: ?>
          <a class="btn btn-light" href="<?= url('/profil') ?>">Batal</a>
        <?php endif; ?>
      </div>
    </form>

<?php if ($standalone): ?>
  </div>
</div>
<script src="<?= asset('vendor/bootstrap.bundle.min.js') ?>"></script>
</body></html>
<?php else: ?>
      </div>
    </div>
  </div>
</div>
<?php endif; ?>
