<?php

namespace App\Filament\Central\Widgets;

use App\Filament\Central\Resources\CompanyResource;
use App\Models\Central\Company;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as BaseWidget;

class RecentTenants extends BaseWidget
{
    protected static ?int $sort = 3;

    protected int|string|array $columnSpan = 'full';

    public function table(Table $table): Table
    {
        return $table
            ->heading('Tenants recenți')
            ->query(Company::query()->latest()->limit(8))
            ->columns([
                Tables\Columns\TextColumn::make('slug')
                    ->copyable()
                    ->url(fn (Company $record) => CompanyResource::getUrl('view', ['record' => $record])),
                Tables\Columns\TextColumn::make('name')->weight('bold'),
                Tables\Columns\TextColumn::make('status')
                    ->badge()
                    ->color(fn ($s) => match ($s) {
                        'active' => 'success',
                        'trial' => 'warning',
                        'suspended', 'expired' => 'danger',
                        default => 'gray',
                    }),
                Tables\Columns\TextColumn::make('plan.name')->placeholder('—'),
                Tables\Columns\TextColumn::make('users_count')->counts('users')->label('Useri'),
                Tables\Columns\TextColumn::make('created_at')->label('Creat')->since(),
            ])
            ->paginated(false);
    }
}
