<?php

declare(strict_types=1);

namespace App\Filament\Components\Table;

use Filament\Tables\Columns\TextColumn;

class ReplyTextColumn extends TextColumn
{
    public static function create(): static
    {
        return parent::make('reply.message')
            ->translateLabel()
            ->formatStateUsing(function ($state, $record) {
                if (! $record->reply) {
                    return '-';
                }

                $text = $record->reply->message ?? '-';

                return strlen($text) > 50 ? substr($text, 0, 50) . '...' : $text;
            })
            ->sortable(['reply.message'])
            ->toggleable();
    }
}
