<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/divisi'); ?>">Master Divisi</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-7">
        <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 Divisi' : 'Tambah Divisi Baru'; ?>
            </h3>
          </div>
          <?php
            $form_action = $row
              ? site_url('master/divisi/edit/' . $row->id_divisi)
              : site_url('master/divisi/tambah');
            echo form_open($form_action, ['id' => 'form-divisi']);
          ?>
          <div class="card-body">
            <div class="form-group">
              <label>Kode Divisi <span class="text-danger">*</span></label>
              <input type="text" name="kode_divisi"
                     class="form-control <?php echo form_error('kode_divisi') ? 'is-invalid' : ''; ?>"
                     value="<?php echo html_escape(set_value('kode_divisi', $row->kode_divisi ?? '')); ?>"
                     maxlength="10" placeholder="Cth: PROD" style="text-transform:uppercase;">
              <?php if (form_error('kode_divisi')): ?>
                <div class="invalid-feedback"><?php echo form_error('kode_divisi'); ?></div>
              <?php endif; ?>
              <small class="text-muted">Maks. 10 karakter, huruf/angka saja. Akan diubah ke huruf kapital.</small>
            </div>

            <div class="form-group">
              <label>Nama Divisi <span class="text-danger">*</span></label>
              <input type="text" name="nama_divisi"
                     class="form-control <?php echo form_error('nama_divisi') ? 'is-invalid' : ''; ?>"
                     value="<?php echo html_escape(set_value('nama_divisi', $row->nama_divisi ?? '')); ?>"
                     maxlength="100" placeholder="Nama lengkap divisi">
              <?php if (form_error('nama_divisi')): ?>
                <div class="invalid-feedback"><?php echo form_error('nama_divisi'); ?></div>
              <?php endif; ?>
            </div>

            <div class="form-group">
              <label>Keterangan</label>
              <textarea name="keterangan" class="form-control" rows="3"
                        placeholder="Deskripsi singkat divisi (opsional)"><?php echo html_escape(set_value('keterangan', $row->keterangan ?? '')); ?></textarea>
            </div>
          </div>
          <div class="card-footer d-flex justify-content-between">
            <a href="<?php echo site_url('master/divisi'); ?>" 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 Divisi'; ?>
            </button>
          </div>
          <?php echo form_close(); ?>
        </div>
      </div>
    </div>
  </div>
</section>
