<section class="content-header">
  <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"><a href="<?php echo site_url('master/jabatan'); ?>">Master Jabatan</a></li>
          <li class="breadcrumb-item active"><?php echo $row ? 'Edit' : 'Tambah'; ?></li>
        </ol>
      </div>
    </div>
  </div>
</section>

<section class="content">
  <div class="container-fluid">
    <div class="row justify-content-center">
      <div class="col-md-8">
        <div class="card card-danger card-outline">
          <div class="card-header">
            <h3 class="card-title">
              <i class="fa fa-<?php echo $row ? 'pencil' : 'plus'; ?> mr-1"></i>
              <?php echo $row ? 'Edit Jabatan' : 'Tambah Jabatan Baru'; ?>
            </h3>
          </div>
          <?php
            $form_action = $row
              ? site_url('master/jabatan/edit/' . $row->id_jabatan)
              : site_url('master/jabatan/tambah');
            echo form_open($form_action, ['id' => 'form-jabatan']);
          ?>
          <div class="card-body">
            <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label>Divisi <span class="text-danger">*</span></label>
                  <select name="id_divisi" id="id_divisi"
                          class="form-control <?php echo form_error('id_divisi') ? 'is-invalid' : ''; ?>">
                    <option value="">-- Pilih Divisi --</option>
                    <?php foreach ($list_divisi as $d): ?>
                      <option value="<?php echo $d->id_divisi; ?>"
                        <?php echo set_select('id_divisi', $d->id_divisi, ($row && $row->id_divisi == $d->id_divisi)); ?>>
                        <?php echo html_escape($d->nama_divisi); ?>
                      </option>
                    <?php endforeach; ?>
                  </select>
                  <?php if (form_error('id_divisi')): ?>
                    <div class="invalid-feedback"><?php echo form_error('id_divisi'); ?></div>
                  <?php endif; ?>
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-group">
                  <label>Level Jabatan <span class="text-danger">*</span></label>
                  <select name="level_jabatan"
                          class="form-control <?php echo form_error('level_jabatan') ? 'is-invalid' : ''; ?>">
                    <option value="">-- Pilih Level --</option>
                    <?php foreach ([1 => 'Manager', 2 => 'Supervisor', 3 => 'Staff'] as $lvl => $lbl): ?>
                      <option value="<?php echo $lvl; ?>"
                        <?php echo set_select('level_jabatan', $lvl, ($row && $row->level_jabatan == $lvl)); ?>>
                        <?php echo $lbl; ?>
                      </option>
                    <?php endforeach; ?>
                  </select>
                  <?php if (form_error('level_jabatan')): ?>
                    <div class="invalid-feedback"><?php echo form_error('level_jabatan'); ?></div>
                  <?php endif; ?>
                </div>
              </div>
            </div>

            <div class="row">
              <div class="col-md-4">
                <div class="form-group">
                  <label>Kode Jabatan <span class="text-danger">*</span></label>
                  <input type="text" name="kode_jabatan"
                         class="form-control <?php echo form_error('kode_jabatan') ? 'is-invalid' : ''; ?>"
                         value="<?php echo html_escape(set_value('kode_jabatan', $row->kode_jabatan ?? '')); ?>"
                         maxlength="10" placeholder="Cth: KPROD" style="text-transform:uppercase;">
                  <?php if (form_error('kode_jabatan')): ?>
                    <div class="invalid-feedback"><?php echo form_error('kode_jabatan'); ?></div>
                  <?php endif; ?>
                </div>
              </div>
              <div class="col-md-8">
                <div class="form-group">
                  <label>Nama Jabatan <span class="text-danger">*</span></label>
                  <input type="text" name="nama_jabatan"
                         class="form-control <?php echo form_error('nama_jabatan') ? 'is-invalid' : ''; ?>"
                         value="<?php echo html_escape(set_value('nama_jabatan', $row->nama_jabatan ?? '')); ?>"
                         maxlength="100" placeholder="Nama lengkap jabatan">
                  <?php if (form_error('nama_jabatan')): ?>
                    <div class="invalid-feedback"><?php echo form_error('nama_jabatan'); ?></div>
                  <?php endif; ?>
                </div>
              </div>
            </div>
          </div>
          <div class="card-footer d-flex justify-content-between">
            <a href="<?php echo site_url('master/jabatan'); ?>" class="btn btn-secondary">
              <i class="fa fa-arrow-left mr-1"></i> Kembali
            </a>
            <button type="submit" class="btn btn-danger">
              <i class="fa fa-save mr-1"></i> <?php echo $row ? 'Simpan Perubahan' : 'Tambah Jabatan'; ?>
            </button>
          </div>
          <?php echo form_close(); ?>
        </div>
      </div>
    </div>
  </div>
</section>
