<?php

namespace App\Filament\Clusters\Cards\CardOrders\Pages;

use App\Filament\Clusters\Cards\CardOrders\CardOrderResource;
use App\Modules\OrderStatus\Repositories\OrderStatusRepository;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
use Filament\Schemas\Components\Tabs\Tab;

class ListCardOrders extends ListRecords
{
    protected static string $resource = CardOrderResource::class;

    protected function getHeaderActions(): array
    {
        return [
            CreateAction::make(),
        ];
    }

    public function getTabs(): array
    {
        $data = [];
        foreach (array_keys(OrderStatusRepository::statusClasses()) as $status) {
            if ($status === '') {
                $data[null] = Tab::make(__('All'));
            } else {
                $data[$status] = Tab::make(OrderStatusRepository::statusFormatted($status))->query(fn ($query) => $query->where('status', $status));
            }
        }

        return $data;

        return [
            null => Tab::make('All'),
            'new' => Tab::make()->query(fn ($query) => $query->where('status', 'new')),
            'processing' => Tab::make()->query(fn ($query) => $query->where('status', 'processing')),
            'shipped' => Tab::make()->query(fn ($query) => $query->where('status', 'shipped')),
            'delivered' => Tab::make()->query(fn ($query) => $query->where('status', 'delivered')),
            'cancelled' => Tab::make()->query(fn ($query) => $query->where('status', 'cancelled')),
        ];
    }
}
