@extends('layouts.app')

@section('content')
    <div class="row justify-content-center">
        <div class="col-lg-6">
            <div class="card shadow-sm">
                <div class="card-header fw-bold">Edit permission module</div>
                <div class="card-body">
                    <form method="POST" action="{{ route('visibility-modules.update', $module) }}" class="row g-2">
                        @csrf
                        @method('PUT')
                        <div class="col-12">
                            <label class="form-label">Key</label>
                            <input name="key" class="form-control font-monospace" required maxlength="80" value="{{ old('key', $module->key) }}">
                            <div class="form-text">Changing the key updates existing department and user permission rows.</div>
                        </div>
                        <div class="col-12">
                            <label class="form-label">Label</label>
                            <input name="label" class="form-control" required maxlength="120" value="{{ old('label', $module->label) }}">
                        </div>
                        <div class="col-12">
                            <label class="form-label">Group</label>
                            <input name="group" class="form-control" required maxlength="80" value="{{ old('group', $module->group) }}">
                        </div>
                        <div class="col-12">
                            <label class="form-label">Description</label>
                            <input name="description" class="form-control" maxlength="255" value="{{ old('description', $module->description) }}">
                        </div>
                        <div class="col-12">
                            <label class="form-label">Sort order</label>
                            <input type="number" name="sort_order" class="form-control" min="0" max="9999" value="{{ old('sort_order', $module->sort_order) }}">
                        </div>
                        <div class="col-12 form-check">
                            <input type="hidden" name="is_active" value="0">
                            <input class="form-check-input" type="checkbox" name="is_active" value="1" id="mod_act" {{ old('is_active', $module->is_active) ? 'checked' : '' }}>
                            <label class="form-check-label" for="mod_act">Active (inactive modules are ignored for access checks)</label>
                        </div>
                        <div class="col-12 d-flex gap-2">
                            <button class="btn btn-primary">Update</button>
                            <a href="{{ route('visibility-modules.index') }}" class="btn btn-outline-secondary">Back</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection
