<?php

declare(strict_types=1);

namespace App\Filament\Navigation;

use App\Filament\Resources\Categories\CategoryResource;
use App\Models\Category;
use Filament\Navigation\NavigationItem;

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

        return collect($modelTypes)->map(function ($modelType) {
            $item = match ($modelType) {
                'App\Models\Post' => ['title' => 'بلاگ', 'icon' => 'heroicon-o-newspaper'],
                'App\Models\Product' => ['title' => 'محصولات', 'icon' => 'heroicon-o-shopping-cart'],
                'App\Models\Game' => ['title' => 'بازی ها', 'icon' => 'heroicon-o-puzzle-piece'],
                'App\Models\Gift' => ['title' => 'گیفت کارت ها', 'icon' => 'heroicon-o-gift'],
                'App\Models\Appleid' => ['title' => 'اپل ایدی ها', 'icon' => 'heroicon-o-apple'],
                'App\Models\Application' => ['title' => 'برنامه ها', 'icon' => 'heroicon-o-device-phone-mobile'],
                'App\Models\Payment' => ['title' => 'پرداخت ها', 'icon' => 'heroicon-o-credit-card'],
                default => ['title' => 'دسته بندی', 'icon' => 'heroicon-o-folder'],
            };

            return NavigationItem::make('دسته بندی ' . $item['title'])
                ->url(fn () => CategoryResource::getUrl('index', [
                    'tableFilters[model_type][value]' => $modelType,
                ]))
                ->icon($item['icon'])
                ->group($item['title'])
                ->sort(0); // Optional: Adjust sort order if needed
        })->toArray();
    }
}
