<?php

declare(strict_types=1);

namespace App\Filament\Navigation;

use App\Filament\Resources\ProductResource;
use App\Models\Product;
use Filament\Navigation\NavigationItem;
use Illuminate\Support\Str;

class ProductNavigation
{
    public static function getNavigationItems(): array
    {
        // Fetch unique model_type values
        $modelTypes = Product::distinct()->pluck('model_type')->filter()->values();

        return collect($modelTypes)->map(function ($modelType) {
            $item = match ($modelType) {
                'App\Models\Gift' => ['title' => 'گیفت کارت ها', 'icon' => 'heroicon-o-gift'],
                'App\Models\Payment' => ['title' => 'پرداخت ها', 'icon' => 'heroicon-o-credit-card'],
                'App\Models\Game' => ['title' => 'بازی ها', 'icon' => 'heroicon-o-puzzle-piece'],
                default => ['title' => Str::replace('App\Models\\', '', $modelType), 'icon' => 'heroicon-o-shopping-cart'],
            };

            return NavigationItem::make($item['title'])
                ->url(fn () => ProductResource::getUrl('index', [
                    'tableFilters[model_type][value]' => $modelType,
                ]))
                ->icon($item['icon'])
                ->group($item['title'])
                ->sort(0); // Optional: Adjust sort order if needed
        })->toArray();
    }
}
