@extends('layout.layout')

@php
    $title = 'Edit Profil';
    $subTitle = 'Profil Pengguna';
@endphp

@section('content')

    <div class="card basic-data-table">
        <div class="card-body">
            <div
                class="d-flex flex-column flex-md-row justify-content-between align-items-start align-items-md-center mb-3 gap-3">
                <div>
                    <h5 class="mb-0">Edit Profil</h5>
                </div>
                <div class="d-flex gap-2">
                    <a href="{{ route('profile.index') }}" class="btn btn-secondary btn-sm d-flex align-items-center gap-2">
                        <iconify-icon icon="iconoir:arrow-left"></iconify-icon>
                        <span>Kembali</span>
                    </a>
                </div>
            </div>

            @if (session('success'))
                <div class="alert alert-success">{{ session('success') }}</div>
            @endif

            @if ($errors->any())
                <div class="alert alert-danger">
                    <ul class="mb-0">
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif

            <form method="POST" action="{{ route('profile.update') }}">
                @csrf
                @method('PUT')

                <div class="row g-3">
                    <div class="col-12 col-md-6">
                        <label class="form-label">Nama Lengkap <span class="text-danger">*</span></label>
                        <input type="text" name="name" class="form-control" required
                            value="{{ old('name', $user->name) }}" placeholder="Masukkan nama lengkap">
                    </div>

                    <div class="col-12 col-md-6">
                        <label class="form-label">Username <span class="text-danger">*</span></label>
                        <input type="text" name="username" class="form-control" required
                            value="{{ old('username', $user->username) }}" placeholder="Masukkan username">
                    </div>

                    <div class="col-12 col-md-6">
                        <label class="form-label">Email</label>
                        <input type="email" class="form-control" value="{{ $user->email }}" readonly>
                        <div class="form-text">
                            <a href="{{ route('profile.change-email') }}" class="text-primary">Klik di sini untuk mengubah
                                email</a>
                        </div>
                    </div>

                    <div class="col-12 col-md-6">
                        <label class="form-label">Password</label>
                        <input type="password" class="form-control" value="••••••••" readonly>
                        <div class="form-text">
                            <a href="{{ route('profile.change-password') }}" class="text-primary">Klik di sini untuk
                                mengubah password</a>
                        </div>
                    </div>
                </div>

                <!-- User Info -->
                <div class="mt-4">
                    <div class="alert alert-light">
                        <h6>Informasi Akun:</h6>
                        <ul class="mb-0">
                            <li>Bergabung: {{ $user->created_at->format('d/m/Y H:i:s') }}</li>
                            <li>Terakhir diperbarui: {{ $user->updated_at->format('d/m/Y H:i:s') }}</li>
                            <li>Role:
                                @if ($user->roles->count() > 0)
                                    @foreach ($user->roles as $role)
                                        <span class="badge bg-primary me-1">{{ $role->name }}</span>
                                    @endforeach
                                @else
                                    <span class="badge bg-secondary">Tidak ada role</span>
                                @endif
                            </li>
                        </ul>
                    </div>
                </div>

                <div class="mt-4 d-flex gap-2">
                    <button class="btn btn-primary d-flex align-items-center gap-2">
                        <iconify-icon icon="material-symbols:save"></iconify-icon>
                        <span>Simpan Perubahan</span>
                    </button>
                    <a href="{{ route('profile.index') }}" class="btn btn-light">Batal</a>
                </div>
            </form>
        </div>
    </div>

@endsection
