import scopes, { getScopes } from '@utils/scopes';
import { USER_SCOPES } from '@constants/entities/Scope';

import interagencyRoute from './interagency';
import subpoenasRoute from './subpoenas';
import baselineDataRoute from './baseline-data';
import conversionRoute from './conversion';
import recordsRoute from './records';
import adminRoute from './admin';
import reportsRoute from './reports';
import approvalRoute from './approval';

import { expansionMenuItem, disabledMenuItem } from './utils';
import { lazyLoadWatcher } from '../utils/mfe-loader';

const routes = [
  {
    name: 'start',
    path: 'start',
    components: {
      default: () => import('@/recruits/components/start/index.vue'),
    },
    meta: {
      label: 'Единый Реестр Воинского Учёта',
    },
  },
  interagencyRoute({
    path: '/interagency',
    label: 'Внешний обмен',
    icon: 'pgs-interagency',
    order: 10,
  }),
  subpoenasRoute({
    path: '/subpoenas',
    label: 'Реестр повесток',
    icon: 'pgs-document',
    order: 20,
  }),
  baselineDataRoute({
    path: '/baseline-data',
    label: 'Эталонные данные',
    icon: 'pgs-people',
    order: 30,
  }),
  conversionRoute({
    path: '/conversion',
    icon: 'pgs-group',
    label: 'Конвертация',
    order: 35,
  }),
  recordsRoute({
    path: '/records',
    label: 'Ведение учёта',
    icon: 'pgs-report',
    order: 40,
  }),
  approvalRoute({
    path: '/approval',
    icon: 'pgs-sign-2',
    label: 'Пакетное подписание',
    order: 45,
  }),
  // conscriptionRoute({
  //   path: '/conscription',
  //   icon: 'pgs-soldier',
  //   label: 'Призыв на военную службу',
  //   order: 45,
  //   scopes: scopes.conscription,
  // }),
  disabledMenuItem({
    path: '/control',
    label: 'Управление и мониторинг',
    icon: 'pgs-process-registry',
    scopes: getScopes([
      USER_SCOPES.GOMU_SPECIALIST,
      USER_SCOPES.MILITARY_COMMISSARIAT_ADMINISTRATOR,
      USER_SCOPES.SYSTEM_ADMINISTRATOR,
    ]),
    order: 50,
  }),
  disabledMenuItem({
    path: '/analytics',
    label: 'Аналитическая подсистема',
    icon: 'pgs-analytics',
    scopes: getScopes([
      USER_SCOPES.GOMU_SPECIALIST,
      USER_SCOPES.MILITARY_COMMISSARIAT_ADMINISTRATOR,
      USER_SCOPES.SYSTEM_ADMINISTRATOR,
    ]),
    order: 60,
  }),
  expansionMenuItem({
    path: '/dataquality',
    label: 'Контроль качества данных',
    icon: 'pgs-double-check',
    order: 70,
    children: [
      {
        component: () => import('@/recruits/layouts/basic-list-layout.vue'),
        path: '',
        children: [
          {
            name: 'incidents-journal',
            component: () =>
              import('@/recruits/components/dataquality/incidents-journal'),
            path: 'incidents-journal',
            // Сусин сказал сделать так
            meta: {
              scopes: getScopes([
                USER_SCOPES.MILITARY_COMMISSAR,
                USER_SCOPES.MILITARY_RECRUIT_SPECIALIST,
                USER_SCOPES.GOMU_SPECIALIST,
                USER_SCOPES.GOMU_OBSERVER,
                USER_SCOPES.SYSTEM_ADMINISTRATOR,
              ]),
              label: 'Журнал инцидентов',
              place: 'drawer',
              storeCountGetters: 'menuCounters/activeIncidentsCounter',
            },
          },
          {
            name: 'incidents-archive',
            component: () =>
              import('@/recruits/components/dataquality/incidents-archive'),
            path: 'incidents-archive',
            // Сусин сказал сделать так
            meta: {
              scopes: getScopes([
                USER_SCOPES.MILITARY_COMMISSAR,
                USER_SCOPES.MILITARY_RECRUIT_SPECIALIST,
                USER_SCOPES.GOMU_SPECIALIST,
                USER_SCOPES.GOMU_OBSERVER,
                USER_SCOPES.SYSTEM_ADMINISTRATOR,
              ]),
              label: 'Архив инцидентов',
              place: 'drawer',
              storeCountGetters: 'menuCounters/archiveIncidentsCounter',
            },
          },
        ],
      },
      {
        component: () => import('@/recruits/layouts/tabbed-card-layout.vue'),
        path: 'incident/:id',
        scopes: scopes.dataquality,
        meta: {
          scopes: getScopes([
            USER_SCOPES.MILITARY_COMMISSAR,
            USER_SCOPES.MILITARY_RECRUIT_SPECIALIST,
            USER_SCOPES.GOMU_SPECIALIST,
            USER_SCOPES.GOMU_OBSERVER,
            USER_SCOPES.SYSTEM_ADMINISTRATOR,
          ]),
          tabs: [
            {
              name: 'Информация',
              path: 'incident-main',
            },
            {
              name: 'История',
              path: 'incident-history',
            },
          ],
        },
        children: [
          {
            name: 'incident-main',
            path: 'main',
            components: {
              masthead: () =>
                import('@/recruits/components/dataquality/incident/masthead'),
              default: () =>
                import('@/recruits/components/dataquality/incident/main'),
            },
          },
          {
            name: 'incident-history',
            path: 'history',
            components: {
              masthead: () =>
                import('@/recruits/components/dataquality/incident/masthead'),
              default: () =>
                import('@/recruits/components/dataquality/incident/history'),
            },
          },
        ],
      },
    ],
  }),
  disabledMenuItem({
    path: '/nsi',
    label: 'Подсистема НСИ',
    icon: 'pgs-database',
    order: 80,
    scopes: getScopes([
      USER_SCOPES.GOMU_SPECIALIST,
      USER_SCOPES.MILITARY_COMMISSARIAT_ADMINISTRATOR,
      USER_SCOPES.SYSTEM_ADMINISTRATOR,
    ]),
  }),
  adminRoute({
    path: '/admin',
    label: 'Администрирование',
    icon: 'pgs-admin',
    order: 90,
  }),
  disabledMenuItem({
    path: '/archive',
    label: 'Архив',
    icon: 'pgs-archive',
    order: 100,
    scopes: getScopes([
      USER_SCOPES.GOMU_SPECIALIST,
      USER_SCOPES.SYSTEM_ADMINISTRATOR,
    ]),
  }),
  // reportsOldRoute(),
  // TODO: заменить старые /reports на новые
  reportsRoute({
    path: '/reports',
    icon: 'pgs-statements',
    label: 'Отчеты',
    order: 110,
    scopes: getScopes([
      USER_SCOPES.MILITARY_COMMISSAR,
      USER_SCOPES.MILITARY_RECRUIT_SPECIALIST,
      USER_SCOPES.MILITARY_DISTRICT_OBSERVER,
      USER_SCOPES.GOMU_SPECIALIST,
      USER_SCOPES.GOMU_OBSERVER,
      USER_SCOPES.SYSTEM_ADMINISTRATOR,
    ]),
  }),
  disabledMenuItem({
    path: '/internal',
    label: 'Служебное',
    icon: 'pgs-app',
    order: 120,
    scopes: getScopes([
      USER_SCOPES.GOMU_SPECIALIST,
      USER_SCOPES.SYSTEM_ADMINISTRATOR,
    ]),
  }),
  {
    name: 'profile', // Профиль
    component: () => import('@/recruits/components/profile/index.vue'),
    path: 'profile',
    meta: {
      // Флаг, который позволяет сделать редирект на степпер, если придёт соответствующий пуш
      hasRedirectToStepper: true,
    },
  },
];

export default routes;
