<?php

declare(strict_types=1);

namespace App\Filament\Components\Table;

use Filament\Tables\Columns\TextColumn;

class DescTextColumn extends TextColumn
{
    public static function create(): static
    {
        return parent::make('desc')
            ->label('توضیحات')
            ->sortable()
            ->getStateUsing(function ($record) {
                $words = explode(' ', $record->desc);
                $value = implode(' ', array_slice($words, 0, 5));
                if (count($words) > 5) {
                    $value .= '...';
                }

                return $value;
            })
            ->toggleable()
            ->toggledHiddenByDefault();
    }
}
