@extends('layouts.app')

@section('content')
<div class="container mx-auto max-w-2xl px-4">
    @include('admin.panel._nav')

    <h1 class="mb-6 text-xl font-semibold text-gray-900">Edit Pengguna</h1>

    <form method="POST" action="{{ route('admin.users.update', $user) }}" class="space-y-4">
        @csrf
        @method('PUT')

        <div>
            <label class="block text-sm font-medium text-gray-700">Nama</label>
            <input type="text" name="name" value="{{ old('name', $user->name) }}" required
                   class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm">
        </div>

        <div>
            <label class="block text-sm font-medium text-gray-700">Email</label>
            <input type="email" name="email" value="{{ old('email', $user->email) }}" required
                   class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm">
        </div>

        <div>
            <label class="block text-sm font-medium text-gray-700">Password baru (opsional)</label>
            <input type="password" name="password"
                   class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm">
        </div>

        <div>
            <label class="block text-sm font-medium text-gray-700">Konfirmasi Password baru</label>
            <input type="password" name="password_confirmation"
                   class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm">
        </div>

        <div>
            <label class="block text-sm font-medium text-gray-700">Role</label>
            <select name="role" required class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm">
                @foreach ($roles as $role)
                    <option value="{{ $role->name }}" @selected(old('role', $user->roles->first()?->name) === $role->name)>
                        {{ $role->name }}
                    </option>
                @endforeach
            </select>
        </div>

        <div class="flex items-center gap-2">
            <input type="checkbox" name="is_active" id="is_active" value="1" @checked(old('is_active', $user->is_active))>
            <label for="is_active" class="text-sm text-gray-700">Aktif</label>
        </div>

        <div class="flex gap-3">
            <button type="submit" class="rounded bg-gray-900 px-4 py-2 text-sm text-white hover:bg-gray-700">Simpan</button>
            <a href="{{ route('admin.users.index') }}" class="rounded border border-gray-300 px-4 py-2 text-sm text-gray-700">Batal</a>
        </div>
    </form>
</div>
@endsection
