@extends('layouts.master')

@section('title')
    Peneliti Asing
@endsection

@section('header')
<div class="page-title">
    <h3>Peneliti Asing</h3>
</div>
@endsection

@section('contents')
@php
 $menu = 'dashboard';
@endphp
    <div class="account-settings-container layout-top-spacing">
        <form id="contact" class="section contact" action="{{ $edit ? route('penelitiasing.update', ['penelitiasing' => encrypt($data->id)]) : route('penelitiasing.store') }}" method="POST">


        <div class="account-content">
            <div class="scrollspy-example" data-spy="scroll" data-target="#account-settings-scroll" data-offset="-100">
                <div class="row">
                    @if ($edit)
                        {{ method_field('PUT') }}
                    @endif
                    <div class="col-xl-12 col-lg-12 col-md-12 layout-spacing">
                            @csrf
                            <div class="info">
                                <h5 class="">Data Peneliti Asing</h5>
                                <div class="row">
                                    <div class="col-md-11 mx-auto">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label>Nama Lengkap & Gelar</label>
                                                    <input type="text" class="form-control mb-4" id="unit_pelaksanaan" placeholder="Nama Lengkap & Gelar" name="nama" value="{{ $edit ? $data->nama : old('nama') }}" required>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label>Jenis Kelamin</label>
                                                    <select class="form-control" id="jenis-kelamin" name="jenis_kelamin" required>
                                                        <option {{ $edit ? ($data->jenis_kelamin == 'Laki-Laki' ? 'selected' : '') : '' }}>Laki-Laki</option>
                                                        <option {{ $edit ? ($data->jenis_kelamin == 'Perempuan' ? 'selected' : '') : '' }}>Perempuan</option>
                                                    </select>
                                                </div>
                                            </div>
                                             <div class="col-md-6">
                                                <div class="form-group">
                                                    <label>Institusi Asal</label>
                                                    <input type="text" class="form-control mb-4" id="unit_pelaksanaan" name="institusi" placeholder="Institusi Asal" value="{{ $edit ? $data->institusi : old('institusi') }}" required>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label>Negara</label>
                                                    <select class="form-control" id="negara" name="negara_id" required>
                                                        <option value="">Pilih Negara</option>
                                                        @foreach ($negara as $item)
                                                            <option value="{{ encrypt($item->id) }}" {{ $edit ? ($data->negara_id == $item->id ? 'selected' : '') : (old('negara_id') ? (decrypt(old('negara_id')) == $item->id ? 'selected' : '') : '') }}>{{ $item->nama }}</option>
                                                        @endforeach
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label>Pendidikan Tertinggi</label>
                                                    <select class="form-control" id="pendidikan" name="pendidikan" required>
                                                        <option {{ $edit ? ($data->pendidikan == 'Master' ? 'selected' : '') : '' }}>Master</option>
                                                        <option {{ $edit ? ($data->pendidikan == 'Doctor' ? 'selected' : '') : '' }}>Doctor</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label>Bidang Kepakaran</label>
                                                    <div class="row">
                                                        <div class="col-md-6">
                                                            <select class="form-control" id="bidang-kepakaran-kategori" onchange="getChildren(this)" data-parent="MsBidangKepakaranKategori" data-target="bidang-kepakaran">
                                                                <option value="">Pilih Kategori</option>
                                                                @foreach ($kategori as $item)
                                                                    <option value="{{ encrypt($item->id) }}">{{ $item->namabidang }}</option>
                                                                @endforeach
                                                            </select>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <select class="form-control" id="bidang-kepakaran" name="bidang_id" required>
                                                                @if ($edit)
                                                                    <option value="{{ encrypt($data->bidang_id) }}">{{ $data->bidang->nama }}</option>
                                                                @endif
                                                            </select>
                                                        </div>
                                                    </div>

                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label>Lama Tinggal</label>
                                                    <input type="text" class="form-control mb-4" id="nomor_kontrak" placeholder="Lama Tinggal" name="lamatinggal" value="{{ $edit ? $data->lamatinggal : old('lamatinggal') }}" required>
                                                </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 src="{{ url('theme/plugins/apex/apexcharts.min.js') }} "></script>
    <script src="{{ url('theme/assets/js/dashboard/dash_2.js') }} "></script>
    <script>
        function getChildren(element){
            var parent = $(element).data('parent');
            var id = $(element).val();
            var target = $("#"+$(element).data('target'));
            var request = $.ajax({
                url: "{{ route('get-children') }}",
                type: "GET",
                dataType: "html",
                data: {parent: parent, id: id},
                success: function(result){
                    target.html(result);
                }
            })
        }
    </script>
@endsection
