<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Edit User') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6">
                    <div class="flex items-center justify-between mb-6">
                        <h1 class="text-2xl font-bold text-gray-800">Edit Data: {{ $user->name }}</h1>
                        <a href="{{ route('users.index') }}" class="btn-secondary flex items-center">
                            <i class="fas fa-arrow-left mr-2"></i>
                            Kembali
                        </a>
                    </div>

                    <form action="{{ route('users.update', $user) }}" method="POST">
                        @csrf
                        @method('PUT')
                        
                        <div class="space-y-6">
                            <div>
                                <label for="name" class="block text-sm font-medium text-gray-700 mb-2">Nama Lengkap</label>
                                <input type="text" name="name" id="name" value="{{ old('name', $user->name) }}" 
                                       class="w-full border-gray-300 focus:border-primary focus:ring-primary rounded-lg shadow-sm @error('name') border-red-500 @enderror" 
                                       placeholder="Masukkan nama lengkap" required>
                                @error('name')
                                    <p class="text-red-500 text-sm mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <div>
                                <label for="username" class="block text-sm font-medium text-gray-700 mb-2">Username</label>
                                <input type="text" name="username" id="username" value="{{ old('username', $user->username) }}" 
                                       class="w-full border-gray-300 focus:border-primary focus:ring-primary rounded-lg shadow-sm @error('username') border-red-500 @enderror" 
                                       placeholder="Masukkan username" required>
                                @error('username')
                                    <p class="text-red-500 text-sm mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <div>
                                <label for="password" class="block text-sm font-medium text-gray-700 mb-2">Password Baru (Opsional)</label>
                                <input type="password" name="password" id="password" 
                                       class="w-full border-gray-300 focus:border-primary focus:ring-primary rounded-lg shadow-sm @error('password') border-red-500 @enderror" 
                                       placeholder="Kosongkan jika tidak ingin mengubah password">
                                <p class="text-sm text-gray-500 mt-1">Kosongkan field ini jika tidak ingin mengubah password.</p>
                                @error('password')
                                    <p class="text-red-500 text-sm mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <div>
                                <label for="role" class="block text-sm font-medium text-gray-700 mb-2">Role</label>
                                <select name="role" id="role" class="w-full border-gray-300 focus:border-primary focus:ring-primary rounded-lg shadow-sm @error('role') border-red-500 @enderror" required>
                                    <option value="">Pilih role</option>
                                    <option value="admin" {{ old('role', $user->role) == 'admin' ? 'selected' : '' }}>Admin</option>
                                    <option value="guru" {{ old('role', $user->role) == 'guru' ? 'selected' : '' }}>Guru</option>
                                    <option value="santri" {{ old('role', $user->role) == 'santri' ? 'selected' : '' }}>Santri</option>
                                </select>
                                @error('role')
                                    <p class="text-red-500 text-sm mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <div class="flex justify-end space-x-3 pt-4">
                                <a href="{{ route('users.index') }}" class="btn-secondary">Batal</a>
                                <button type="submit" class="btn-primary flex items-center">
                                    <i class="fas fa-save mr-2"></i>
                                    Update
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</x-app-layout> 