@extends('layouts.app')
@section('title', 'Edit User - Admin')

@push('styles')
<style>
/* ===== DARK MODE FOR EDIT USER PAGE ===== */

.dark [style*="color:#1A56DB"] {
    color: #60a5fa !important;
}

.dark .page-title {
    color: #f1f5f9 !important;
}

.dark .page-subtitle {
    color: #cbd5e1 !important;
}

.dark .card {
    background: #1e293b !important;
    border-color: #334155 !important;
}

.dark .form-group label.form-label {
    color: #cbd5e1 !important;
}

.dark [style*="color:#94A3B8;font-weight:400"] {
    color: #94a3b8 !important;
}

.dark .form-control {
    background: #334155 !important;
    border-color: #475569 !important;
    color: #f1f5f9 !important;
}

.dark .form-control::placeholder {
    color: #94a3b8 !important;
}

.dark .form-control:focus {
    border-color: #60a5fa !important;
    background: #334155 !important;
    color: #f1f5f9 !important;
}

.dark .form-control.is-invalid {
    border-color: #dc2626 !important;
}

.dark .invalid-feedback {
    color: #fca5a5 !important;
}

.dark .form-hint {
    color: #cbd5e1 !important;
}

.dark .form-control:disabled {
    background: #334155 !important;
    color: #94a3b8 !important;
    border-color: #475569 !important;
}

/* ===== LIGHT MODE FALLBACK ===== */

.light .page-title {
    color: #0f172a !important;
}

.light .page-subtitle {
    color: #64748b !important;
}

.light .card {
    background: #ffffff !important;
}

.light .form-control {
    background: #ffffff !important;
    color: #1e293b !important;
}
</style>
@endpush

@section('content')
<div class="max-w-lg mx-auto">
    <div style="margin-bottom:2rem">
        <a href="{{ route('admin.users.show',$user->id) }}" style="color:#1A56DB;text-decoration:none;font-size:.875rem;display:inline-flex;align-items:center;gap:4px;margin-bottom:.75rem">
            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 18 9 12 15 6"/></svg>
            Kembali ke Detail
        </a>
        <h1 class="page-title">Edit User</h1>
        <p class="page-subtitle">{{ $user->email }}</p>
    </div>
    <div class="card">
        <form action="{{ route('admin.users.update',$user->id) }}" method="POST">
            @csrf @method('PUT')
            <div class="form-group">
                <label class="form-label">Nama Lengkap <span class="required">*</span></label>
                <input type="text" name="name" class="form-control {{ $errors->has('name')?'is-invalid':'' }}" value="{{ old('name',$user->name) }}" required>
                @error('name')<div class="invalid-feedback">{{ $message }}</div>@enderror
            </div>
            <div class="form-group">
                <label class="form-label">Email <span class="required">*</span></label>
                <input type="email" name="email" class="form-control {{ $errors->has('email')?'is-invalid':'' }}" value="{{ old('email',$user->email) }}" required>
                @error('email')<div class="invalid-feedback">{{ $message }}</div>@enderror
            </div>
            <div class="form-group">
                <label class="form-label">Password Baru <span style="color:#94A3B8;font-weight:400">(kosongkan jika tidak diubah)</span></label>
                <input type="password" name="password" class="form-control {{ $errors->has('password')?'is-invalid':'' }}">
                @error('password')<div class="invalid-feedback">{{ $message }}</div>@enderror
            </div>
            <div class="form-group">
                <label class="form-label">Konfirmasi Password Baru</label>
                <input type="password" name="password_confirmation" class="form-control">
            </div>
            <div class="form-group">
                <label class="form-label">Role <span class="required">*</span></label>
                <select name="role" class="form-control" {{ $user->id === Auth::id() ? 'disabled' : '' }}>
                    <option value="user" {{ old('role',$user->role)==='user'?'selected':'' }}>User</option>
                    <option value="admin" {{ old('role',$user->role)==='admin'?'selected':'' }}>Admin</option>
                </select>
                @if($user->id === Auth::id())
                <input type="hidden" name="role" value="{{ $user->role }}">
                <div class="form-hint">Tidak bisa mengubah role akun sendiri</div>
                @endif
            </div>
            <div style="display:flex;gap:.75rem;margin-top:1.5rem">
                <a href="{{ route('admin.users.show',$user->id) }}" class="btn btn-secondary" style="flex:1;justify-content:center">Batal</a>
                <button type="submit" class="btn btn-primary" style="flex:1">Simpan Perubahan</button>
            </div>
        </form>
    </div>
</div>
@endsection