@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="{{route($route.'.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">Username</label>
                            <div class="col-12 pr-1">
                                <input type="text" value="{{@$item->username ? @$item->username :  old('username')}}" name="username" class="form-control @error('username') is-invalid @enderror" placeholder="Masukan username Sekolah" required>
                                @error('username')
                                <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">Nama</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="emailverify">Email</label>
                            <div class="col-12 pr-1">
                                <input type="email" name="email" value="{{@$item->email ? @$item->email :  old('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" for="fname">Role User</label>
                            <div class="col-12 pr-1">
                                <select name="group" class="form-control @error('group') is-invalid @enderror" required>
                                    <option value="">-Pilih Role User-</option>
                                    @foreach($group as $data_group)
                                    <option {{@$item->ms_group_id == $data_group->MsGroupId ? 'selected' : ''}} value="{{encode_id($data_group->MsGroupId)}}">{{$data_group->name}}</option>
                                    @endforeach
                                </select>
                                @error('group')
                                <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">Wilayah</label>
                            <div class="col-12 pr-1">
                                <select name="ms_kabupaten_id" class="form-control @error('ms_kabupaten_id') is-invalid @enderror">
                                    <option value="">-Pilih Wilayah-</option>
                                    @foreach($kabupaten as $data_kabupaten)
                                        <option {{@$item->ms_kabupaten_id == $data_kabupaten->MsKabupatenId ? 'selected' : ''}} value="{{encode_id($data_kabupaten->MsKabupatenId)}}">{{$data_kabupaten->name}}</option>
                                    @endforeach
                                </select>
                                @error('ms_kabupaten_id')
                                <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">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="{{route($route.'.index')}}" 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