<x-layouts.portal title="Edit Staff Member" page-title="Team Management">
    <div class="mb-8 flex justify-between items-end">
        <div>
            <a href="{{ route('portal.staff.index') }}" class="text-[10px] font-bold text-amber-600 uppercase tracking-widest hover:underline flex items-center mb-2">
                <svg class="w-3 h-3 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path></svg>
                Back to Team
            </a>
            <h2 class="text-xl font-bold text-zinc-900 tracking-tight">Edit Staff: {{ $staff->name }}</h2>
            <p class="text-xs text-zinc-500 mt-1">Update profile or reset password for this team member.</p>
        </div>
        <x-badge :variant="$staff->active ? 'success' : 'zinc'" :label="$staff->active ? 'Active Account' : 'Inactive Account'" />
    </div>

    <form action="{{ route('portal.staff.update', $staff) }}" method="POST">
        @csrf
        @method('PATCH')
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
            <div class="lg:col-span-2 space-y-6">
                <!-- Basic Information -->
                <x-card title="Basic Information">
                    <div class="space-y-4">
                        <x-input name="name" label="Full Name" :value="old('name', $staff->name)" required />
                        
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <x-input type="email" name="email" label="Email Address" :value="old('email', $staff->email)" required />
                            <x-input name="phone_number" label="Phone Number" :value="old('phone_number', $staff->phone_number)" />
                        </div>

                        <div class="pt-4 border-t border-zinc-100">
                            <label class="text-[10px] font-bold text-zinc-400 uppercase tracking-widest mb-4 block">Update Role</label>
                            <div class="grid grid-cols-2 gap-4">
                                <label class="relative flex items-center p-4 border border-zinc-200 rounded-sm hover:bg-zinc-50 cursor-pointer group">
                                    <input type="radio" name="role" value="waiter" {{ $staff->role == 'waiter' ? 'checked' : '' }} class="sr-only peer">
                                    <div class="w-4 h-4 border-2 border-zinc-300 rounded-full mr-3 peer-checked:border-amber-600 peer-checked:bg-amber-600 transition-all flex items-center justify-center">
                                        <div class="w-1.5 h-1.5 bg-white rounded-full"></div>
                                    </div>
                                    <div>
                                        <p class="text-[11px] font-bold text-zinc-900 leading-none">Waiter</p>
                                        <p class="text-[9px] text-zinc-500 mt-1">Access to Waiter App & KOT</p>
                                    </div>
                                </label>
                                <label class="relative flex items-center p-4 border border-zinc-200 rounded-sm hover:bg-zinc-50 cursor-pointer group">
                                    <input type="radio" name="role" value="biller" {{ $staff->role == 'biller' ? 'checked' : '' }} class="sr-only peer">
                                    <div class="w-4 h-4 border-2 border-zinc-300 rounded-full mr-3 peer-checked:border-amber-600 peer-checked:bg-amber-600 transition-all flex items-center justify-center">
                                        <div class="w-1.5 h-1.5 bg-white rounded-full"></div>
                                    </div>
                                    <div>
                                        <p class="text-[11px] font-bold text-zinc-900 leading-none">Biller / POS</p>
                                        <p class="text-[9px] text-zinc-500 mt-1">Access to Billing & Settlements</p>
                                    </div>
                                </label>
                                <label class="relative flex items-center p-4 border border-zinc-200 rounded-sm hover:bg-zinc-50 cursor-pointer group">
                                     <input type="radio" name="role" value="kitchen" {{ $staff->role == 'kitchen' ? 'checked' : '' }} class="sr-only peer">
                                     <div class="w-4 h-4 border-2 border-zinc-300 rounded-full mr-3 peer-checked:border-amber-600 peer-checked:bg-amber-600 transition-all flex items-center justify-center">
                                         <div class="w-1.5 h-1.5 bg-white rounded-full"></div>
                                     </div>
                                     <div>
                                         <p class="text-[11px] font-bold text-zinc-900 leading-none">Kitchen / KDS</p>
                                         <p class="text-[9px] text-zinc-500 mt-1">Access to Live Order Display</p>
                                     </div>
                                 </label>
                            </div>
                        </div>
                    </div>
                </x-card>

                <!-- Security / Reset Password -->
                <x-card title="Security & Password" description="Leave password fields blank to keep current password.">
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <x-input type="password" name="password" label="New Password (Optional)" placeholder="••••••••" />
                        <x-input type="password" name="password_confirmation" label="Confirm New Password" placeholder="••••••••" />
                    </div>
                </x-card>
            </div>

            <div class="space-y-6">
                <x-card title="Account Meta">
                    <div class="space-y-3">
                        <div class="flex justify-between items-center">
                            <span class="text-[10px] font-bold text-zinc-400 uppercase tracking-tighter">Joined On</span>
                            <span class="text-[10px] font-bold text-zinc-600">{{ $staff->created_at->format('M d, Y') }}</span>
                        </div>
                        <div class="flex justify-between items-center">
                            <span class="text-[10px] font-bold text-zinc-400 uppercase tracking-tighter">Branch ID</span>
                            <span class="text-[10px] font-bold text-zinc-600">#{{ $staff->active_branch_id }}</span>
                        </div>
                    </div>
                </x-card>

                <div class="pt-4">
                    <x-button type="submit" class="w-full py-4! text-xs!">
                        Update Staff Record
                    </x-button>
                </div>
            </div>
        </div>
    </form>
</x-layouts.portal>
