<?php

namespace App\Filament\Widgets;

use App\Support\AdminDashboard;
use Filament\Widgets\ChartWidget;

class RevenueChart extends ChartWidget
{
    protected ?string $heading = 'Verified revenue';

    protected ?string $description = 'Paid transactions only. Currencies stay separate.';

    protected int|string|array $columnSpan = ['md' => 2, 'xl' => 4];

    protected static ?int $sort = -2;

    protected function getData(): array
    {
        $trend = app(AdminDashboard::class)->snapshot()['revenueTrend'];

        return [
            'datasets' => [
                ['label' => 'KES', 'data' => $trend['kes'], 'backgroundColor' => 'rgba(88,185,230,.65)', 'borderColor' => '#2787b8', 'borderRadius' => 5],
                ['label' => 'USD', 'data' => $trend['usd'], 'backgroundColor' => 'rgba(28,43,95,.58)', 'borderColor' => '#1c2b5f', 'borderRadius' => 5],
            ],
            'labels' => $trend['labels'],
        ];
    }

    protected function getType(): string
    {
        return 'bar';
    }

    protected function getOptions(): array
    {
        return [
            'plugins' => ['legend' => ['position' => 'bottom']],
            'scales' => ['y' => ['beginAtZero' => true]],
        ];
    }
}
