<x-app-layout>
    <x-slot name="header">
        <div class="flex items-center justify-between w-full">
            <div>
                <h1 class="text-lg font-semibold text-gray-800">Edit User</h1>
                <p class="text-xs text-gray-400 mt-0.5">Update sub-user details and roles</p>
            </div>
            <a href="{{ route('business-users.index') }}" class="inline-flex items-center gap-1.5 text-sm text-gray-500 hover:text-indigo-600 transition">
                <svg class="w-4 h-4" 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"/></svg>
                Back to Users
            </a>
        </div>
    </x-slot>

    <div class="max-w-2xl mx-auto py-6">
        <form method="POST" action="{{ route('business-users.update', $user->id) }}" class="bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden p-6 space-y-6">
            @csrf
            @method('PUT')

            <div>
                <h2 class="text-sm font-semibold text-gray-800 uppercase tracking-wider mb-4">User Details</h2>
                <div class="grid grid-cols-1 sm:grid-cols-2 gap-5">
                    <div class="sm:col-span-2">
                        <label class="block text-xs font-medium text-gray-500 mb-1.5">Full Name</label>
                        <input type="text" name="name" value="{{ old('name', $user->name) }}" required placeholder="e.g. Ali Khan" class="w-full rounded-xl border-gray-200 text-xs focus:border-indigo-400 focus:ring-indigo-400">
                        @error('name') <p class="text-red-500 text-[10px] mt-1">{{ $message }}</p> @enderror
                    </div>

                    <div class="sm:col-span-2">
                        <label class="block text-xs font-medium text-gray-500 mb-1.5">Email Address</label>
                        <input type="email" name="email" value="{{ old('email', $user->email) }}" required placeholder="user@company.com" class="w-full rounded-xl border-gray-200 text-xs focus:border-indigo-400 focus:ring-indigo-400">
                        @error('email') <p class="text-red-500 text-[10px] mt-1">{{ $message }}</p> @enderror
                    </div>

                    <div>
                        <label class="block text-xs font-medium text-gray-500 mb-1.5">Password <span class="text-gray-400">(leave blank to keep current)</span></label>
                        <input type="password" name="password" placeholder="••••••••" class="w-full rounded-xl border-gray-200 text-xs focus:border-indigo-400 focus:ring-indigo-400">
                        @error('password') <p class="text-red-500 text-[10px] mt-1">{{ $message }}</p> @enderror
                    </div>

                    <div>
                        <label class="block text-xs font-medium text-gray-500 mb-1.5">Confirm Password</label>
                        <input type="password" name="password_confirmation" placeholder="••••••••" class="w-full rounded-xl border-gray-200 text-xs focus:border-indigo-400 focus:ring-indigo-400">
                    </div>

                    <div class="sm:col-span-2">
                        <label class="block text-xs font-medium text-gray-500 mb-1.5">Assigned Role</label>
                        <select name="role" class="w-full rounded-xl border-gray-200 text-xs focus:border-indigo-400 focus:ring-indigo-400">
                            <option value="">Select a Role</option>
                            @foreach($roles as $role)
                                <option value="{{ $role->name }}" {{ old('role', $user->roles->pluck('name')->first()) === $role->name ? 'selected' : '' }}>{{ $role->name }}</option>
                            @endforeach
                        </select>
                        @error('role') <p class="text-red-500 text-[10px] mt-1">{{ $message }}</p> @enderror
                    </div>
                </div>
            </div>

            <div class="flex justify-end gap-3 border-t border-gray-50 pt-4">
                <a href="{{ route('business-users.index') }}" class="px-4 py-2 border border-gray-200 rounded-xl text-xs font-semibold text-gray-600 hover:bg-gray-50 transition">Cancel</a>
                <button type="submit" class="px-4 py-2 bg-indigo-600 hover:bg-indigo-700 text-white rounded-xl text-xs font-semibold transition">Save Changes</button>
            </div>
        </form>
    </div>
</x-app-layout>
