@extends('layouts.master')

@section('title')
    Dashboard
@endsection

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

@section('contents')
@php
 $menu = 'dashboard';
@endphp
    <div class="account-settings-container layout-top-spacing">
        <form action="{{ $edit ? route('kekayaanintelek.update', ['kekayaanintelek' => encrypt($data->id)]) : route('kekayaanintelek.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 ? $data->nidn : '' }}" placeholder="NIDN" aria-label="nidn">
                                                    <input type="text" class="form-control" name="nidn" value="{{ $edit ? $data->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 for="inputEmail4">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 for="inputPassword4">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="contact" class="section contact">
                                <div class="info">
                                    <h5 class="">Data Hak Kekayaan Intelektual</h5>
                                    <div class="row">
                                        <div class="col-md-11 mx-auto">
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <div class="form-group @if ($errors->has('judul_hki')) has-error @endif">
                                                        <label>Judul HKI</label>
                                                        <textarea class="form-control" id="judulhki" name="judul_hki" placeholder="Judul" rows="3" required>{!! $edit ? $data->judul_hki : old('judul_hki') !!}</textarea>
                                                        @if($errors->has('judul_hki'))
                                                            <label id="login-error" class="text-danger" for="login">{{ $errors->first('judul_hki') }}</label>
                                                        @endif
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group @if ($errors->has('jenis')) has-error @endif">
                                                        <label>Jenis</label>
                                                        <select name="jenis" class="form-control" id="jenis" required>
                                                            <option {{ $edit ? ($data->jenis == 'Paten' ? 'selected' : '') : (old('jenis') ? (old('jenis') == 'Paten' ? 'selected' :'') : '') }}>Paten</option>
                                                            <option {{ $edit ? ($data->jenis == 'Paten Sederhana' ? 'selected' : '') : (old('jenis') ? (old('jenis') == 'Paten Sederhana' ? 'selected' :'') : '') }}>Paten Sederhana</option>
                                                            <option {{ $edit ? ($data->jenis == 'Hak Cipta' ? 'selected' : '') : (old('jenis') ? (old('jenis') == 'Hak Cipta' ? 'selected' :'') : '') }}>Hak Cipta</option>
                                                            <option {{ $edit ? ($data->jenis == 'Desain Produksi Industri' ? 'selected' : '') : (old('jenis') ? (old('jenis') == 'Desain Produksi Industri' ? 'selected' :'') : '') }}>Desain Produksi Industri</option>
                                                            <option {{ $edit ? ($data->jenis == 'Perlindungan Varietas Tanaman' ? 'selected' : '') : (old('jenis') ? (old('jenis') == 'Perlindungan Varietas Tanaman' ? 'selected' :'') : '') }}>Perlindungan Varietas Tanaman</option>
                                                            <option {{ $edit ? ($data->jenis == 'Desain Tata Letak Sirkuit Terpadu' ? 'selected' : '') : (old('jenis') ? (old('jenis') == 'Desain Tata Letak Sirkuit Terpadu' ? 'selected' :'') : '') }}>Desain Tata Letak Sirkuit Terpadu</option>
                                                        </select>
                                                        @if($errors->has('jenis'))
                                                            <label id="login-error" class="text-danger" for="login">{{ $errors->first('jenis') }}</label>
                                                        @endif
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group  @if ($errors->has('status')) has-error @endif">
                                                        <label>Status</label>
                                                        <select name="status" class="form-control" id="status" required>
                                                            <option {{ $edit ? ($data->status == 'Terdaftar' ? 'selected' : '') : (old('status') ? (old('status') == 'Terdaftar' ? 'selected' :'') : '') }}>Terdaftar</option>
                                                            <option {{ $edit ? ($data->status == 'Granted/Bersertifikat' ? 'selected' : '') : (old('status') ? (old('status') == 'Granted/Bersertifikat' ? 'selected' :'') : '') }}>Granted/Bersertifikat</option>
                                                        </select>
                                                        @if($errors->has('status'))
                                                            <label id="login-error" class="text-danger" for="login">{{ $errors->first('status') }}</label>
                                                        @endif
                                                    </div>
                                                </div>
                                                <div class="col-md-4">
                                                    <div class="form-group @if ($errors->has('nopendaftaran')) has-error @endif">
                                                        <label>No. Pendaftaran</label>
                                                        <input type="text" class="form-control" id="nopendaftaran" value="{{ $edit ? $data->nopendaftaran : old('nopendaftaran') }}" name="nopendaftaran" placeholder="No. Pendaftaran" required>
                                                        @if($errors->has('nopendaftaran'))
                                                            <label id="login-error" class="text-danger" for="login">{{ $errors->first('nopendaftaran') }}</label>
                                                        @endif
                                                    </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 src="{{ url('theme/plugins/apex/apexcharts.min.js') }} "></script>
    <script src="{{ url('theme/assets/js/dashboard/dash_2.js') }} "></script>
    <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
