@extends('layouts.master')
@section('breadcrumbs')
<ol class="breadcrumb page-breadcrumb">
    @foreach($breadcrumbs as $dataBread)
    <li class="breadcrumb-item {{@$dataBread['active'] == true ? 'active' : ''}}">
        @if(@$dataBread['url'])
        <a href="{{@$dataBread['url']}}">{{$dataBread['name']}}</a>
        @else
        {{$dataBread['name']}}
        @endif
    </li>
    @endforeach
</ol>
@endsection
@section('content')
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                <i class="fal fa-align-justify"></i> {{$title}}
            </div>
            <form action="{{url('profile-store')}}" method="POST" class="">
            {{csrf_field()}}
            <div class="card-body">
                <div class="row">
                    <div class="col-md-12">
                        <input type="hidden" name="secure_id" value="{{@$keyId}}">
                    </div>

                    <div class="col-12 mb-3">
                        <div class="form-group">
                            <label class="col-xl-12 form-label" for="fname">NPSN</label>
                            <div class="col-12 pr-1">
                                <input maxlength="8" type="text" disabled value="{{@$item->username ? @$item->username :  old('npsn')}}" name="npsn" class="form-control @error('npsn') is-invalid @enderror numberInput" placeholder="Masukan NPSN Sekolah" required>
                                @error('npsn')
                                <span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
                                @enderror
                                <small class="text-primary"><i>Pastikan NPSN Telah Sesuai</i></small>
                            </div>
                        </div>
                    </div>
                    <div class="col-12 mb-3">
                        <div class="form-group">
                            <label class="col-xl-12 form-label" for="fname">Nama Sekolah</label>
                            <div class="col-12 pr-1">
                                <input type="text" value="{{@$item->name ? @$item->name :  old('name')}}" name="name"  class="form-control @error('name') is-invalid @enderror" placeholder="Masukan Nama Sekolah" required>
                                @error('name')
                                <span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
                                @enderror
                            </div>
                        </div>
                    </div>
                    <div class="col-12 mb-3">
                        <div class="form-group">
                            <label class="col-xl-12 form-label" for="fname">Tingkat Sekolah</label>
                            <div class="col-12 pr-1">
                                <select name="tingkat_sekolah" class="form-control @error('tingkat_sekolah') is-invalid @enderror">
                                    <option value="" data-select2-id="3">-Pilih Tingkat Sekolah-</option>
                                    <option {{@$item->profile->ms_tingkat_sekolah_id == 1 ? 'selected' : ''}} value="1" data-select2-id="11">SD</option>
                                    <option {{@$item->profile->ms_tingkat_sekolah_id == 2 ? 'selected' : ''}} value="2" data-select2-id="12">SMP</option>
                                    <option {{@$item->profile->ms_tingkat_sekolah_id == 3 ? 'selected' : ''}} value="3" data-select2-id="13">SMA</option>
                                    <option {{@$item->profile->ms_tingkat_sekolah_id == 4 ? 'selected' : ''}} value="4" data-select2-id="14">SMK</option>
                                    <option {{@$item->profile->ms_tingkat_sekolah_id == 5 ? 'selected' : ''}} value="5" data-select2-id="15">MI</option>
                                    <option {{@$item->profile->ms_tingkat_sekolah_id == 6 ? 'selected' : ''}} value="6" data-select2-id="16">MTs</option>
                                    <option {{@$item->profile->ms_tingkat_sekolah_id == 7 ? 'selected' : ''}} value="7" data-select2-id="17">MA</option>
                                    <option {{@$item->profile->ms_tingkat_sekolah_id == 8 ? 'selected' : ''}} value="8" data-select2-id="18">SD LB</option>
                                    <option {{@$item->profile->ms_tingkat_sekolah_id == 9 ? 'selected' : ''}} value="9" data-select2-id="19">SMP LB</option>
                                    <option {{@$item->profile->ms_tingkat_sekolah_id == 10 ? 'selected' : ''}} value="10" data-select2-id="20">SMA LM</option>
                                    <option {{@$item->profile->ms_tingkat_sekolah_id == 11 ? 'selected' : ''}} value="11" data-select2-id="21">SLB Khusus</option>
                                </select>
                                @error('tingkat_sekolah')
                                <span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
                                @enderror
                            </div>
                        </div>
                    </div>
                    <div class="col-12 mb-3">
                        <div class="form-group">
                            <label class="col-xl-12 form-label" for="fname">Status Sekolah</label>
                            <div class="col-12 pr-1">
                                <select name="status_sekolah" class="form-control @error('status_sekolah') is-invalid @enderror" required>
                                    <option value="" data-select2-id="3">-Pilih Status Sekolah-</option>
                                    <option {{@$item->profile->status_sekolah == 'Negeri' ? 'selected' : ''}} value="Negeri">Negeri</option>
                                    <option {{@$item->profile->status_sekolah == 'Swasta' ? 'selected' : ''}} value="Swasta">Swasta</option>
                                </select>
                                @error('status_sekolah')
                                <span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
                                @enderror
                            </div>
                        </div>
                    </div>
                    <div class="col-12 mb-3">
                        <div class="form-group">
                            <label class="col-xl-12 form-label" for="emailverify">Alamat Sekolah</label>
                            <div class="col-12 pr-1">
                                <input type="text" value="{{@$item->profile->alamat_sekolah ? @$item->profile->alamat_sekolah :  old('alamat_sekolah')}}" name="alamat_sekolah" class="form-control @error('alamat_sekolah') is-invalid @enderror" placeholder="Masukan Alamat Sekolah, Nama Jalan / Dusun / RT-RW" required>
                                @error('alamat_sekolah')
                                    <span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
                                @enderror
                            </div>
                        </div>
                    </div>
                    <div class="col-12 mb-3">
                        <div class="form-group">
                            <label class="col-xl-12 form-label" for="emailverify">Kontak Person</label>
                            <div class="col-12 pr-1">
                                <input type="text" value="{{@$item->profile->kontak_person ? @$item->profile->kontak_person :  old('kontak_person')}}" name="kontak_person" class="form-control @error('kontak_person') is-invalid @enderror" placeholder="Masukan Kontak Person" required>
                                @error('kontak_person')
                                    <span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
                                @enderror
                            </div>
                        </div>
                    </div>
                    <div class="col-12 mb-3">
                        <div class="form-group">
                            <label class="col-xl-12 form-label" for="emailverify">Telp/WA</label>
                            <div class="col-12 pr-1">
                                <input type="text" value="{{@$item->profile->telp ? @$item->profile->telp :  old('telp')}}" name="telp" class="form-control @error('telp') is-invalid @enderror numberInput" maxlength="16" placeholder="Masukan Telp/WA" required>
                                @error('telp')
                                    <span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
                                @enderror
                            </div>
                        </div>
                    </div>
                    <div class="col-12 mb-3">
                        <div class="form-group">
                            <label class="col-xl-12 form-label" for="emailverify">Latitude</label>
                            <div class="col-12 pr-1">
                                <input type="text" value="{{@$item->profile->lat ? @$item->profile->lat :  old('lat')}}" name="lat" class="form-control @error('lat') is-invalid @enderror" placeholder="Masukan Latitude">
                                @error('lat')
                                    <span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
                                @enderror
                            </div>
                        </div>
                    </div>
                    <div class="col-12 mb-3">
                        <div class="form-group">
                            <label class="col-xl-12 form-label" for="emailverify">Longitude</label>
                            <div class="col-12 pr-1">
                                <input type="text" value="{{@$item->profile->long ? @$item->profile->long :  old('long')}}" name="long" class="form-control @error('long') is-invalid @enderror" placeholder="Masukan longitude">
                                @error('long')
                                    <span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
                                @enderror
                            </div>
                        </div>
                    </div>
                    <div class="col-12 mb-3">
                        <div class="form-group">
                            <label class="col-xl-12 form-label" for="emailverify">Email</label>
                            <div class="col-12 pr-1">
                                <input type="email" name="email" disabled value="{{@$item->email}}" id="emailverify" class="form-control @error('email') is-invalid @enderror" placeholder="Masukan Email Aktif" required>
                                @error('email')
                                    <span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
                                @enderror
                                <small class="text-primary">* Pastikan email benar dan aktif, akses aplikasi akan dikirim ke email yang didaftarkan.</small>
                            </div>
                        </div>
                    </div>
                    <div class="col-12 mb-3">
                        <div class="form-group">
                            <label class="col-xl-12 form-label">Password Baru</label>
                            <div class="col-12 pr-1">
                                <div class="input-group">
                                    <input type="password" id="password" autocomplete="new-password" name="password" class="form-control @error('password') is-invalid @enderror" placeholder="Masukan Password Minimm 8 characters">
                                    <div class="input-group-append">
                                        <button class="btn btn-default waves-effect waves-themed" type="button" id="togglePassword"><i class="fal fa-eye"></i></button>
                                    </div>
                                </div>
                                @error('password')
                                    <span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
                                @enderror
                                <div class="help-block">
                                Kata Sandi harus mengandung Minimal 8 karakter, maksimal 15 karakter, <br>setidaknya 1 huruf kecil dan huruf besar, angka dan simbol
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card-footer">
                <div class="row">
                    <div class="col-md-12 text-right">
                        <a href="{{url('dashboard')}}" class="btn btn-danger"><i class="fal fa-times"></i> Batal</a>
                        <button type="submit" class="btn btn-success"><i class="fal fa-save"></i> Simpan</button>
                    </div>
                </div>
            </div>
            </form>
        </div>
    </div>
</div>
@endsection
@section('page-js')
	<script type="text/javascript">
     $(document).ready(function() {
            $('.numberInput').on('input', function() {
                this.value = this.value.replace(/[^0-9]/g, ''); // Hanya angka 0-9
            });
            $('#togglePassword').on('click', function() {
                let passwordField = $('#password');
                let icon = $(this).find('i');

                // Cek apakah input saat ini bertipe password
                if (passwordField.attr('type') === 'password') {
                    passwordField.attr('type', 'text'); // Ubah ke teks
                    icon.removeClass('fa-eye').addClass('fa-eye-slash'); // Ganti ikon
                } else {
                    passwordField.attr('type', 'password'); // Ubah ke password
                    icon.removeClass('fa-eye-slash').addClass('fa-eye'); // Kembalikan ikon
                }
            });
        });   
    </script>
@endsection