@extends('student.layouts.app')
@section('title', 'Profil | Career Development and Consultation (CDC)')
@section('header')
    <div class="py-5 toolbar py-lg-5" id="kt_toolbar">
        <div id="kt_toolbar_container" class="flex-wrap container-xxl d-flex flex-stack">
            <div class="page-title d-flex flex-column me-3">
                <h1 class="my-1 d-flex text-dark fw-bolder fs-3">Profil</h1>
                <ul class="my-1 text-gray-600 breadcrumb breadcrumb-dot fw-bold fs-7">
                    <li class="text-gray-600 breadcrumb-item">
                        <a href="{{ route('student.dashboard') }}" class="text-gray-600 text-hover-primary">Dashboard</a>
                    </li>
                    <li class="text-gray-600 breadcrumb-item">Informasi Akun</li>
                    <li class="text-gray-600 breadcrumb-item">Perbarui Profil</li>
                </ul>
            </div>
        </div>
    </div>
@endsection
@section('content')
    <div class="mb-5 card mb-xl-10">
        <div class="border-0 card-header">
            <div class="m-0 card-title">
                <h3 class="m-0 fw-bolder">Informasi Akun</h3>
            </div>
        </div>
        <div>
            <form action="{{ route('student.profile.setting.update') }}" method="POST" class="form"
                enctype="multipart/form-data" autocomplete="off">
                @csrf
                @method('patch')
                <div class="card-body border-top p-9">
                    @once
                        @if (session()->has('success'))
                            <div class="p-6 mb-12 border border-dashed rounded notice d-flex bg-light-success border-success">
                                <span class="svg-icon svg-icon-2tx svg-icon-success me-4">
                                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
                                        fill="none">
                                        <rect opacity="0.3" x="2" y="2" width="20" height="20" rx="10"
                                            fill="black" />
                                        <rect x="11" y="14" width="7" height="2" rx="1"
                                            transform="rotate(-90 11 14)" fill="black" />
                                        <rect x="11" y="17" width="2" height="2" rx="1"
                                            transform="rotate(-90 11 17)" fill="black" />
                                    </svg>
                                </span>
                                <div class="d-flex flex-stack flex-grow-1">
                                    <div class="fw-bold">
                                        <div class="text-gray-700 fs-6">{{ session()->get('success') }}</div>
                                    </div>
                                </div>
                            </div>
                        @endif
                    @endonce
                    <div class="mb-6 row">
                        <label class="col-lg-4 col-form-label fw-bold fs-6">Foto Profil</label>
                        <div class="col-lg-8">
                            <div class="image-input image-input-outline" data-kt-image-input="true"
                                style="background-image: url({{ asset('assets/employee/media/avatars/blank.png') }})">
                                <div class="image-input-wrapper w-125px h-125px"
                                    style="background-image: url({{ asset($user->picture ?: 'assets/employee/media/avatars/blank.png') }})">
                                </div>
                                <label class="shadow btn btn-icon btn-circle btn-active-color-primary w-25px h-25px bg-body"
                                    data-kt-image-input-action="change" data-bs-toggle="tooltip" title="Ubah foto">
                                    <i class="bi bi-pencil-fill fs-7"></i>
                                    <input type="file" name="picture" accept=".png, .jpg, .jpeg" />
                                    <input type="hidden" name="avatar_remove" />
                                </label>
                                <span class="shadow btn btn-icon btn-circle btn-active-color-primary w-25px h-25px bg-body"
                                    data-kt-image-input-action="cancel" data-bs-toggle="tooltip" title="Batal">
                                    <i class="bi bi-x fs-2"></i>
                                </span>
                            </div>
                            <div class="form-text">Format foto: png, jpg, jpeg dan tidak lebih dari 1 MB.</div>
                            @error('picture')
                                <div class="fv-plugins-message-container invalid-feedback">
                                    <span>{{ $message }}</span>
                                </div>
                            @enderror
                        </div>
                    </div>
                    <div class="mb-6 row">
                        <label class="col-lg-4 col-form-label required fw-bold fs-6">Nama</label>
                        <div class="col-lg-8 fv-row">
                            <input type="text" name="name" class="form-control form-control-lg form-control-solid"
                                placeholder="Nama" value="{{ old('name', $user->name) }}" />
                            @error('name')
                                <div class="fv-plugins-message-container invalid-feedback">
                                    <span>{{ $message }}</span>
                                </div>
                            @enderror
                        </div>
                    </div>
                    @if ($user->role === 'student')
                        <div class="mb-6 row">
                            <label class="col-lg-4 col-form-labe required fw-bold fs-6">NIM</label>
                            <div class="col-lg-8 fv-row">
                                <input type="text" name="nim" class="form-control form-control-lg form-control-solid"
                                    placeholder="Nomor Induk Mahasiswa" value="{{ old('nim', $user->student->nim) }}" />
                                @error('nim')
                                    <div class="fv-plugins-message-container invalid-feedback">
                                        <span>{{ $message }}</span>
                                    </div>
                                @enderror
                            </div>
                        </div>
                        <div class="mb-6 row">
                            <label class="col-lg-4 col-form-label required fw-bold fs-6">Jurusan</label>
                            <div class="col-lg-8 fv-row">
                                <select name="department_id" data-control="select2" data-placeholder="Teknologi Informasi"
                                    class="form-select form-select-solid form-select-lg">
                                    <option value=""></option>
                                    @foreach ($departments as $department)
                                        <option value="{{ $department->id }}"
                                            {{ old('department_id', $user->student->department_id) == $department->id ? 'selected' : '' }}>
                                            {{ $department->department_name }}
                                        </option>
                                    @endforeach
                                </select>
                                @error('department_id')
                                    <div class="fv-plugins-message-container invalid-feedback">
                                        <span>{{ $message }}</span>
                                    </div>
                                @enderror
                            </div>
                        </div>
                        <div class="mb-6 row">
                            <label class="col-lg-4 col-form-label required fw-bold fs-6">Program Studi</label>
                            <div class="col-lg-8 fv-row">
                                <input type="text" name="faculty"
                                    class="form-control form-control-lg form-control-solid"
                                    placeholder="Teknik Informatika"
                                    value="{{ ucfirst(old('faculty', $user->student->faculty)) }}" />
                                @error('faculty')
                                    <div class="fv-plugins-message-container invalid-feedback">
                                        <span>{{ $message }}</span>
                                    </div>
                                @enderror
                            </div>
                        </div>
                    @endif
                    <div class="mb-6 row">
                        <label class="col-lg-4 col-form-label fw-bold fs-6">Jenis Kelamin</label>
                        <div class="col-lg-8 fv-row">
                            <select name="gender" data-control="select2"
                                data-placeholder="Silahkan pilih jenis kelamin anda"
                                class="form-select form-select-solid form-select-lg">
                                <option value=""></option>
                                <option value="Laki-Laki"
                                    {{ old('gender', $user->gender) == 'Laki-Laki' ? 'selected' : '' }}>
                                    Laki-Laki
                                </option>
                                <option value="Perempuan"
                                    {{ old('gender', $user->gender) == 'Perempuan' ? 'selected' : '' }}>
                                    Perempuan
                                </option>
                            </select>
                            @error('gender')
                                <div class="fv-plugins-message-container invalid-feedback">
                                    <span>{{ $message }}</span>
                                </div>
                            @enderror
                        </div>
                    </div>
                    <div class="mb-6 row">
                        <label class="col-lg-4 col-form-label fw-bold fs-6">Tanggal Lahir</label>
                        <div class="col-lg-8 fv-row">
                            <input type="date" name="birth_date"
                                class="form-control form-control-lg form-control-solid" placeholder="1999-01-01"
                                id="kt_datepicker_1" value="{{ old('birth_date', $user->birth_date) }}" />
                            @error('birth_date')
                                <div class="fv-plugins-message-container invalid-feedback">
                                    <span>{{ $message }}</span>
                                </div>
                            @enderror
                        </div>
                    </div>
                    <div class="mb-6 row">
                        <label class="col-lg-4 col-form-label fw-bold fs-6">
                            <span>Telepon</span>
                            <i class="fas fa-exclamation-circle ms-1 fs-7" data-bs-toggle="tooltip"
                                title="Nomor telepon aktif"></i>
                        </label>
                        <div class="col-lg-8 fv-row">
                            <input type="tel" name="phone" class="form-control form-control-lg form-control-solid"
                                placeholder="08xxx" value="{{ old('phone', $user->phone) }}" />
                            @error('phone')
                                <div class="fv-plugins-message-container invalid-feedback">
                                    <span>{{ $message }}</span>
                                </div>
                            @enderror
                        </div>
                    </div>
                    <div class="mb-6 row">
                        <label class="col-lg-4 col-form-label fw-bold fs-6">Alamat</label>
                        <div class="col-lg-8 fv-row">
                            <textarea name="address" rows="4" cols="50" class="form-control form-control-lg form-control-solid">{{ old('address', $user->address) }}
                            </textarea>
                            @error('address')
                                <div class="fv-plugins-message-container invalid-feedback">
                                    <span>{{ $message }}</span>
                                </div>
                            @enderror
                        </div>
                    </div>
                </div>

                <div class="py-6 card-footer d-flex justify-content-end px-9">
                    <a href="{{ route('student.profile') }}"
                        class="btn btn-light btn-active-light-primary me-2">Kembali</a>
                    <button type="submit" class="btn btn-primary">Simpan Perubahan</button>
                </div>
            </form>
        </div>
    </div>
@endsection
@push('scripts')
    <script>
        $("#kt_datepicker_1").flatpickr();
    </script>
@endpush
