<?php

namespace Tests\Unit;

use App\Filament\Clusters\DailyOps\DailyOpsCluster;
use App\Filament\Clusters\RareAdmin\RareAdminCluster;
use App\Filament\Clusters\WeeklyOps\WeeklyOpsCluster;
use App\Providers\Filament\SuperAdminPanelProvider;
use Filament\Pages\Enums\SubNavigationPosition;
use Filament\Panel;
use Tests\TestCase;

class SuperAdminNavigationGroupsTest extends TestCase
{
    public function test_super_admin_navigation_groups_use_translated_labels(): void
    {
        app()->setLocale('en');

        $expectations = [
            \App\Filament\Resources\EventResource::class => 'admin.nav.events',
            \App\Filament\Resources\EventTypeResource::class => 'admin.nav.events',
            \App\Filament\Resources\PhotoResource::class => 'admin.nav.events',
            \App\Filament\Resources\TaskResource::class => 'admin.nav.curation',
            \App\Filament\Resources\EmotionResource::class => 'admin.nav.curation',
            \App\Filament\Resources\LegalPageResource::class => 'admin.nav.content',
            \App\Filament\Blog\Resources\PostResource::class => 'admin.nav.content',
            \App\Filament\Blog\Resources\CategoryResource::class => 'admin.nav.content',
            \App\Filament\Resources\UserResource::class => 'admin.nav.platform',
            \App\Filament\Resources\TenantResource::class => 'admin.nav.tenants',
            \App\Filament\Resources\MediaStorageTargetResource::class => 'admin.nav.storage',
            \App\Filament\Resources\PackageAddonResource::class => 'admin.nav.commercial',
            \App\Filament\Resources\PackageResource::class => 'admin.nav.commercial',
            \App\Filament\Resources\PhotoboothSettings\PhotoboothSettingResource::class => 'admin.nav.storage',
            \App\Filament\Resources\PurchaseResource::class => 'admin.nav.billing',
            \App\Filament\Clusters\DailyOps\Resources\TenantPaddleHealths\TenantPaddleHealthResource::class => 'admin.nav.billing',
            \App\Filament\Resources\PurchaseHistoryResource::class => 'admin.nav.commercial',
            \App\Filament\Resources\EventPurchaseResource::class => 'admin.nav.commercial',
            \App\Filament\Resources\TenantPackageResource::class => 'admin.nav.commercial',
            \App\Filament\Resources\Coupons\CouponResource::class => 'admin.nav.commercial',
            \App\Filament\Resources\GiftVoucherResource::class => 'admin.nav.commercial',
            \App\Filament\Resources\TenantFeedbackResource::class => 'admin.nav.feedback_support',
            \App\Filament\Resources\InfrastructureActionLogs\InfrastructureActionLogResource::class => 'admin.nav.infrastructure',
            \App\Filament\SuperAdmin\Pages\WatermarkSettingsPage::class => 'admin.nav.branding',
            \App\Filament\SuperAdmin\Pages\DokployDeployments::class => 'admin.nav.infrastructure',
            \App\Filament\SuperAdmin\Pages\OpsHealthDashboard::class => 'admin.nav.infrastructure',
            \App\Filament\SuperAdmin\Pages\IntegrationsHealthDashboard::class => 'admin.nav.infrastructure',
            \App\Filament\Clusters\DailyOps\Pages\JoinTokenAnalyticsDashboard::class => 'admin.nav.security',
        ];

        foreach ($expectations as $resourceClass => $key) {
            $this->assertSame(__($key), $resourceClass::getNavigationGroup(), $resourceClass);
        }

        $clusterExpectations = [
            \App\Filament\Resources\EventResource::class => DailyOpsCluster::class,
            \App\Filament\Resources\PhotoResource::class => DailyOpsCluster::class,
            \App\Filament\Resources\TenantResource::class => DailyOpsCluster::class,
            \App\Filament\Resources\PurchaseResource::class => DailyOpsCluster::class,
            \App\Filament\Clusters\DailyOps\Resources\TenantPaddleHealths\TenantPaddleHealthResource::class => DailyOpsCluster::class,
            \App\Filament\Resources\TenantFeedbackResource::class => DailyOpsCluster::class,
            \App\Filament\SuperAdmin\Pages\OpsHealthDashboard::class => DailyOpsCluster::class,
            \App\Filament\SuperAdmin\Pages\IntegrationsHealthDashboard::class => DailyOpsCluster::class,
            \App\Filament\Clusters\DailyOps\Pages\JoinTokenAnalyticsDashboard::class => DailyOpsCluster::class,
            \App\Filament\Resources\TaskResource::class => WeeklyOpsCluster::class,
            \App\Filament\Resources\EmotionResource::class => WeeklyOpsCluster::class,
            \App\Filament\Resources\EventTypeResource::class => WeeklyOpsCluster::class,
            \App\Filament\Resources\UserResource::class => WeeklyOpsCluster::class,
            \App\Filament\Resources\PackageResource::class => WeeklyOpsCluster::class,
            \App\Filament\Resources\PackageAddonResource::class => WeeklyOpsCluster::class,
            \App\Filament\Resources\TenantPackageResource::class => WeeklyOpsCluster::class,
            \App\Filament\Resources\Coupons\CouponResource::class => WeeklyOpsCluster::class,
            \App\Filament\Resources\GiftVoucherResource::class => WeeklyOpsCluster::class,
            \App\Filament\Resources\PurchaseHistoryResource::class => WeeklyOpsCluster::class,
            \App\Filament\Resources\EventPurchaseResource::class => WeeklyOpsCluster::class,
            \App\Filament\Resources\InfrastructureActionLogs\InfrastructureActionLogResource::class => RareAdminCluster::class,
            \App\Filament\Resources\MediaStorageTargetResource::class => RareAdminCluster::class,
            \App\Filament\Resources\PhotoboothSettings\PhotoboothSettingResource::class => RareAdminCluster::class,
            \App\Filament\Resources\LegalPageResource::class => RareAdminCluster::class,
            \App\Filament\Blog\Resources\PostResource::class => RareAdminCluster::class,
            \App\Filament\Blog\Resources\CategoryResource::class => RareAdminCluster::class,
            \App\Filament\SuperAdmin\Pages\WatermarkSettingsPage::class => RareAdminCluster::class,
            \App\Filament\SuperAdmin\Pages\DokployDeployments::class => RareAdminCluster::class,
        ];

        foreach ($clusterExpectations as $resourceClass => $clusterClass) {
            $this->assertSame($clusterClass, $resourceClass::getCluster(), $resourceClass);
        }

        $this->assertSame(SubNavigationPosition::Top, DailyOpsCluster::getSubNavigationPosition());
        $this->assertSame(SubNavigationPosition::Top, WeeklyOpsCluster::getSubNavigationPosition());
        $this->assertSame(SubNavigationPosition::Top, RareAdminCluster::getSubNavigationPosition());
    }

    public function test_super_admin_panel_uses_top_navigation(): void
    {
        $provider = new SuperAdminPanelProvider(app());
        $panel = $provider->panel(Panel::make());

        $this->assertTrue($panel->hasTopNavigation());
    }
}
