TenantAtlas/app/Filament/Widgets/Workspace/WorkspaceSummaryStats.php
2026-03-09 22:52:00 +01:00

65 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filament\Widgets\Workspace;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
class WorkspaceSummaryStats extends StatsOverviewWidget
{
protected static bool $isLazy = false;
protected int|string|array $columnSpan = 'full';
protected ?string $pollingInterval = null;
/**
* @var array<int, array{
* key: string,
* label: string,
* value: int,
* description: string,
* destination_url: ?string,
* color: string
* }>
*/
public array $metrics = [];
/**
* @param array<int, array{
* key: string,
* label: string,
* value: int,
* description: string,
* destination_url: ?string,
* color: string
* }> $metrics
*/
public function mount(array $metrics = []): void
{
$this->metrics = $metrics;
}
/**
* @return array<Stat>
*/
protected function getStats(): array
{
return collect($this->metrics)
->map(function (array $metric): Stat {
$stat = Stat::make($metric['label'], $metric['value'])
->description($metric['description'])
->color($metric['color']);
if ($metric['destination_url'] !== null) {
$stat->url($metric['destination_url']);
}
return $stat;
})
->all();
}
}