<?php

declare(strict_types=1);

namespace App\Filament\Navigation;

use App\Filament\Resources\Faqs\FaqResource;
use App\Models\Faq;
use Filament\Navigation\NavigationItem;
use Illuminate\Support\Str;

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

        return collect($modelTypes)->map(function ($modelType) {
            $item = match ($modelType) {
                'App\Models\Page' => ['title' => 'صفحات', 'icon' => 'heroicon-o-document'],
                default => ['title' => Str::replace('App\Models\\', '', $modelType), 'icon' => 'heroicon-o-question-mark-circle'],
            };

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