<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
        <div class="container-fluid">
            <?= $this->session->flashdata('msg') ?>
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0">Data Kriteria</h1>
                </div><!-- /.col -->
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="<?=base_url('dashboard')?>">Beranda</a></li>
                        <li class="breadcrumb-item active">Kriteria</li>
                    </ol>
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

    <!-- Main content -->
    <div class="content">
        <div class="container-fluid">
            <div class="card">
                <!-- /.card-header -->

                <div class="card-body">

                    <a data-toggle="modal" data-target="#tambah" href=""><button
                            class="btn btn-sm bg-blue text-white">Tambah
                            Kriteria</button></a>
                    <br><br>
                    <div class="table-responsive">
                        <table class="table table-flush" id="datatable-basic">
                            <thead>
                                <tr>
                                    <th>No</th>
                                    <th>Kode</th>
                                    <th>Nama Kriteria</th>
                                    <th>Bobot</th>
                                    <th>Tipe</th>
                                    <th>Aksi</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $i = 1; foreach ($list_kriteria as $row): ?>
                                <tr>
                                    <td><?=$i++?> </td>
                                    <td><?=$row->kode_kriteria?> </td>
                                    <td><?=$row->nama_kriteria?> </td>
                                    <td> <?=$row->bobot_vektor?></td>
                                    <td><?=$row->tipe?> </td>
                                    <td>
                                        <a data-toggle="modal" data-target="#edit-<?=$row->id_kriteria?>"
                                            href=""><button class="btn btn-sm bg-warning text-white">Edit</button></a>
                                        <a data-toggle="modal" data-target="#delete-<?=$row->id_kriteria?>"
                                            href=""><button class="btn btn-sm bg-red text-white">Hapus</button></a>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <!-- /.container-fluid -->
        </div>
        <!-- /.content -->
    </div>
</div>

<!-- /.content-wrapper -->

<!-- form untuk tambah data  -->
<div class="modal fade" id="tambah" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="defaultModalLabel">
                    <center>Form Tambah Kriteria</center>
                </h4>
            </div>
            <div class="modal-body">
                <form action="<?= base_url('kriteria/proseskriteria')?>" method="Post">

                    <table class="table table-bordered">
                        <tr>
                            <th>Kode</th>
                            <th>
                                <input type="text" class="form-control" name="kode_kriteria"
                                    placeholder="Masukkan Kode Kriteria" required autofocus>
                            </th>
                        </tr>
                        <tr>
                            <th>Nama Kriteria</th>
                            <th>
                                <input type="text" class="form-control" name="nama_kriteria"
                                    placeholder="Masukkan Nama Kriteria" required autofocus>
                            </th>
                        </tr>
                        <tr>
                            <th>Bobot</th>
                            <th>
                                <input type="text" class="form-control" name="bobot_vektor"
                                    placeholder="Masukkan Bobot Kriteria (0.2)" required autofocus>
                            </th>
                        </tr>
                        <tr>
                            <th>Tipe</th>
                            <th>
                                <input name="tipe" type="radio" id="tipe1" value="Benefit" required />
                                <label for="tipe1">Benefit</label>
                                <input name="tipe" type="radio" id="tipe2" value="Cost" required />
                                <label for="tipe2">Cost</label>
                            </th>
                        </tr>
                    </table>

                    <input type="submit" class="btn bg-indigo btn-block text-white" name="tambah" value="Tambah">
                    <br><br>

                    <?php echo form_close() ?>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-link waves-effect" data-dismiss="modal">Tutup</button>
            </div>
        </div>
    </div>
</div>

<!-- form untuk edit data  -->
<?php $i = 1; foreach ($list_kriteria as $row): ?>
<div class="modal fade" id="edit-<?=$row->id_kriteria?>">
    <div class="modal-dialog edit-<?=$row->id_kriteria?>">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Form Edit Data Kriteria</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form action="<?= base_url('kriteria/proseskriteria')?>" method="Post">
                    <table class="table table-bordered table-striped table-hover" style="max-height: 300px">
                        <input type="hidden" name="id_kriteria" value="<?=$row->id_kriteria?>">
                        <tbody>
                            <tr>
                                <th>Kode</th>
                                <th>
                                    <input type="text" class="form-control" name="kode_kriteria"
                                        placeholder="Masukkan Kode Kriteria " required autofocus
                                        value="<?=$row->kode_kriteria?>">
                                </th>
                            </tr>
                            <tr>
                                <th>Nama Kriteria</th>
                                <th>
                                    <input type="text" class="form-control" name="nama_kriteria"
                                        placeholder="Masukkan Nama Kriteria " required autofocus
                                        value="<?=$row->nama_kriteria?>">
                                </th>
                            </tr>
                            <tr>
                                <th>Bobot</th>
                                <th>
                                    <input type="text" class="form-control" name="bobot_vektor"
                                        placeholder="Masukkan Bobot Kriteria" required autofocus
                                        value="<?=$row->bobot_vektor?>">
                                </th>
                            </tr>
                            <tr>
                                <th>Tipe</th>
                                <th>
                                    <input name="tipe" type="radio" id="tipe1"
                                        <?php if ($row->tipe== "Benefit") {echo "checked";}?> value="Benefit"
                                        required />
                                    <label for="tipe1">Benefit</label>
                                    <input name="tipe" type="radio" id="tipe2"
                                        <?php if ($row->tipe== "Cost") {echo "checked";}?> value="Cost" required />
                                    <label for="tipe2">Cost</label>
                                </th>
                            </tr>

                        </tbody>
                    </table>
                    <input type="submit" class="btn bg-blue btn-block text-white " name="edit" value="Simpan"> <br><br>

                    <?php echo form_close() ?>
            </div>
            <div class="modal-footer justify-content-between">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<?php endforeach; ?>


<!-- form untuk hapus data  -->
<?php $i = 1; foreach ($list_kriteria as $row): ?>
<div class="modal fade" id="delete-<?=$row->id_kriteria?>" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="defaultModalLabel">
                    <center>Hapus data kriteria?</center>
                </h4>
                <center><span style="color :red"><i>Semua data yang terkait dengan <?=$row->nama_kriteria?> akan
                            dihapus.</i></span></center>
            </div>
            <div class="modal-body">

                <div class="row">
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">

                        <form action="<?= base_url('kriteria/proseskriteria')?>" method="Post">
                            <input type="hidden" value="<?=$row->id_kriteria?>" name="id_kriteria">
                            <input type="submit" class="btn bg-green btn-block text-white " name="hapus" value="Ya">

                    </div>
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
                        <button type="button" class="btn bg-red btn-block text-white"
                            data-dismiss="modal">Tidak</button>
                    </div>
                    <?php echo form_close() ?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php endforeach; ?>