// Libs
// -----------------------------------------------------------------------------
import { ReactNode } from 'react';
import { Navigate } from 'react-router-dom';

// App
// -----------------------------------------------------------------------------
import { Page, paths } from './constants';
import { AccountsDashboard } from 'pages/AccountsDashboard';
import AssetsDashboard from 'pages/AssetsDashboard';
import CorrelationRulesDashboard from 'pages/CorrelationRulesDashboard';
import IncidentsDashboard from 'pages/IncidentsDashboard';
import EventsJournalDashboard from 'pages/EventsJournalDashboard';
import WidgetsDashboard from 'pages/WidgetsDashboard/WidgetsDashboard';
import RotationDashboard from 'pages/RotationDashboard';
import NCIRCCDashboard from 'pages/NCIRCCDashboard';
import { DevicesDashboard } from 'pages/DevicesDashboard';
import { Login } from '../Login/Login';
import { NetworkMap } from '../NetworkMap/NetworkMap';
import { NetworkActivityMap } from '../NetworkActivityMap/NetworkActivityMap';
import { EventExportSettings } from '../EventExportSettings/EventExportSettings';
import { StorageDashboard } from '../StorageDashboard/StorageDashboard';
import { ProfilePage } from 'pages/ProfilePage/ProfilePage';
import { SettingsDashboard } from '../SettingsDashboard/SettingsDashboard';
import { CorrelationRulesGroupsDashboard } from 'pages/CorrelationRulesGroupsDashboard';
import { LicensePage } from 'pages/LicensePage';
import { LicenseActivationPage } from 'pages/LicenseActivationPage';

export type TypeRoute = {
  path: string;
  exact?: boolean;
  component: ReactNode;
};

export function useRoutes(isLicenseActivated: boolean | null): TypeRoute[] {
  if (isLicenseActivated === true) {
    return [
      // TODO: раскомментировать после релиза
      // {
      //   path: paths[Page.HOME],
      //   component: <WidgetsDashboard />,
      // },

      // TODO: убрать после релиза
      {
        path: paths[Page.HOME],
        component: <Navigate to={paths[Page.INCIDENTS_DASHBOARD]} replace />,
      },

      {
        path: paths[Page.ASSETS_DASHBOARD],
        component: <AssetsDashboard />,
      },
      {
        path: paths[Page.ASSETS_DETAIL],
        component: <AssetsDashboard />,
      },
      {
        path: paths[Page.ASSETS_GROUP],
        component: <AssetsDashboard />,
      },
      {
        path: paths[Page.INCIDENTS_DASHBOARD],
        component: <IncidentsDashboard />,
      },
      {
        path: paths[Page.INCIDENTS_DETAIL],
        component: <IncidentsDashboard />,
      },
      {
        path: paths[Page.CORRELATION_RULES_DASHBOARD],
        component: <CorrelationRulesDashboard />,
      },
      {
        path: paths[Page.CORRELATION_RULES_ADD],
        component: <CorrelationRulesDashboard />,
      },
      {
        path: paths[Page.CORRELATION_RULES_DETAIL],
        component: <CorrelationRulesDashboard />,
      },
      {
        path: paths[Page.CORRELATION_RULES_GROUPS_DASHBOARD],
        component: <CorrelationRulesGroupsDashboard />,
      },
      {
        path: paths[Page.LOGIN],
        component: <Login />,
      },
      {
        path: paths[Page.ROTATION_DASHBOARD_INCIDENTS],
        component: <RotationDashboard />,
      },
      {
        path: paths[Page.ROTATION_DASHBOARD_EVENTS],
        component: <RotationDashboard />,
      },
      {
        path: paths[Page.NETWORK_MAP_STATIC],
        component: <NetworkMap />,
      },
      {
        path: paths[Page.NETWORK_MAP_AUTOMATIC],
        component: <NetworkActivityMap />,
      },
      {
        path: paths[Page.EVENT_EXPORT_SETTING],
        component: <EventExportSettings />,
      },
      {
        path: paths[Page.STORAGE],
        component: <StorageDashboard />,
      },
      {
        path: paths[Page.STORAGE_DETAIL],
        component: <StorageDashboard />,
      },
      {
        path: paths[Page.DEVICES_DASHBOARD],
        component: <DevicesDashboard />,
      },
      {
        path: paths[Page.SECURITY_SYSTEM_DETAIL],
        component: <DevicesDashboard />,
      },
      {
        path: paths[Page.SECURITY_SYSTEM_GROUP],
        component: <DevicesDashboard />,
      },
      {
        path: paths[Page.EVENTS_JOURNAL],
        component: <EventsJournalDashboard />,
      },
      {
        path: paths[Page.EVENTS_DETAIL],
        component: <EventsJournalDashboard />,
      },
      {
        path: paths[Page.ACCOUNTS_USER_ID],
        component: <AccountsDashboard />,
      },
      {
        path: paths[Page.ACCOUNTS_GROUP],
        component: <AccountsDashboard />,
      },
      {
        path: paths[Page.ACCOUNTS_USER],
        component: <AccountsDashboard />,
      },
      {
        path: paths[Page.NCIRCC_ORGANIZATION_CARD],
        component: <NCIRCCDashboard />,
      },
      {
        path: paths[Page.NCIRCC_MESSAGE],
        component: <NCIRCCDashboard />,
      },
      {
        path: paths[Page.NCIRCC_API],
        component: <NCIRCCDashboard />,
      },
      {
        path: paths[Page.NCIRCC_BULLETIN],
        component: <NCIRCCDashboard />,
      },
      {
        path: paths[Page.USER_PROFILE],
        component: <ProfilePage />,
      },
      {
        path: paths[Page.USER_GROUPS],
        component: <ProfilePage />,
      },
      {
        path: paths[Page.SETTINGS_TLS],
        component: <SettingsDashboard />,
      },
      {
        path: paths[Page.SETTINGS_AUTH],
        component: <SettingsDashboard />,
      },
      {
        path: paths[Page.LICENSE_CURRENT],
        component: <LicensePage />,
      },
      {
        path: paths[Page.LICENSE_ACTIVATION],
        component: <LicenseActivationPage />,
      },
      // Для всех остальных роутов редиректить на начальную страниц
      {
        path: '*',
        component: <Navigate to={paths[Page.HOME]} replace />,
      },
    ];
  } else if (isLicenseActivated === false) {
    return [
      {
        path: paths[Page.LICENSE_ACTIVATION],
        component: <LicenseActivationPage />,
      },
      {
        path: '*',
        component: <Navigate to={paths[Page.LICENSE_ACTIVATION]} replace />,
      },
    ];
  } else {
    return [];
  }
}
