<?php

namespace App\Providers\Filament;

use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\AuthenticateSession;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Widgets;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use Filament\Navigation\NavigationGroup;
use Filament\Navigation\NavigationItem;
use Filament\Navigation\NavigationBuilder;
use App\Filament\Pages\Dashboard;
use App\Filament\Widgets\AccountWidget;
use App\Filament\Widgets\FilamentInfoWidget;

class AdminPanelProvider extends PanelProvider
{
    public function hasDashboard(): bool
    {
        return false;
    }
    public function panel(Panel $panel): Panel
    {
            return Panel::make()
                ->default()
                ->id('admin')
                ->path('admin')
                ->login()
                ->colors([
                    'primary' => Color::Amber,
                ])
                ->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
                ->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
                ->pages([
                    Dashboard::class,
                ])
                ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
                // ->widgets([
                //     AccountWidget::class,
                //     FilamentInfoWidget::class,
                // ])
            ->middleware([
                EncryptCookies::class,
                AddQueuedCookiesToResponse::class,
                StartSession::class,
                AuthenticateSession::class,
                ShareErrorsFromSession::class,
                VerifyCsrfToken::class,
                SubstituteBindings::class,
                DisableBladeIconComponents::class,
                DispatchServingFilamentEvent::class,
            ])
            ->authMiddleware([
                Authenticate::class,
            ]);
    }

    public function navigation(NavigationBuilder $builder): NavigationBuilder
    {
        return $builder
            ->groups([
                NavigationGroup::make('Telegram 管理')  // 父级群组
                    ->items([
                        NavigationItem::make('指令列表')   // 子菜单项
                            ->icon('heroicon-o-command-line')
                            ->url(route('filament.admin.resources.tg-comm.index'))
                            ->isActiveWhen(fn (): bool => request()->routeIs('filament.admin.resources.tg-comm.*')),
                        
                        NavigationItem::make('其它功能')
                            ->icon('heroicon-o-cog')
                            ->url(route('filament.admin.pages.other-functions'))
                            ->isActiveWhen(fn (): bool => request()->routeIs('filament.admin.pages.other-functions')),
                    ]),
            ]);
    }

}
