<?php include __DIR__ . '/../../views/layouts/header.php'; ?>
<div class="wrapper">
<?php include __DIR__ . '/../../views/layouts/sidebar.php'; ?>
<div class="main-content">
<?php include __DIR__ . '/../../views/layouts/topbar.php'; ?>
<div class="page-content">
  <div class="page-header">
    <h1><i class="bi bi-building me-2 text-primary"></i>Profil Sekolah</h1>
  </div>

  <?php if ($flash): ?>
  <div class="alert alert-<?= $flash['type'] ?> alert-auto-dismiss alert-dismissible fade show">
    <i class="bi bi-check-circle-fill me-2"></i><?= e($flash['message']) ?>
    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
  </div>
  <?php endif; ?>

  <?php if (!empty($errors)): ?>
  <div class="alert alert-danger"><ul class="mb-0"><?php foreach ($errors as $e): ?><li><?= e($e) ?></li><?php endforeach; ?></ul></div>
  <?php endif; ?>

  <form method="POST" enctype="multipart/form-data" class="needs-validation" novalidate>
    <input type="hidden" name="csrf_token" value="<?= e($csrfToken) ?>">
    <div class="row g-3">
      <div class="col-12 col-lg-8">
        <div class="card">
          <div class="card-header"><h6>Informasi Sekolah</h6></div>
          <div class="card-body">
            <div class="row g-3">
              <div class="col-md-8">
                <label class="form-label">Nama Sekolah <span class="text-danger">*</span></label>
                <input type="text" class="form-control" name="nama_sekolah" required
                       value="<?= e($data['nama_sekolah'] ?? '') ?>">
              </div>
              <div class="col-md-4">
                <label class="form-label">NPSN</label>
                <input type="text" class="form-control" name="npsn" value="<?= e($data['npsn'] ?? '') ?>">
              </div>
              <div class="col-12">
                <label class="form-label">Alamat</label>
                <textarea class="form-control" name="alamat" rows="2"><?= e($data['alamat'] ?? '') ?></textarea>
              </div>
              <div class="col-md-4">
                <label class="form-label">Telepon</label>
                <input type="text" class="form-control" name="telepon" value="<?= e($data['telepon'] ?? '') ?>">
              </div>
              <div class="col-md-4">
                <label class="form-label">Email</label>
                <input type="email" class="form-control" name="email" value="<?= e($data['email'] ?? '') ?>">
              </div>
              <div class="col-md-4">
                <label class="form-label">Website</label>
                <input type="text" class="form-control" name="website" value="<?= e($data['website'] ?? '') ?>">
              </div>
              <div class="col-md-6">
                <label class="form-label">Kepala Sekolah</label>
                <input type="text" class="form-control" name="kepala_sekolah" value="<?= e($data['kepala_sekolah'] ?? '') ?>">
              </div>
              <div class="col-md-6">
                <label class="form-label">NIP Kepala Sekolah</label>
                <input type="text" class="form-control" name="nip_kepala" value="<?= e($data['nip_kepala'] ?? '') ?>">
              </div>
              <div class="col-md-4">
                <label class="form-label">Tahun Ajaran</label>
                <input type="text" class="form-control" name="tahun_ajaran"
                       value="<?= e($data['tahun_ajaran'] ?? '2024/2025') ?>" placeholder="2024/2025">
              </div>
              <div class="col-md-4">
                <label class="form-label">Semester Aktif</label>
                <select class="form-select" name="semester">
                  <option value="Ganjil" <?= ($data['semester'] ?? '') === 'Ganjil' ? 'selected' : '' ?>>Ganjil</option>
                  <option value="Genap" <?= ($data['semester'] ?? '') === 'Genap' ? 'selected' : '' ?>>Genap</option>
                </select>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="col-12 col-lg-4">
        <div class="card mb-3">
          <div class="card-header"><h6>Logo Sekolah</h6></div>
          <div class="card-body text-center">
            <?php if (!empty($data['logo'])): ?>
              <img src="<?= BASE_URL ?>/uploads/<?= e($data['logo']) ?>"
                   id="logoPreview" class="mb-3 rounded" style="max-height:100px;max-width:100%;">
            <?php else: ?>
              <div id="logoPreview" class="mb-3 text-muted">
                <i class="bi bi-image" style="font-size:3rem;"></i>
                <div class="fs-sm">Belum ada logo</div>
              </div>
            <?php endif; ?>
            <label class="btn btn-outline-primary btn-sm">
              <i class="bi bi-upload me-1"></i> Upload Logo
              <input type="file" name="logo" accept="image/*" class="d-none img-upload-input" data-preview="logoPreview">
            </label>
            <div class="text-muted mt-1 fs-sm">PNG/JPG, max 2MB</div>
          </div>
        </div>
        <div class="card">
          <div class="card-body">
            <button type="submit" class="btn btn-primary w-100">
              <i class="bi bi-save me-1"></i> Simpan Pengaturan
            </button>
          </div>
        </div>
      </div>
    </div>
  </form>
</div>
<?php include __DIR__ . '/../../views/layouts/footer.php'; ?>
</div>
</div>
