@extends('layouts.app')

@section('title', "Edit User — {$user->name}")

@section('content')
<div class="max-w-xl mx-auto space-y-6">

    <div class="flex items-center justify-between pb-4 border-b border-slate-200">
        <div>
            <h1 class="text-2xl font-bold text-slate-900 tracking-tight">Edit User Account</h1>
            <p class="text-xs text-slate-500 mt-1">Update user account permissions and settings.</p>
        </div>
        <a href="{{ route('admin.users.index') }}" class="px-3 py-1.5 bg-slate-100 text-slate-700 font-semibold rounded text-xs">
            &larr; Back to Users
        </a>
    </div>

    @if ($errors->any())
        <div class="bg-red-50 border-l-4 border-red-500 p-4 text-red-700 text-xs rounded">
            <ul class="list-disc list-inside">
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    <form method="POST" action="{{ route('admin.users.update', $user->id) }}" class="bg-white rounded-lg border border-slate-200 shadow-sm p-6 space-y-4">
        @csrf
        @method('PUT')

        <div>
            <label for="name" class="block text-xs font-bold text-slate-700 uppercase mb-1">Full Name *</label>
            <input type="text" name="name" id="name" value="{{ old('name', $user->name) }}" required
                class="w-full px-3 py-2 border border-slate-300 rounded text-sm focus:ring-1 focus:ring-harcourts-blue">
        </div>

        <div>
            <label for="email" class="block text-xs font-bold text-slate-700 uppercase mb-1">Email Address *</label>
            <input type="email" name="email" id="email" value="{{ old('email', $user->email) }}" required
                class="w-full px-3 py-2 border border-slate-300 rounded text-sm focus:ring-1 focus:ring-harcourts-blue">
        </div>

        <div>
            <label for="role" class="block text-xs font-bold text-slate-700 uppercase mb-1">Role *</label>
            <select name="role" id="role" required class="w-full px-3 py-2 border border-slate-300 rounded text-sm focus:ring-1 focus:ring-harcourts-blue">
                <option value="harcourts_admin" {{ old('role', $user->role) === 'harcourts_admin' ? 'selected' : '' }}>Harcourts Admin (Office Staff)</option>
                <option value="designer" {{ old('role', $user->role) === 'designer' ? 'selected' : '' }}>Designer (Design & Marketing Team)</option>
                <option value="super_admin" {{ old('role', $user->role) === 'super_admin' ? 'selected' : '' }}>Super Admin / Portal Owner</option>
            </select>
        </div>

        <div class="pt-2">
            <label class="flex items-center space-x-2 font-bold text-xs text-slate-700 cursor-pointer">
                <input type="checkbox" name="active" value="1" {{ old('active', $user->active) ? 'checked' : '' }} class="rounded text-harcourts-blue">
                <span>Account Active</span>
            </label>
        </div>

        <div class="pt-4 border-t border-slate-100 flex items-center justify-end space-x-3">
            <a href="{{ route('admin.users.index') }}" class="px-4 py-2 text-xs font-semibold text-slate-600">Cancel</a>
            <button type="submit" class="px-5 py-2 bg-harcourts-blue text-white font-bold text-xs uppercase tracking-wider rounded shadow">
                Save Changes
            </button>
        </div>
    </form>

</div>
@endsection
