@extends('layouts.admin')
@section('styles')
    <link rel="stylesheet" href="{{ asset('assets/admin/css/vendors/flatpickr/flatpickr.min.css') }}">
    <link rel="stylesheet" href="{{ asset('assets/admin/css/vendors/select2.css') }}">
    <link rel="stylesheet" href="{{ asset('assets/admin/css/weak-password.css') }}">
    <link rEL="stylesheet" href="{{ asset('assets/admin/css/icon-password.css') }}">
    </link>
@endsection
@section('app')
    <div class="container-fluid">
        <div class="edit-profile">
            <div class="row">
                <div class="col-xl-4">
                    <div class="card">
                        <div class="card-body">
                            <form action="{{ route('setting.account.updatePassword', encryptId($profile->id)) }}"
                                method="post">
                                @csrf
                                @method('put')
                                <div class="row mb-2">
                                    <div class="profile-title">
                                        <div class="media profile-media-md">
                                            <img alt="image"
                                                src="{{ optional($profile->attachments()->where('type', 'avatar')->first())->formatted_attachment ? Storage::url('users/' . optional($profile->attachments()->where('type', 'avatar')->first())->formatted_attachment) : '' }}">
                                            <div class="media-body">
                                                <h5 class="mb-1">{{ $profile->biography->full_name ?? '' }}</h5>
                                                <p>{{ $profile->role->name ?? '' }}</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="mb-3">
                                    <label class="form-label" for="current_password">Kata Sandi Saat Ini</label>
                                    <input name="current_password"
                                        class="form-control @error('current_password') is-invalid @enderror" type="password"
                                        id="current_password" placeholder="********">
                                    @error('current_password')
                                        <div class="invalid-feedback">
                                            {{ $message }}
                                        </div>
                                    @enderror
                                </div>
                                <div class="mb-3">
                                    <label class="form-label" for="new_password">Kata Sandi Baru</label>
                                    <div class="password-wrapper">
                                        <input name="new_password"
                                            class="form-control @error('new_password') is-invalid @enderror" type="password"
                                            id="new_password" placeholder="********"
                                            pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}"
                                            title="Harus berisi setidaknya satu angka dan satu huruf besar dan kecil, dan setidaknya 8 karakter atau lebih">
                                    </div>
                                    <div role="alert" id="new_password_message" style="display: none">
                                        <p style="font-weight: bold;" class="mt-3"> Kata Sandi harus
                                            terdiri
                                            dari: </p>
                                        <p id="length" class="invalid"> Minimal <b> 8
                                                karakter
                                            </b> </p>
                                        <p id="letter" class="invalid"> Huruf <b> kecil
                                                (a-z)</b> </p>
                                        <p id="capital" class="invalid"> Huruf <b> KAPITAL
                                                (A-Z)</b></p>
                                        <p id="number" class="invalid"> <b>Angka</b>(0-9)
                                        </p>
                                        <p id="symbol" class="invalid">
                                            <b>Symbol</b>(!$#%@)
                                        </p>
                                    </div>
                                    @error('new_password')
                                        <div class="invalid-feedback">
                                            {{ $message }}
                                        </div>
                                    @enderror
                                </div>
                                <div class="mb-3">
                                    <label class="form-label" for="repeat_new_password">Ulangi Kata Sandi Saat Baru</label>
                                    <div class="password-wrapper">
                                        <input name="repeat_new_password"
                                            class="form-control @error('repeat_new_password') is-invalid @enderror"
                                            type="password" id="repeat_new_password" placeholder="********"
                                            pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}"
                                            title="Harus berisi setidaknya satu angka dan satu huruf besar dan kecil, dan setidaknya 8 karakter atau lebih">
                                    </div>
                                    @error('repeat_new_password')
                                        <div class="invalid-feedback">
                                            {{ $message }}
                                        </div>
                                    @enderror
                                    <div id="feedback" class="mt-2" style="display: none;">
                                        <div id="repeat_password_message"></div>
                                    </div>
                                </div>
                                <div class="mb-3">
                                    <button class="btn btn-primary button-disable" type="submit">Simpan</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="col-xl-8">
                    <form class="card" action="{{ route('setting.account.updateProfile', encryptId($profile->id)) }}"
                        method="post" enctype="multipart/form-data">
                        @csrf
                        @method('put')
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label" for="full_name">Nama Lengkap</label>
                                        <input name="full_name"
                                            class="form-control @error('full_name') is-invalid @enderror" type="text"
                                            placeholder="Masukan Nama Lengkap"
                                            value="{{ old('full_name', $profile->biography->full_name) }}" id="full_name"
                                            @disabled(auth()->user()->role_id !== 1 && auth()->user()->role_id !== 2)>
                                        @error('full_name')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label" for="username">Nama Pengguna</label>
                                        <input name="username"
                                            class="form-control @error('username') is-invalid @enderror" type="text"
                                            placeholder="Masukan Nama Pengguna"
                                            value="{{ old('username', $profile->username) }}" id="username"
                                            @disabled(auth()->user()->role_id !== 1 && auth()->user()->role_id !== 2)>
                                        @error('username')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label" for="email">Email</label>
                                        <input name="email" class="form-control @error('email') is-invalid @enderror"
                                            type="text" placeholder="Masukan Email"
                                            value="{{ old('email', $profile->email) }}" id="email"
                                            @disabled(auth()->user()->role_id !== 1 && auth()->user()->role_id !== 2)>
                                        @error('email')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label" for="contact_number">Kontak
                                            <span class="form-span"><i>(format : 08xxxxxxxx)</i></span>
                                        </label>
                                        <input name="contact_number"
                                            class="form-control @error('contact_number') is-invalid @enderror"
                                            type="text" placeholder="Masukan Kontak"
                                            value="{{ old('contact_number', $profile->biography->contact_number) }}"
                                            id="contact_number" @disabled(auth()->user()->role_id !== 1 && auth()->user()->role_id !== 2)>
                                        @error('contact_number')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label" for="pob">Tempat Lahir</label>
                                        <input name="pob" class="form-control @error('pob') is-invalid @enderror"
                                            type="text" placeholder="Masukan Tempat Lahir"
                                            value="{{ old('pob', $profile->biography->pob) }}" id="pob"
                                            @disabled(auth()->user()->role_id !== 1 && auth()->user()->role_id !== 2)>
                                        @error('pob')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label" for="dob">Tanggal Lahir</label>
                                        <div class="input-group flatpicker-calender">
                                            <input name="dob"
                                                class="form-control @error('dob') is-invalid @enderror human-friendly"
                                                type="date" placeholder="Masukan Tanggal Lahir"
                                                value="{{ old('dob', $profile->biography->dob) }}" id="dob"
                                                @disabled(auth()->user()->role_id !== 1 && auth()->user()->role_id !== 2)>
                                        </div>
                                        @error('dob')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label" for="entry_date">Tanggal Bekerja</label>
                                        <input name="entry_date"
                                            class="form-control @error('entry_date') is-invalid @enderror" type="text"
                                            placeholder="Masukan Tanggal Bekerja"
                                            value="{{ old('entry_date', formatDateIndo($profile->entry_date)) }}"
                                            id="entry_date" disabled>
                                        @error('entry_date')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label" for="base_salary">Gaji Pokok</label>
                                        <input name="base_salary"
                                            class="form-control @error('base_salary') is-invalid @enderror"
                                            type="text" placeholder="Masukan Gaji Pokok"
                                            value="{{ old('base_salary', formatToRupiah($profile->base_salary)) }}"
                                            id="base_salary" disabled>
                                        @error('base_salary')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label" for="sop">SOP</label>
                                        <textarea name="sop" class="form-control @error('sop') is-invalid @enderror" id="sop" rows="3"
                                            placeholder="Masukan SOP" disabled>{{ old('sop', $profile->sop) }}</textarea>
                                        @error('sop')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label" for="address">Alamat</label>
                                        <textarea name="address" class="form-control @error('address') is-invalid @enderror" id="address" rows="3"
                                            placeholder="Masukan Alamat" @disabled(auth()->user()->role_id !== 1 && auth()->user()->role_id !== 2)>{{ old('address', $profile->biography->address) }}</textarea>
                                        @error('address')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label" for="avatar">Avatar
                                            <span class="form-span"><i>(.jpeg,.png,.jpg,.gif,.svg)</i></span>
                                        </label>
                                        <input name="avatar" class="form-control @error('avatar') is-invalid @enderror"
                                            id="avatar" type="file" value="{{ old('avatar') }}"
                                            accept="image/jpeg,image/png,image/jpg,image/gif,image/svg"
                                            @disabled(auth()->user()->role_id !== 1 && auth()->user()->role_id !== 2)>
                                        @error('avatar')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label" for="gender">Jenis Kelamin
                                        </label>
                                        <select name="gender"
                                            class="form-control @error('gender') is-invalid @enderror select2"
                                            id="gender" @disabled(auth()->user()->role_id !== 1 && auth()->user()->role_id !== 2)>
                                            <option value=""></option>
                                            <option value="1" @selected($profile->biography->gender == '1')>Laki-laki</option>
                                            <option value="2" @selected($profile->biography->gender == '2')>Perempuan</option>
                                        </select>
                                        @error('gender')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-12">
                                    <div class="mb-3">
                                        <label class="form-label" for="role">Role</label>
                                        <input name="role" class="form-control @error('role') is-invalid @enderror"
                                            type="text" placeholder="Masukan Role"
                                            value="{{ old('role', $profile->role->name) }}" id="role" disabled>
                                        @error('role')
                                            <div class="invalid-feedback">
                                                {{ $message }}
                                            </div>
                                        @enderror
                                    </div>
                                </div>
                                @if (auth()->user()->role_id === 1 || auth()->user()->role_id === 2)
                                    <div class="col-md-12">
                                        <button class="btn btn-primary button-disable" type="submit">Simpan</button>
                                    </div>
                                @endif
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('beforeScripts')
    <script src="{{ asset('assets/admin/js/flat-pickr/flatpickr.js?ver=1.0.0') }}"></script>
    <script src="{{ asset('assets/admin/js/flat-pickr/custom-flatpickr.js?ver=1.0.0') }}"></script>
@endsection
@section('afterScripts')
    <script src="{{ asset('assets/js/forms/button-disable.js?ver=1.0.0') }}"></script>
    <script src="{{ asset('assets/admin/js/select2/select2.js') }}"></script>
    <script src="{{ asset('assets/admin/js/select2/select2-config.js?ver=1.0.0') }}"></script>
    <script src="{{ asset('assets/js/forms/weak-password.js?ver=1.0.0') }}"></script>
    <script src="{{ asset('assets/js/forms/toggle-password-icon.js?ver=1.0.0') }}"></script>
@endsection
