<?= $this->extend('layout/template') ?>
<?= $this->section('content') ?>

<div class="card">
    <div class="card-header bg-warning">
        <h3 class="card-title">
            <i class="fas fa-edit"></i> Edit Buku
        </h3>
    </div>

    <form action="<?= base_url('buku/update/'.$buku['id']) ?>" method="post">
        <?= csrf_field(); ?>

        <div class="card-body">

            <div class="row">

                <div class="col-md-6">

                    <div class="form-group">
                        <label>Kode Buku</label>
                        <input type="text" name="kode_buku" class="form-control"
                               value="<?= $buku['kode_buku'] ?>" required>
                    </div>

                    <div class="form-group">
                        <label>Judul Buku</label>
                        <input type="text" name="judul" class="form-control"
                               value="<?= $buku['judul'] ?>" required>
                    </div>

                    <div class="form-group">
                        <label>Penulis</label>
                        <input type="text" name="penulis" class="form-control"
                               value="<?= $buku['penulis'] ?>" required>
                    </div>

                    <div class="form-group">
                        <label>Penerbit</label>
                        <input type="text" name="penerbit" class="form-control"
                               value="<?= $buku['penerbit'] ?>">
                    </div>

                </div>

                <div class="col-md-6">

                    <div class="form-group">
                        <label>Tahun</label>
                        <input type="number" name="tahun" class="form-control"
                               value="<?= $buku['tahun'] ?>">
                    </div>

                    <div class="form-group">
                        <label>Rak</label>
                        <input type="text" name="rak" class="form-control"
                               value="<?= $buku['rak'] ?>">
                    </div>

                    <div class="form-group">
                        <label>Kategori</label>

                        <select name="kategori" class="form-control">

                            <?php
                            $kategori=[
                                'Pelajaran',
                                'Novel',
                                'Agama',
                                'Komputer',
                                'Ensiklopedia',
                                'Lainnya'
                            ];

                            foreach($kategori as $k):
                            ?>

                            <option value="<?= $k ?>"
                            <?= $buku['kategori']==$k?'selected':'' ?>>
                                <?= $k ?>
                            </option>

                            <?php endforeach ?>

                        </select>

                    </div>

                    <div class="form-group">
                        <label>Stok</label>
                        <input type="number" name="stok" class="form-control"
                               value="<?= $buku['stok'] ?>">
                    </div>

                </div>

            </div>

        </div>

        <div class="card-footer">

            <button class="btn btn-success">

                <i class="fas fa-save"></i>

                Update

            </button>

            <a href="<?= base_url('buku') ?>" class="btn btn-secondary">

                Kembali

            </a>

        </div>

    </form>

</div>

<?= $this->endSection() ?>