components([ Grid::make(12) ->columnSpanFull() ->schema([ Section::make('Grup evaluare') ->columnSpan(4) ->schema([ TextInput::make('name') ->label('Denumire') ->required() ->maxLength(255), TextInput::make('code') ->label('Cod') ->maxLength(100) ->helperText('Opțional, pentru identificare internă.'), TextInput::make('description') ->label('Descriere') ->maxLength(255), ]) ->columns(1), // ========================= // CATEGORIES ASSEMBLER // ========================= Section::make('Categorii') ->columnSpan(8) ->schema([ Repeater::make('groupCategories') ->label('Categorii în acest grup') ->relationship('groupCategories') ->orderColumn('order') ->reorderable() ->collapsed() ->reactive() ->itemLabel(function (array $state): string { $category = EvaluationCategory::find($state['evaluation_category_id']); return $category?->name ?? 'Categorie'; }) ->schema([ Select::make('evaluation_category_id') ->label('Categorie') ->relationship('category', 'name') ->searchable() ->preload() ->required() ->createOptionForm(function (Schema $schema) { return EvaluationCategoryResource::form($schema); }) ->createOptionUsing(function (array $data): int { $data['team_id'] = Filament::getTenant()->id; return EvaluationCategory::create($data)->getKey(); }) ->editOptionForm(function (Schema $schema) { return EvaluationCategoryResource::form($schema); }) ->createOptionAction( fn (Action $action) => $action ->modalWidth(Width::ScreenTwoExtraLarge) ->slideOver() ->modalSubmitActionLabel('Adaugă categorie') ->link() ->color('warning') ->label('Adaugă') ) ->editOptionAction( fn (Action $action) => $action ->modalWidth(Width::ScreenTwoExtraLarge) ->slideOver() ->modalSubmitActionLabel('Editează categorie') ->link() ->color('warning') ->label('Editează') ) ->helperText('Selectează o categorie existentă sau creează una nouă.'), TextEntry::make('questions_preview') ->label('Întrebări') ->state(function (callable $get) { $categoryId = $get('evaluation_category_id'); if (! $categoryId) { return new \Illuminate\Support\HtmlString('— Selectează o categorie.'); } $category = EvaluationCategory::query() ->with('questions') ->find($categoryId); if (! $category || $category->questions->isEmpty()) { return new \Illuminate\Support\HtmlString('— Fără întrebări.'); } $html = '
'; foreach ($category->questions as $question) { $html .= '
'; $html .= '
' . e($question->question) . '
'; // Action trigger button $html .= ''; $html .= '
'; } $html .= '
'; return new \Illuminate\Support\HtmlString($html); }) ->columnSpanFull(), ]) ->minItems(1), ]), ]) ]); } public function editAction(): Action { return Action::make('edit') ->modalHeading('Editează întrebare') ->modalWidth(Width::ScreenTwoExtraLarge) ->schema(fn (Schema $schema, array $arguments) => EvaluationQuestionForm::configure($schema) ) ->mountUsing(function (Action $action, array $arguments) { $question = EvaluationQuestion::find($arguments['questionId']); $action->record($question); }) ->action(function (array $data, Action $action) { $action->getRecord()->update($data); }); } }