@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 Role</h1>

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

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

        <div>
            <label class="mb-2 block text-sm font-medium text-gray-700">Permission</label>
            <div class="grid grid-cols-2 gap-2">
                @foreach ($permissions as $permission)
                    <label class="flex items-center gap-2 text-sm text-gray-700">
                        <input type="checkbox" name="permissions[]" value="{{ $permission->id }}"
                               @checked(in_array($permission->id, old('permissions', $rolePermissions)))>
                        {{ $permission->name }}
                    </label>
                @endforeach
            </div>
        </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.roles.index') }}" class="rounded border border-gray-300 px-4 py-2 text-sm text-gray-700">Batal</a>
        </div>
    </form>
</div>
@endsection
