@include('layouts.header_admin')

<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-gray-800"><i class="fas fa-fw fa-cubes"></i> Data Sub Kriteria</h1>
</div>

{!! session('message') !!}

@if (count($kriteria)==0)
<div class="alert alert-info">
    Data masih kosong.
</div>
@endif

@foreach ($kriteria as $key)
<div class="card shadow mb-4">
    <!-- /.card-header -->
    <div class="card-header py-3">
        <div class="d-sm-flex align-items-center justify-content-between">
            <h6 class="m-0 font-weight-bold text-primary"><i class="fa fa-table"></i> {{ $key->keterangan }} ({{ $key->kode_kriteria }})</h6>
            
            <a href="#tambah{{ $key->id_kriteria }}" data-toggle="modal" class="btn btn-sm btn-success"> <i class="fa fa-plus"></i> Tambah Data </a>
        </div>
    </div>
    
    <div class="modal fade" id="tambah{{ $key->id_kriteria }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="myModalLabel"><i class="fa fa-plus"></i> Tambah {{ $key->keterangan }}</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                </div>
                <form action="{{ url('SubKriteria/simpan') }}" method="POST">
                    {{ csrf_field() }}
                    <div class="modal-body">
                        <input type="hidden" name="id_kriteria" value="{{ $key->id_kriteria }}">
                        <div class="form-group">
                            <label for="deskripsi" class="font-weight-bold">Nama Sub Kriteria</label>
                            <input autocomplete="off" type="text" id="deskripsi" class="form-control" name="deskripsi" required>
                        </div>
                        <div class="form-group">
                            <label for="nilai" class="font-weight-bold">Nilai</label>
                            <input autocomplete="off" type="text" id="nilai" name="nilai" class="form-control" required>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-warning" data-dismiss="modal"><i class="fa fa-times"></i> Batal</button>
                        <button type="submit" class="btn btn-success"><i class="fa fa-save"></i> Simpan</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-bordered" width="100%" cellspacing="0">
                <thead class="bg-primary text-white">
                    <tr align="center">                        
                        <th width="5%">No</th>
                        <th>Nama Sub Kriteria</th>
                        <th>Nilai</th>
                        <th width="15%">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                <?php
                    $sub_kriteria1 = \App\Models\SubKriteriaModel::data_sub_kriteria($key->id_kriteria);
                    $no = 1;
                    ?>

                    @foreach ($sub_kriteria1 as $key)
                    <tr align="center">
                        <td>{{ $no }}</td>
                        <td align="left">{{ $key->deskripsi }}</td>
                        <td>{{ $key->nilai }}</td>
                        <td>
                            <div class="btn-group" role="group">
                                <a data-toggle="modal" title="Edit Data" href="#editsk{{ $key->id_sub_kriteria }}" class="btn btn-warning btn-sm"><i class="fa fa-edit"></i></a>
                                <a data-toggle="tooltip" data-placement="bottom" title="Hapus Data" href="{{ url('SubKriteria/destroy/'.$key->id_sub_kriteria) }}" onclick="return confirm('Apakah anda yakin untuk menghapus data ini')" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></a>
                            </div>
                        </td>
                    </tr>

                    <!-- Modal -->
                    <div class="modal fade" id="editsk{{ $key->id_sub_kriteria }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="myModalLabel"><i class="fa fa-edit"></i> Edit {{ $key->deskripsi }}</h5>
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                </div>
                                <form action="{{ url('SubKriteria/edit/'.$key->id_sub_kriteria) }}" method="POST">
                                    {{ csrf_field() }}
                                    <div class="modal-body">
                                        <input type="hidden" name="id_kriteria" value="{{ $key->id_kriteria }}">
                                        <div class="form-group">
                                            <label for="deskripsi" class="font-weight-bold">Nama Sub Kriteria</label>
                                            <input type="text" id="deskripsi" autocomplete="off" class="form-control" value="{{ $key->deskripsi }}" name="deskripsi" required>
                                        </div>
                                        <div class="form-group">
                                            <label for="nilai" class="font-weight-bold">Nilai</label>
                                            <input type="text" autocomplete="off" id="nilai" name="nilai" class="form-control" value="{{ $key->nilai }}" required>
                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-warning" data-dismiss="modal"><i class="fa fa-times"></i> Batal</button>
                                        <button type="submit" class="btn btn-success"><i class="fa fa-save"></i> Update</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                    <?php
                    $no++;
                    ?>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
@endforeach  
@include('layouts.footer_admin')

<style>
    .page-item.active .page-link {
        background-color: #4e73df !important;
        border-color: #4e73df !important;
        color: white !important;
    }
    
    .page-link {
        color: #4e73df !important;
    }
    
    .page-link:hover {
        color: #2e59d9 !important;
    }
</style>

