<section class="content-header" id="konfigurasi-utama">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-6">
        <h1><?php echo $page_title; ?></h1>
        <p class="text-muted mb-0"><?php echo $page_subtitle; ?></p>
      </div>
      <div class="col-sm-6 text-right">
        <ol class="breadcrumb float-sm-right">
          <li class="breadcrumb-item"><a href="<?php echo site_url('dashboard'); ?>">Dashboard</a></li>
          <li class="breadcrumb-item active">Konfigurasi Sistem</li>
        </ol>
      </div>
    </div>
  </div>
</section>

<section class="content">
  <div class="container-fluid">
    <?php echo form_open('master/konfigurasi/simpan', ['id'=>'form-konfigurasi']); ?>

    <?php foreach ($groups as $group_key => $group): ?>
    <div class="card card-danger card-outline" id="<?php echo html_escape($group_key); ?>">
      <div class="card-header">
        <h3 class="card-title">
          <i class="fa <?php echo $group['icon']; ?> mr-1"></i> <?php echo $group['label']; ?>
        </h3>
      </div>
      <div class="card-body">
        <div class="row">
          <?php foreach ($group['keys'] as $kunci): ?>
          <?php
            $val = $config[$kunci] ?? '';
            $label = ucwords(str_replace(['_',' '], [' ',' '], $kunci));
            $is_persen = strpos($kunci, 'bpjs') !== FALSE || strpos($kunci, 'tarif') !== FALSE;
          ?>
          <div class="col-md-4">
            <div class="form-group">
              <label><?php echo html_escape($label); ?></label>
              <?php if ($is_persen): ?>
              <div class="input-group">
                <input type="number" step="0.01" name="<?php echo $kunci; ?>"
                       class="form-control" value="<?php echo html_escape($val); ?>">
                <div class="input-group-append"><span class="input-group-text">%</span></div>
              </div>
              <?php elseif ($kunci === 'jam_kerja_per_hari'): ?>
              <div class="input-group">
                <input type="number" name="<?php echo $kunci; ?>"
                       class="form-control" value="<?php echo html_escape($val); ?>" min="1" max="24">
                <div class="input-group-append"><span class="input-group-text">jam/hari</span></div>
              </div>
              <?php elseif ($kunci === 'alamat_perusahaan'): ?>
              <textarea name="<?php echo $kunci; ?>" class="form-control" rows="2"><?php echo html_escape($val); ?></textarea>
              <?php else: ?>
              <input type="text" name="<?php echo $kunci; ?>"
                     class="form-control" value="<?php echo html_escape($val); ?>">
              <?php endif; ?>
            </div>
          </div>
          <?php endforeach; ?>
        </div>
      </div>
    </div>
    <?php endforeach; ?>

    <div class="mb-4 text-right">
      <button type="submit" class="btn btn-danger">
        <i class="fa fa-save mr-1"></i> Simpan Semua Konfigurasi
      </button>
    </div>

    <?php echo form_close(); ?>
  </div>
</section>
