@extends('layouts.app')

@section('content')
<div class="bg-white shadow rounded p-6 max-w-md mx-auto">
    <h2 class="text-2xl font-bold mb-4">Edit User</h2>

    <form action="{{ route('user.update', $user->id) }}" method="POST">
        @csrf
        @method('PUT')

        <div class="mb-4">
            <label class="block mb-1 font-medium">Name</label>
            <input type="text" name="name" class="w-full border-gray-300 rounded"
                   value="{{ old('name', $user->name) }}" required>
        </div>

        <div class="mb-4">
            <label class="block mb-1 font-medium">Email</label>
            <input type="email" name="email" class="w-full border-gray-300 rounded"
                   value="{{ old('email', $user->email) }}" required>
        </div>

        <div class="mb-4">
            <label class="block mb-1 font-medium">Role</label>
            <select name="role" class="w-full border-gray-300 rounded" required>
                @foreach(\Spatie\Permission\Models\Role::all() as $role)
                    <option value="{{ $role->name }}"
                        {{ $user->hasRole($role->name) ? 'selected' : '' }}>
                        {{ ucfirst($role->name) }}
                    </option>
                @endforeach
            </select>
        </div>
        <!-- Permissions -->
        <div class="mb-4">
            <label class="block mb-1 font-medium">Permissions</label>
            <div class="space-y-2">
                <label class="flex items-center">
                    <input type="checkbox" name="can_sell" value="1"
                        class="mr-2" {{ $user->can_sell ? 'checked' : '' }}>
                    Can Sell
                </label>
                <label class="flex items-center">
                    <input type="checkbox" name="can_lease" value="1"
                        class="mr-2" {{ $user->can_lease ? 'checked' : '' }}>
                    Can Lease
                </label>
                <label class="flex items-center">
                    <input type="checkbox" name="can_rent" value="1"
                        class="mr-2" {{ $user->can_rent ? 'checked' : '' }}>
                    Can Rent
                </label>
            </div>
        </div>

        <button type="submit" class="bg-yellow-500 text-white px-4 py-2 rounded">Update</button>
    </form>
</div>
@endsection
