import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SettingsResolver } from '@shared/services';
import { FeatureFlagGuard } from './guards/feature-flag.guard'

const routes: Routes = [
    {
        path: '',
        redirectTo: 'onlineboard',
        pathMatch: 'full',
    },
    {
        path: 'ru',
        redirectTo: 'onlineboard'
    },
    {
        path: 'en',
        redirectTo: 'onlineboard'
    },
    {
        path: 'es',
        redirectTo: 'onlineboard'
    },
    {
        path: 'fr',
        redirectTo: 'onlineboard'
    },
    {
        path: 'it',
        redirectTo: 'onlineboard'
    },
    {
        path: 'ja',
        redirectTo: 'onlineboard'
    },
    {
        path: 'ko',
        redirectTo: 'onlineboard'
    },
    {
        path: 'zh',
        redirectTo: 'onlineboard'
    },
    {
        path: 'de',
        redirectTo: 'onlineboard'
    },
    {
        path: 'onlineboard',
        loadChildren: () =>
            import('./features/online-board/online-board.module').then(
                (m) => m.OnlineBoardModule,
            ),
        resolve: {
            [SettingsResolver.KEY]: SettingsResolver,
        },
    },
    {
        path: 'schedule',
        loadChildren: () =>
            import('./features/schedule/schedule.module').then(
                (m) => m.ScheduleModule,
            ),
        resolve: {
            [SettingsResolver.KEY]: SettingsResolver,
        },
    },
    {
        path: 'flights-map',
        data: { featureFlag: 'flightsMap' } as const,
        canLoad: [FeatureFlagGuard],
        loadChildren: () =>
            import('./features/flights-map/flights-map.module').then(
                (m) => m.FlightsMapModule,
            ),
        resolve: {
            [SettingsResolver.KEY]: SettingsResolver,
        },
    },
    {
        path: 'error',
        loadChildren: () =>
            import('./modules/pages/error-pages/error-pages.module').then(
                (m) => m.ErrorPagesModule,
            ),
    },
    {
        path: '**',
        redirectTo: 'error/404',
    },
];

@NgModule({
    imports: [
        RouterModule.forRoot(routes, {
            onSameUrlNavigation: 'reload',
            enableTracing: false,
            initialNavigation: 'enabled',
        }),
    ],
    exports: [RouterModule],
})
export class AppRoutingModule {}
