@extends('layouts.admin')

@section('title', 'Profil Saya')
@section('header', 'Profil Saya')

@section('breadcrumb')
<li class="breadcrumb-item active">Profil</li>
@endsection

@section('content')

<div class="row g-4" style="max-width:760px;">

    {{-- Account Info --}}
    <div class="col-12">
        <div class="card border-0 shadow-sm">
            <div class="card-body d-flex align-items-center gap-3 py-3">
                <div class="rounded-circle bg-primary bg-opacity-10 d-flex align-items-center justify-content-center flex-shrink-0"
                     style="width:52px;height:52px;">
                    <i class="bi bi-person-fill text-primary fs-4"></i>
                </div>
                <div>
                    <div class="fw-semibold">{{ $user->name }}</div>
                    <div class="text-muted small">{{ $user->email }}</div>
                    <span class="badge {{ $user->isSuperAdmin() ? 'bg-danger' : 'bg-primary' }} mt-1">
                        {{ $user->isSuperAdmin() ? 'Super Admin' : 'Admin Program' }}
                    </span>
                </div>
            </div>
        </div>
    </div>

    {{-- Update Email --}}
    <div class="col-md-6">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-header bg-white py-3">
                <h6 class="mb-0 fw-semibold">
                    <i class="bi bi-envelope me-2 text-primary"></i>Tukar Alamat Emel
                </h6>
            </div>
            <div class="card-body">

                @if(session('email_success'))
                <div class="alert alert-success small py-2">
                    <i class="bi bi-check-circle me-1"></i>{{ session('email_success') }}
                </div>
                @endif

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

                    <div class="mb-3">
                        <label class="form-label small fw-medium">Kata Laluan Semasa <span class="text-danger">*</span></label>
                        <input type="password" name="current_password" autocomplete="current-password"
                               class="form-control form-control-sm @error('current_password', 'email') is-invalid @enderror"
                               placeholder="••••••••">
                        @error('current_password', 'email')
                        <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>

                    <div class="mb-3">
                        <label class="form-label small fw-medium">Emel Baru <span class="text-danger">*</span></label>
                        <input type="email" name="email" autocomplete="email"
                               class="form-control form-control-sm @error('email', 'email') is-invalid @enderror"
                               value="{{ old('email', $user->email) }}"
                               placeholder="emel@contoh.com">
                        @error('email', 'email')
                        <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>

                    <button type="submit" class="btn btn-primary btn-sm w-100">
                        <i class="bi bi-check-lg me-1"></i> Kemaskini Emel
                    </button>
                </form>
            </div>
        </div>
    </div>

    {{-- Update Password --}}
    <div class="col-md-6">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-header bg-white py-3">
                <h6 class="mb-0 fw-semibold">
                    <i class="bi bi-key me-2 text-primary"></i>Tukar Kata Laluan
                </h6>
            </div>
            <div class="card-body">

                @if(session('password_success'))
                <div class="alert alert-success small py-2">
                    <i class="bi bi-check-circle me-1"></i>{{ session('password_success') }}
                </div>
                @endif

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

                    <div class="mb-3">
                        <label class="form-label small fw-medium">Kata Laluan Semasa <span class="text-danger">*</span></label>
                        <input type="password" name="current_password" autocomplete="current-password"
                               class="form-control form-control-sm @error('current_password', 'password') is-invalid @enderror"
                               placeholder="••••••••">
                        @error('current_password', 'password')
                        <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>

                    <div class="mb-3">
                        <label class="form-label small fw-medium">Kata Laluan Baru <span class="text-danger">*</span></label>
                        <input type="password" name="password" autocomplete="new-password"
                               class="form-control form-control-sm @error('password', 'password') is-invalid @enderror"
                               placeholder="Min. 8 aksara">
                        @error('password', 'password')
                        <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>

                    <div class="mb-3">
                        <label class="form-label small fw-medium">Sahkan Kata Laluan Baru <span class="text-danger">*</span></label>
                        <input type="password" name="password_confirmation" autocomplete="new-password"
                               class="form-control form-control-sm"
                               placeholder="••••••••">
                    </div>

                    <button type="submit" class="btn btn-primary btn-sm w-100">
                        <i class="bi bi-check-lg me-1"></i> Tukar Kata Laluan
                    </button>
                </form>
            </div>
        </div>
    </div>

</div>

@endsection
