@extends('layouts.master')

@section('title')
    Buku Ajar/Teks
@endsection

@section('header')
<div class="page-title">
    <h3>Buku Ajar/Teks</h3>
</div>
@endsection

@section('contents')
@php
 $menu = 'dashboard';
@endphp
    <div class="account-settings-container layout-top-spacing">
        <form action="{{ $edit ? route('bukuajar.update', ['bukuajar' => encrypt($bukuajar->id)]) : route('bukuajar.store') }}" method="POST">
            @if ($edit)
                {{ method_field('PUT') }}
            @endif
            @csrf
            <div class="account-content">
                <div class="scrollspy-example" data-spy="scroll" data-target="#account-settings-scroll" data-offset="-100">
                    <div class="row">

                        <div class="col-xl-12 col-lg-12 col-md-12 layout-spacing">
                            <div id="general-info" class="section general-info">
                                <div class="info">
                                    <h6 class="">Data Dosen</h6>
                                    <div class="row">
                                        <div class="col-lg-11 mx-auto">
                                            <div class="form-group mb-4">
                                                <div class="input-group @if ($errors->has('nidn')) has-error @endif">
                                                    <input type="text" class="form-control" id="input_nidn_dosen" value="{{ $edit ? $bukuajar->nidn : '' }}" placeholder="NIDN" aria-label="nidn">
                                                    <input type="text" class="form-control" name="nidn" value="{{ $edit ? $bukuajar->nidn : '' }}" id="nidn_dosen" placeholder="NIDN" aria-label="nidn" hidden>
                                                    <div class="input-group-append">
                                                        <button class="btn btn-info" onclick="checkNidn('nidn_dosen')" type="button">Cek</button>
                                                    </div>
                                                </div>
                                                @if($errors->has('nidn'))
                                                    <label id="login-error" class="text-danger" for="login">{{ $errors->first('nidn') }}</label>
                                                @endif
                                            </div>
                                            <div class="form-row mb-4">
                                                <div class="form-group col-md-6">
                                                    <label>Nama Dosen</label>
                                                    <input type="text" id="nama_nidn_dosen" class="form-control" id="namadosen" disabled>
                                                </div>
                                                <div class="form-group col-md-6">
                                                    <label>Program Studi</label>
                                                    <input type="text" id="prodi_nidn_dosen" class="form-control" id="programstudi" disabled>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-xl-12 col-lg-12 col-md-12 layout-spacing">
                            <div id="general-info" class="section general-info">
                                <div class="info">
                                    <h5 class="">Data Buku Ajar / Buku Teks</h5>
                                    <div class="row">
                                        <div class="col-md-11 mx-auto">
                                            <div class="row">
                                            @php $kategori=array('Buku Teks' => 'Buku Teks', 'Monograf' => 'Monograf', 'Buku Ajar' => 'Buku Ajar', 'Book Chapter' => 'Book Chapter', 'Buku Hasil Penelitian Lainnya' => 'Buku Hasil Penelitian Lainnya'); @endphp
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Pilih Kategori</label>
                                                        <select class="form-control" id="kategori" name="kategori">
                                                        @foreach($kategori as $item)
                                                            @if($edit)
                                                                <option value="{{$item}}" {{ ( $bukuajar->kategori == $item) ? 'selected' : '' }}>{{$item}}</option>
                                                            @else
                                                                <option value="{{$item}}">{{$item}}</option>
                                                            @endif
                                                        @endforeach
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                </div>
                                                <div class="col-md-12">
                                                    <div class="form-group">
                                                            <label>Judul</label>
                                                            <textarea class="form-control" id="judul" name="judul" placeholder="Judul" rows="5">{!! $edit ? $bukuajar->judul : old('judul') !!}</textarea>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>ISBN</label>
                                                        <input type="text" class="form-control mb-4" id="isbn" name="isbn" placeholder="ISBN"  value="{{ $edit ? $bukuajar->isbn : old('isbn') }}">
                                                    </div>
                                                </div>
                                                <div class="col-md-4">
                                                    <div class="form-group">
                                                        <label>Jumlah Halaman</label>
                                                        <input type="text" class="form-control mb-4" id="jumlahhalaman" name="jumlah_hal" placeholder="Jumlah Halaman"  value="{{ $edit ? $bukuajar->jumlah_hal : old('jumlah_hal') }}">
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Penerbit</label>
                                                        <input type="text" class="form-control mb-4" id="penerbit" name="penerbit" placeholder="Penerbit"  value="{{ $edit ? $bukuajar->penerbit : old('penerbit') }}">
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>URL</label>
                                                        <input type="text" class="form-control mb-4" id="url" name="url" placeholder="http://"  value="{{ $edit ? $bukuajar->url : old('url') }}">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>

            <div class="account-settings-footer">
                <div class="as-footer-container">
                    <button id="multiple-reset" class="btn btn-warning">Batal</button>
                    <button id="multiple-messages" class="btn btn-primary">Save Changes</button>
                </div>
            </div>
        </form>
    </div>

@endsection

@section('js')
    <script>
        function checkNidn(id){
            var value = $('#input_'+id).val();

            var request = $.ajax({
                url: "{{ route('get-biodata') }}",
                type: "get",
                dataType: "json",
                data: {nidn:value},
                success: function(result){
                    $('#nama_'+id).val(result['name']);
                    $('#prodi_'+id).val(result['prodi']);
                    $('#'+id).val(result['nidn']);
                }
            })
        }
    </script>
@endsection
