@extends('layouts.app')
<style>
    .form-group.required .control-label:after {
        content:"*";
        color:red;
    }
</style>
@section('content')
<div class="container">
    <div class="row justify-content-center mt-3">
        <div class="col-md-12">
            <div class="card">
                
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb pb-3">
                      <li class="breadcrumb-item"><a href="{{ route('home') }}">Home</a></li>
                      <li class="breadcrumb-item active" aria-current="page">Kakitangan</li>
                    </ol>
                  </nav>


                <div class="card-body">
                    <form action="{{ route('kakitangan.harian') }}" onsubmit="validatekakitangan()" method="post">
                        @csrf
                        <div class="row">
                            <div class="col-6 text-center">
                                <div class="row col-12">
                                    <label class="col-6">Pengurus Cawangan :</label>
                                    @if($pc != null)
                                        <input type="text" class="form-control col-6" readonly name="pc" id="pc" value="{{ $pc['name'] }}"/>
                                        <input type="text" class="form-control col-6" hidden name="pc_id" id="pc_id" value="{{ $pc['id'] }}"/>
                                    @else
                                        <input type="text" class="form-control col-6" readonly name="pc" id="pc" value="Tiada Pengurus Cawangan"/>
                                    @endif
                                </div>

                                <div class="row col-12">   
                                    <label class="col-6">Pen. Peng. Cawangan :</label>
                                    @if($ppc != null)
                                        <input type="text" class="form-control col-6" readonly name="ppc" id="ppc" value="{{ $ppc['name'] }}"/>
                                        <input type="text" class="form-control col-6" hidden name="ppc_id" id="ppc_id" value="{{ $ppc['id'] }}"/>
                                    @else
                                        <input type="text" class="form-control col-6" readonly name="pc" id="pc" value="Tiada Penolong Pengurus Cawangan"/>
                                    @endif
                                </div>
                            </div>

                            <div class="col-6 text-center">
                                <div class="row col-12">
                                    <label class="col-6">Khazanah <span class="text-danger">*</span> :</label>
                                    <select name="khazanah" id="khazanah" class="form-control col-6">
                                        <option value="" selected disabled>Sila Pilih Khazanah</option>
                                        @foreach ($khazanah as $index=>$k)
                                            <option value="{{ $k['id'] }}" {{ $k['role_harian'] == 'khazanah' ? 'selected' : ''}}>{{ $k['name'] }}</option>
                                        @endforeach
                                    </select>
                                </div>
                                
                                <div class="row col-12">
                                    <label class="col-6">Penilai 1 <span class="text-danger">*</span> :</label>
                                    <select name="penilai" id="penilai" class="form-control col-6">
                                        <option value="" selected disabled>Sila Pilih Penilai 1</option>
                                        @foreach ($teller as $index=>$t)
                                            <option value="{{ $t['id'] }}" {{ $t['role_harian'] == 'penilai' ? 'selected' : ''}}>{{ $t['name'] }}</option>
                                        @endforeach
                                    </select>
                                </div>

                                <div class="row col-12">
                                    <label class="col-6">Penilai 2 :</label>
                                    <select name="penilai2" id="penilai2" class="form-control col-6">
                                        <option value="" selected>Tiada Penilai 2</option>
                                        @foreach ($teller as $index=>$t)
                                            <option value="{{ $t['id'] }}" {{ $t['role_harian'] == 'penilai2' ? 'selected' : ''}}>{{ $t['name'] }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                        

                        <div class="col-12 row justify-content-end mt-4 mb-4">
                            <input type="submit" class="btn btn-primary mr-4" value="Sahkan">
                        </div>
                    </form>
                    


                    <table class='table table-hover table-striped' id='table-kakitangan' style="width:100%;">
                        <thead class="thead-dark">
                            <tr>
                                <th>Bil</th>
                                <th>Teller</th>
                                <th>Cawangan</th>
                                <th>Roles</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach ($teller as $index=>$t)
                            <tr>
                            <td>{{ $loop->iteration }}</td>
                            <td>{{ $t['name'] }}</td>
                            <td>{{ $t['cawangan'] }}</td>
                            <td>{{ $t['role_harian'] }}</td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                
                </div>
            </div>
        </div>
    </div>
</div>
<script>

    function validatekakitangan(){
        var khazanah = $('#khazanah').val();
        var penilai = $('#penilai').val();
        var penilai2 = $('#penilai2').val();

        console.log(penilai);
        if(khazanah == null || penilai == null){
            Swal.fire({
                icon: 'error',
                title: 'Amaran!',
                text: 'Sila Pilih Khazanah dan Penilai Bertugas Hari Ini.'
            });
            event.preventDefault();
            return false;
        }
        if(penilai == penilai2 && penilai != null){
            Swal.fire({
                icon: 'error',
                title: 'Amaran!',
                text: 'Penilai Sama'
            });
            event.preventDefault();
            return false;
        }

        return true;
    }

    var tablekakitangan = $('#table-kakitangan').DataTable({
          "scrollX": true
        });
    
    </script>
@endsection
