  <?= $this->extend('layout/admin') ?>

  <?= $this->section('title') ?>
  <title>BERITA &mdash; KUA WAY BUNGUR</title>
  <?= $this->endSection() ?>

  <?= $this->section('content') ?>
  <section class="section">
      <div class="section-header">
          <h1>Berita</h1>

          <div class="section-header-breadcrumb">
              <div class="breadcrumb-item active"><a href="<?= base_url('dashboard') ?>">Dashboard</a></div>
              <div class="breadcrumb-item">Berita</div>
          </div>
      </div>

      <div class="section-body">
          <h2 class="section-title">Kelola Berita</h2>
          <p class="section-lead">
              Halaman ini berisi data berita.
          </p>
          <!--notifikasi berhasil-->
          <div class="swal" data-swal="<?= session('success') ?>"></div>
          <!--notifikasi berhasil-->
          <div class="row">
              <div class="col-12 col-md-12 col-lg-12">
                  <div class="card">
                      <div class="card-header">
                          <div class="section-header-button">
                              <a href="<?= base_url('berita/add') ?>" type="button" class="btn btn-info sm">
                                  <i class="fas fa-add"></i> Tambah Data
                              </a>
                          </div>
                      </div>
                      <div class="card-body table-responsive">
                          <table class="table table-striped table-md" id="table-1" style="width: 100%;">
                              <thead>
                                  <tr>
                                      <th class="text-center" scope="col">#</th>
                                      <th class="text-center" scope="col">Judul</th>
                                      <th scope="col">Isi</th>
                                      <th scope="col">Kategori</th>
                                      <th scope="col">Tanggal</th>
                                      <th data-sortable="false" class="text-center" scope="col">Opsi</th>
                                  </tr>
                              </thead>
                              <tbody>
                                  <?php foreach ($beritaData as $key => $value) : ?>
                                  <tr>
                                      <th class="text-center align-middle" scope="row"><?= $key + 1 ?></th>

                                      <td class="text-left align-middle"><?= $value->judul ?></td>
                                      <td class="text-left align-middle">
                                          <?= substr(strip_tags($value->isi), 0, 70) ?>...</td>
                                      </td>
                                      <td class="text-left align-middle"> <?= $value->kategori ?></td>
                                      <td class="text-left align-middle">
                                          <?= date('d-m-Y', strtotime($value->tanggal)) ?></td>
                                      <td class="text-center align-middle">
                                          <div class="">
                                              <a style="margin: 2px;"
                                                  href="<?= base_url('berita/edit/' . $value->id_berita) ?>"
                                                  type="button" class="btn btn-success sm">
                                                  <i class="fas fa-edit"></i>
                                              </a>
                                              <form action="<?= base_url('berita/' . $value->id_berita) ?>"
                                                  method="post" class="d-inline" id="del-<?= $value->id_berita ?>">
                                                  <?= csrf_field() ?>
                                                  <input type="hidden" name="_method" value="DELETE">
                                                  <button class="btn btn-danger sm"
                                                      data-confirm="Hapus Data?|Apakah Anda Yakin?"
                                                      data-confirm-yes="submitDel(<?= $value->id_berita ?>)">
                                                      <i class="fas fa-trash-alt"></i>
                                                  </button>
                                              </form>
                                          </div>
                                      </td>
                                  </tr>
                                  <?php endforeach; ?>
                              </tbody>
                          </table>
                      </div>
                  </div>
              </div>
  </section>
  <?= $this->endSection() ?>