<?php

declare(strict_types=1);

namespace App\Filament\Widgets\Dashboard;

use App\Models\Tenant;
use App\Support\TenantDashboard\TenantDashboardSummaryBuilder;
use Filament\Facades\Filament;
use Filament\Widgets\Widget;

class TenantDashboardContextChips extends Widget
{
    protected static bool $isLazy = false;

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

    protected string $view = 'filament.widgets.dashboard.tenant-dashboard-context-chips';

    /**
     * @return array<string, mixed>
     */
    protected function getViewData(): array
    {
        $tenant = Filament::getTenant();

        if (! $tenant instanceof Tenant) {
            return [
                'context' => [
                    'workspace' => __('localization.dashboard.overview.context_workspace'),
                    'tenant' => __('localization.dashboard.overview.context_no_tenant'),
                    'provider' => null,
                    'providerKey' => null,
                    'latestActivity' => null,
                ],
                'pollingInterval' => null,
            ];
        }

        $summary = app(TenantDashboardSummaryBuilder::class)->build($tenant, auth()->user());

        return [
            'context' => $summary->context,
            'pollingInterval' => $summary->pollingInterval,
        ];
    }
}