<?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">
                <table id="example1" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>No</th>
                            <th>NO Order Custom</th>

                            <?php $role = auth()->user()->role; ?>
                            <?php if ($role != 'customer'): ?>
                                <th>Nama Customer</th>
                            <?php endif; ?>
                            <th>Tanggal Revisi</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $i = 1 ?>
                        <?php foreach ($data as $row) : ?>
                            <tr>
                                <td style="width: 30px;"><?= $i++ ?></td>
                                <td><?= $row->no_order_custom  ?></td>
                                <?php if ($role != 'customer'): ?>
                                    <td><?= $row->user_name ?? '-' ?></td>
                                <?php endif; ?>
                                <td>
                                    <?php $dt = $row->created_at; ?>
                                    <?= $dt ? date('d/m/Y H:i', strtotime($dt)) : '-' ?>
                                </td>
                                <td style="width: 100px;">
                                    <a class="btn btn-info btn-sm" onclick="show_lg('<?= base_url('riwayat_perubahan/detail/' . $row->id_revisi) ?>')">
                                        <i class="fas fa-eye"></i> Detail
                                    </a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div><!-- /.container-fluid -->
</section>

<!-- Modal Approve Revision -->
<div class="modal fade" id="modalApproveRevision" tabindex="-1" role="dialog" aria-labelledby="modalApproveLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form id="formApproveRevision" method="post">
                <div class="modal-header">
                    <h5 class="modal-title" id="modalApproveLabel">Setujui Revisi</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="biaya_revisi">Biaya Tambahan untuk Revisi (Optional)</label>
                        <input type="number" class="form-control" id="biaya_revisi" name="biaya_revisi" step="1000" value="0" placeholder="Input biaya jika ada biaya tambahan">
                        <small class="form-text text-muted">Biarkan 0 jika revisi tidak ada biaya tambahan</small>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-success">Setujui & Simpan</button>
                </div>
            </form>
        </div>
    </div>
</div>

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

<script>
    function setRevisionId(id) {
        let form = document.getElementById('formApproveRevision');
        form.action = '<?= base_url('riwayat_perubahan/approveRevision/') ?>' + id;
    }
</script>