<?php

declare(strict_types=1);

namespace App\Filament\Components\Table;

use Filament\Tables\Columns\TextColumn;
use Illuminate\Support\HtmlString;

class SenderTextColumn extends TextColumn
{
    public static function create(): static
    {
        return parent::make('sender.name')
            ->translateLabel()
            ->formatStateUsing(function ($state, $record) {
                $contact = $record->sender->cellphone ?: $record->sender->email;
                $name = $record->sender->name ?? '-';
                $contact = $contact ?? '-';

                return new HtmlString(<<<HTML
                    <div class="space-y-1">
                        <div class="font-medium">{$name}</div>
                        <div class="text-sm text-gray-500">{$contact}</div>
                    </div>
                HTML);
            })
            ->sortable(['sender.name'])
            ->toggleable();
    }
}
