<?php

declare(strict_types=1);

namespace App\Filament\Components\Table;

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

class UserTextColumn extends TextColumn
{
    public static function create(): static
    {
        return parent::make('user.name')
            ->label('کاربر')
            ->formatStateUsing(function ($state, $record) {
                if (! $record->user) {
                    return '-';
                }

                $contact = $record->user->cellphone ?: $record->user->email ?: '-';
                $name = $record->user->name ?? '-';

                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(['user.name'])
            ->toggleable()
            ->toggledHiddenByDefault();
    }
}
