<?php

namespace App\Providers\Filament;

use Filament\Widgets\AccountWidget;
use Filament\Widgets\FilamentInfoWidget;
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\View\PanelsRenderHook;
use Illuminate\Support\Facades\Blade;
use Composer\InstalledVersions;
use Illuminate\Support\Facades\Auth;
use Filament\FontProviders\GoogleFontProvider;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->default()
            ->authGuard('web')
            ->id('admin')
            ->path('admin')
            ->login()
            ->colors([
                'primary' => Color::Amber,
            ])
            ->brandLogo(fn () => view('filament.admin.logo'))
            ->brandLogoHeight('2rem')
            ->font('Oswald', provider: GoogleFontProvider::class)
            ->favicon(asset('/storage/favicon/favicon-32x32.png'))
            ->breadcrumbs(false)
            ->collapsibleNavigationGroups(false)
            ->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
            ->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
            ->pages([
                // Pages\Dashboard::class,
            ])
            ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
            ->widgets([
                AccountWidget::class,
                FilamentInfoWidget::class,
            ])
            ->renderHook(
                PanelsRenderHook::GLOBAL_SEARCH_BEFORE,
                fn() => Blade::render(Auth::check() ? '<footer style="width:100%; display:flex; flex-direction:column; align-items:center; justify-content:center;"><div style="font-size:0.875rem; color:#6B7280; text-align:center; color:#9CA3AF;">Wykonane przez <a href="https://bwitek.dev" target="_blank" style="font-weight:500;">Bogusław Witek</a>.</div><div style="font-size:0.875rem; color:#6B7280; text-align:center; color:#9CA3AF;">© <?php echo date("Y"); ?> <a href="https://ghost-pizza.pl" target="_blank" style="font-weight:500;">GHOST PIZZA Krzysztof Szymański</a>. Wszelkie prawa zastrzeżone.</div></footer>' : null)
            )
            ->renderHook(
                PanelsRenderHook::BODY_END,
                fn() => Blade::render(!Auth::check() ? '<footer style="position:fixed; bottom:0; left:0; right:0; text-align:center; width:100%; background-color:transparent; box-shadow:0 1px 3px rgba(0,0,0,0.1); display:flex; flex-direction:column; align-items:center; justify-content:center;"><div style="margin-top:0.5rem; font-size:0.875rem; color:#6B7280; text-align:center; color:#9CA3AF;">© <?php echo date("Y"); ?> <a href="https://ghost-pizza.pl" target="_blank" style="font-weight:500;">GHOST PIZZA Krzysztof Szymański</a>. Wszelkie prawa zastrzeżone.</div><div style="margin-bottom:0.5rem; font-size:0.875rem; color:#6B7280; text-align:center; color:#9CA3AF;">Wykonane przez <a href="https://bwitek.dev" target="_blank" style="font-weight:500;">Bogusław Witek</a>.</div></footer>' : null)
            )
            ->globalSearch(false)     
            ->middleware([
                EncryptCookies::class,
                AddQueuedCookiesToResponse::class,
                StartSession::class,
                AuthenticateSession::class,
                ShareErrorsFromSession::class,
                VerifyCsrfToken::class,
                SubstituteBindings::class,
                DisableBladeIconComponents::class,
                DispatchServingFilamentEvent::class,
            ])
            ->authMiddleware([
                Authenticate::class,
            ]);
    }
}