<?php if (auth()->user()->role == 'customer'): ?>
    <?= $this->extend('layouts/topbar') ?>
<?php else: ?>
    <?= $this->extend('layouts/sidebar') ?>
<?php endif; ?>

<?= $this->section('content') ?>
<section class="content">
    <div class="container-fluid">
        <!-- Small boxes (Stat box) -->
        <div class="card mb-3">
            <div class="card-body">
                <?php if (auth()->user()->role == 'admin'): ?>
                    <button class="btn btn-success mb-3" onclick="show('<?= site_url('model/create') ?>')"><i class="fas fa-plus"></i></i>&nbsp; Tambah Data</button>
                <?php endif; ?>
                <table id="example1" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>No</th>
                            <th>Foto Model</th>
                            <th>Nama Model</th>
                            <th>Ongkos Pengerjaan</th>
                            <?php if (auth()->user()->role == 'admin'): ?>
                                <th>Aksi</th>
                            <?php endif; ?>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $i = 1 ?>
                        <?php foreach ($data as $data) : ?>
                            <tr>
                                <td style="width: 30px;"><?= $i++ ?></td>
                                <td><img alt="Avatar" width="50" src="<?= base_url($data->foto_model) ?>"></td>
                                <td><?= $data->nama_model  ?></td>
                                <td>Rp. <?= number_format($data->ongkos_pengerjaan, 0, ",", ".") ?></td>
                                <?php if (auth()->user()->role == 'admin'): ?>
                                    <td style="width: 230px;">
                                        <a class="btn btn-primary btn-sm mt-1" onclick="show('<?= base_url('model/detail/' . $data->kode_model) ?>')"><i class="fas fa-eye"></i>&nbsp;&nbsp;Detail</a>
                                        <a class="btn btn-info btn-sm mt-1" href="<?= base_url('model/edit/' . $data->kode_model) ?>"><i class="fas fa-pencil-alt"></i>&nbsp;&nbsp;Edit</a>
                                        <a class="btn btn-danger btn-sm mt-1" onclick="notificationforDelete(event, this)" href="<?= base_url('model/delete/' . $data->kode_model) ?>"><i class="fas fa-trash"></i>&nbsp;&nbsp; Delete</a>
                                    </td>
                                <?php endif; ?>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div><!-- /.container-fluid -->
</section>
<?= $this->endSection() ?>