<?php

namespace App\Filament\Admin\Widgets;

use App\Models\Order;
use Filament\Widgets\ChartWidget;

class OrderPipelineChart extends ChartWidget
{
    protected static ?string $heading = 'Order Pipeline';

    protected int|string|array $columnSpan = 1;

    protected function getData(): array
    {
        $statuses = Order::statuses();
        $counts = [];

        foreach (array_keys($statuses) as $status) {
            $counts[] = Order::where('status', $status)->count();
        }

        return [
            'datasets' => [
                [
                    'label' => 'Orders',
                    'data' => $counts,
                    'backgroundColor' => [
                        '#f59e0b',
                        '#3b82f6',
                        '#6366f1',
                        '#10b981',
                        '#22c55e',
                        '#ef4444',
                    ],
                ],
            ],
            'labels' => array_values($statuses),
        ];
    }

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