<?php $this->load->helper('az_config'); ?>
<!DOCTYPE html>
<html>
<head>
<title>Hari Libur</title>
<link rel="stylesheet" href="<?php echo base_url();?>assets/plugins/bootstrap/bootstrap.min.css">
<style>
body{padding:20px;background:#f5f5f5;}
.container{max-width:760px;margin:0 auto;background:#fff;padding:24px;border-radius:8px;box-shadow:0 2px 10px rgba(0,0,0,.1);}
h2{color:#333;border-bottom:2px solid #2196F3;padding-bottom:10px;}
.navbtn{margin-bottom:14px;} .navbtn a{margin-right:6px;}
.ok{background:#d4edda;color:#155724;padding:10px;border-radius:5px;margin-bottom:14px;}
.err{background:#f8d7da;color:#721c24;padding:10px;border-radius:5px;margin-bottom:14px;}
table{width:100%;border-collapse:collapse;margin-top:10px;}
table th,table td{border:1px solid #ddd;padding:8px;}
table th{background:#f5f5f5;}
.box{border:1px solid #eee;border-radius:6px;padding:14px;margin-bottom:18px;background:#fafafa;}
.usrlist{max-height:160px;overflow:auto;border:1px solid #ddd;border-radius:5px;padding:8px;background:#fff;}
</style>
</head>
<body>
<div class="container">
<h2><i class="fa fa-calendar-times-o"></i> Hari Libur</h2>

<div class="navbtn">
  <a href="<?php echo base_url();?>index.php/access_schedule" class="btn btn-default btn-sm">Jadwal User</a>
  <a href="<?php echo base_url();?>index.php/access_schedule/holiday" class="btn btn-primary btn-sm">Hari Libur</a>
  <a href="<?php echo base_url();?>index.php/home" class="btn btn-default btn-sm">Kembali</a>
</div>

<?php if ($this->session->flashdata('ok')): ?><div class="ok"><?php echo $this->session->flashdata('ok'); ?></div><?php endif; ?>
<?php if ($this->session->flashdata('err')): ?><div class="err"><?php echo $this->session->flashdata('err'); ?></div><?php endif; ?>

<div class="box">
  <h4>Tambah / Ubah Hari Libur</h4>
  <form method="post" action="<?php echo base_url();?>index.php/access_schedule/save_holiday">
    <div class="form-group">
      <label>Tanggal Libur <span style="color:red">*</span></label>
      <input type="date" name="holiday_date" class="form-control" required>
    </div>
    <div class="form-group">
      <label>Keterangan (opsional)</label>
      <input type="text" name="label" class="form-control" placeholder="cth: Idul Fitri, Tahun Baru">
    </div>
    <div class="form-group">
      <label>Mode</label><br>
      <label style="font-weight:normal;"><input type="radio" name="mode" value="all" checked> Semua libur (tidak ada yang bisa login)</label><br>
      <label style="font-weight:normal;"><input type="radio" name="mode" value="except"> Ada yang tetap aktif (centang di bawah)</label>
    </div>
    <div class="form-group">
      <label>User yang TETAP AKTIF di hari libur (dipakai hanya jika mode “Ada yang tetap aktif”)</label>
      <div class="usrlist">
        <?php foreach ($users as $u): ?>
          <div><label style="font-weight:normal;">
            <input type="checkbox" name="except_user[]" value="<?php echo (int)$u->iduser; ?>">
            <?php echo htmlspecialchars($u->name); ?> (<?php echo htmlspecialchars($u->username); ?>)
          </label></div>
        <?php endforeach; ?>
      </div>
    </div>
    <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Simpan Hari Libur</button>
  </form>
</div>

<h4>Daftar Hari Libur Aktif</h4>
<table>
  <tr><th>Tanggal</th><th>Keterangan</th><th>Mode</th><th>Yang Tetap Aktif</th><th>Aksi</th></tr>
  <?php if (count($holidays)==0): ?>
    <tr><td colspan="5" style="text-align:center;color:#888;">Belum ada hari libur.</td></tr>
  <?php else: foreach ($holidays as $h): ?>
    <tr>
      <td><?php echo htmlspecialchars($h->holiday_date); ?></td>
      <td><?php echo htmlspecialchars($h->label); ?></td>
      <td><?php echo ((int)$h->all_off===1)?'Semua libur':'Ada yang aktif'; ?></td>
      <td><?php echo count($h->exception_names)?htmlspecialchars(implode(', ',$h->exception_names)):'-'; ?></td>
      <td><a href="<?php echo base_url();?>index.php/access_schedule/delete_holiday?id=<?php echo (int)$h->id; ?>"
             onclick="return confirm('Hapus hari libur ini?')" style="color:#c0392b;">Hapus</a></td>
    </tr>
  <?php endforeach; endif; ?>
</table>

</div>
</body>
</html>