src/Filament/Resources/TaskResource/RelationManagers/CommentsRelationManager.php
<?php

declare(strict_types=1);

namespace Alessandronuunes\TasksManagement\Filament\Resources\TaskResource\RelationManagers;

use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;

class CommentsRelationManager extends RelationManager
{
    protected static string $relationship = 'comments';

    public static function getTitle(Model $ownerRecord, string $pageClass): string
    {
        return __('tasks-management::fields.comments.title');
    }

    public function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\RichEditor::make('content')
                    ->label(__('tasks-management::fields.comments.content'))
                    ->required()
                    ->columnSpanFull(),
            ]);
    }

    public function table(Table $table): Table
    {
        return $table
            ->recordTitleAttribute('content')
            ->columns([
                Tables\Columns\TextColumn::make('user.name')
                    ->label(__('tasks-management::fields.comments.user')),
                Tables\Columns\TextColumn::make('content')
                    ->label(__('tasks-management::fields.comments.content'))
                    ->html()
                    ->wrap(),
                Tables\Columns\TextColumn::make('created_at')
                    ->label(__('tasks-management::fields.comments.created_at'))
                    ->dateTime(),
            ])
            ->headerActions([
                Tables\Actions\CreateAction::make()
                    ->label(__('tasks-management::fields.comments.actions.create'))
                    ->createAnother(config('tasks-management.actions.create_another', false))
                    ->modalHeading(__('tasks-management::fields.comments.modal.new')),
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
                Tables\Actions\DeleteAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }
}
