@extends('layouts.master')

@section('title')
    Penelitian Sumber Dana Non Kemenristek/BRIN
@endsection

@section('header')
<div class="page-title">
    <h3>Penelitian Sumber Dana Non Kemenristek/BRIN</h3>
</div>
@endsection

@section('contents')
@php
 $menu = 'dashboard';
@endphp
    <div class="account-settings-container layout-top-spacing">
        <form action="{{ $edit ? route('penelitiansumber.update', ['penelitiansumber' => encrypt($data->id)]) : route('penelitiansumber.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="contact" class="section contact">
                            <div class="info">
                                <h5 class="">Data Penelitian Sumber Dana Non Kemenristek/BRIN</h5>
                                <div class="row">
                                    <div class="col-md-11 mx-auto">
                                        <div class="row">
                                            <div class="col-md-12">
                                                <div class="form-group">
                                                        <label>Judul</label>
                                                        <textarea class="form-control" name="judul" id="judul" placeholder="Judul" rows="3">{{ $edit ? $data->judul : old('judul') }}</textarea>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label>Jenis Penelitian</label>
                                                    <select name="jenis" class="form-control" id="kategori">
                                                        @foreach ($jenis as $item)
                                                            <option {{ $edit ? ($data->jenis == $item ? 'selected' : '') : '' }}>{{ $item }}</option>
                                                        @endforeach
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label>Bidang Penelitian</label>
                                                    <div class="row">
                                                        <div class="col-md-6">
                                                            <select class="form-control" id="bidang-kepakaran-kategori" onchange="getChildren(this)" data-parent="MsBidangPenelitianKategori" data-target="bidang-penelitian">
                                                                <option value="">Pilih Kategori</option>
                                                                @foreach ($kategori_bidang as $item)
                                                                    <option value="{{ encrypt($item->id) }}">{{ $item->namabidang }}</option>
                                                                @endforeach
                                                            </select>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <select class="form-control" id="bidang-penelitian" 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 class="form-group">
                                                    <label>Tujuan Sosial Ekonomi</label>
                                                    <div class="row">
                                                        <div class="col-md-6">
                                                            <select class="form-control" id="bidang-kepakaran-kategori" onchange="getChildren(this)" data-parent="MsTujuanSosialKategori" data-target="tujuan-sosial">
                                                                <option value="">Pilih Kategori</option>
                                                                @foreach ($kategori_tujuan as $item)
                                                                    <option value="{{ encrypt($item->id) }}">{{ $item->namatujuan }}</option>
                                                                @endforeach
                                                            </select>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <select class="form-control" id="tujuan-sosial" name="tujuan_id" required>
                                                                @if ($edit)
                                                                    <option value="{{ encrypt($data->tujuan_id) }}">{{ $data->tujuan->nama }}</option>
                                                                @endif
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label>Sumber Dana</label>
                                                    <select name="sumberdana" class="form-control" id="sumber_dana">
                                                        @foreach ($sumber as $key=>$item)
                                                            <option value="{{ $key }}" {{ $edit ? ($data->sumberdana == $key || old('sumberdana') == $key ? 'selected'  : '') : (old('sumberdana') == $key ? 'selected'  : '') }}>{{ $item }}</option>
                                                        @endforeach
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label>Institusi Sumber Dana</label>
                                                    <select name="institusi_id" class="form-control" id="institusi">
                                                        @foreach ($institusi as $item)
                                                            <option value="{{ encrypt($item->id) }}" {{ $edit ? ($data->institusi_id == $item->id ? 'selected' : '') : (old('institusi_id') ? (decrypt(old('institusi_id')) == $item->id ? 'selected' : '') : '') }}>{{ $item->nama }}</option>
                                                        @endforeach
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label>Jumlah Dana</label>
                                                    <input name="jumlah_dana" type="text" class="form-control mb-4" id="jumlah_dana" placeholder="Jumlah Dana" value="{{ $edit ? $data->jumlah_dana : old('jumlah_dana') }}">
                                                </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">Simpan</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
