@extends('layouts.app')
@section('title', 'Profil Anda')
@section('content')
    <div class="row d-flex align-items-strech">
        <div class="col-lg-6 mx-auto">
            <div class="card">
                <div class="card-header">
                    <h3>Data Diri</h3>
                </div>
                <div class="card-body border-top">
                    <form method="post" action="{{ route('profile.index') }}">
                        @csrf
                        <div class="mb-3">
                            <label for="nik" class="form-label">NIK</label>
                            <input type="text" class="form-control" id="nik" name="nik"
                                placeholder="Contoh: Ardito Pratama" value="{{ isset($profile->nik) ? $profile->nik : '' }}"
                                required>
                            <div id="nik" class="form-text">Silahkan masukkan NIK dengan 16 angka unik.</div>
                            <!-- error message-->
                            @error('nik')
                                <div class="invalid-feedback">
                                    {{ $message }}
                                </div>
                            @enderror
                        </div>
                        <div class="mb-3">
                            <label for="name" class="form-label">Nama</label>
                            <input type="text" class="form-control" id="name" name="name"
                                placeholder="Contoh: Ardito Pratama"
                                value="{{ isset($profile->name) ? $profile->name : '' }}" required>
                            <div id="emailHelp" class="form-text">Silahkan masukkan nama lengkap anda.</div>
                            <!-- error message-->
                            @error('name')
                                <div class="invalid-feedback">
                                    {{ $message }}
                                </div>
                            @enderror
                        </div>
                        <div class="mb-3">
                            <label for="email" class="form-label">Email</label>
                            <input type="email" class="form-control" id="email"
                                value="{{ isset($profile->email) ? $profile->email : '' }}" disabled>
                        </div>

                        <div class="mb-3">
                            <label for="gender" class="form-label">Jenis Kelamin</label>
                            <select class="form-select @error('gender') is-invalid @enderror" id="gender" name="gender"
                                required>
                                <option value="">Pilih Jenis Kelamin</option>
                                <option value="Laki - Laki" {{ $profile->gender == 'Laki - Laki' ? 'selected' : '' }}>Laki -
                                    Laki</option>
                                <option value="Perempuan" {{ $profile->gender == 'Perempuan' ? 'selected' : '' }}>Perempuan
                                </option>
                            </select>
                            <!-- error message -->
                            @error('gender')
                                <div class="invalid-feedback">
                                    {{ $message }}
                                </div>
                            @enderror
                        </div>
                        <div class="mb-3">
                            <label for="place_of_birth" class="form-label">Tempat Lahir</label>
                            <input type="text" class="form-control" id="place_of_birth" name="place_of_birth"
                                value="{{ isset($profile->place_of_birth) ? $profile->place_of_birth : old('place_of_birth') }}"
                                placeholder="Contoh: Jakarta" required>
                            <!-- error message -->
                            @error('place_of_birth')
                                <div class="invalid-feedback">
                                    {{ $message }}
                                </div>
                            @enderror
                        </div>
                        <div class="mb-3">
                            <label for="date_of_birth" class="form-label">Tanggal Lahir</label>
                            <input type="date" class="form-control" id="date_of_birth" name="date_of_birth"
                                value="{{ isset($profile->date_of_birth) ? $profile->date_of_birth : old('date_of_birth') }}"
                                required>
                            <!-- error message -->
                            @error('date_of_birth')
                                <div class="invalid-feedback">
                                    {{ $message }}
                                </div>
                            @enderror
                        </div>
                        <div class="mb-3">
                            <label for="oldPassword" class="form-label">Password Lama</label>
                            <input type="oldPassword"
                                class="form-control @if ($errors->first('msg')) is-invalid @endif  @error('oldPassword') is-invalid @enderror"
                                id="oldPassword" name="oldPassword">
                            <!-- error message -->
                            @error('oldPassword')
                                <div class="invalid-feedback">
                                    {{ $message }}
                                </div>
                            @enderror
                            @if ($errors->first('msg'))
                                <div class="invalid-feedback">
                                    {{ $errors->first('msg') }}
                                </div>
                            @endif
                        </div>
                        <div class="mb-3">
                            <label for="newPassword" class="form-label">Password Baru</label>
                            <input type="newPassword" class="form-control @error('newPassword') is-invalid @enderror"
                                id="newPassword" name="newPassword">
                            <!-- error message -->
                            @error('newPassword')
                                <div class="invalid-feedback">
                                    {{ $message }}
                                </div>
                            @enderror
                        </div>
                        <button type="submit" class="btn btn-primary">Simpan</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

@stop
@push('scripts')
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    @if (Session::has('profile-message'))
        <script>
            Swal.fire({
                text: "{{ Session::get('profile-message')['msg'] }}",
                icon: "{{ Session::get('profile-message')['type'] }}",
                timer: 2500
            });
        </script>
    @endif
@endpush
