import { Menu } from 'antd';
import { NavLink } from 'react-router-dom';
import { useMainMenuMessages } from './i18n';
import { getItem, useCurrentMainMenuActiveKey } from './helpers';
import { CategoryPath, PagePath, Page, paths } from 'pages/AppRoutes/constants';
import styles from './Menu.module.scss';

import type { MenuProps } from 'antd/es/menu';
type MenuItem = Required<MenuProps>['items'][number];

// TODO: у нас есть константы URL'ов страниц, но здесь они не используются
export const MainMenu = (): JSX.Element => {
  const { assets, journals, settings, ncircc } = useMainMenuMessages();

  const items: MenuItem[] = [
    //  Устройства
    getItem(assets.title, 'assets', true, false, [
      getItem(
        <NavLink to={CategoryPath.ASSETS}>{assets.assets_table}</NavLink>,
        CategoryPath.ASSETS,
        false,
      ),
      getItem(
        <NavLink to={CategoryPath.SECURITY_SYSTEMS}>{assets.security}</NavLink>,
        CategoryPath.SECURITY_SYSTEMS,
        false,
      ),
    ]),

    //  Журналы
    getItem(journals.title, 'journals', true, false, [
      getItem(
        <NavLink to={CategoryPath.INCIDENTS}>{journals.incidents}</NavLink>,
        CategoryPath.INCIDENTS,
        false,
      ),
      getItem(
        <NavLink to={CategoryPath.EVENTS}>{journals.events}</NavLink>,
        CategoryPath.EVENTS,
        false,
      ),
      getItem(
        <NavLink to={CategoryPath.CORRELATION_RULES}>
          {journals.correlations}
        </NavLink>,
        CategoryPath.CORRELATION_RULES,
        false,
      ),
    ]),

    //  Настройки
    getItem(settings.title, 'settings', true, false, [
      getItem(
        <NavLink to={`${CategoryPath.SETTINGS}/${PagePath.TLS_CERTIFICATE}`}>
          {settings.system_settings.title}
        </NavLink>,
        `${CategoryPath.SETTINGS}/${PagePath.TLS_CERTIFICATE}`,
        false,
      ),

      // Лицензии
      getItem(settings.license.title, 'settingsLicense', false, false, [
        getItem(
          <NavLink to={paths[Page.LICENSE_CURRENT]}>
            {settings.license.current}
          </NavLink>,
          paths[Page.LICENSE_CURRENT],
          false,
        ),
        getItem(
          <NavLink to={paths[Page.LICENSE_ACTIVATION]}>
            {settings.license.activation}
          </NavLink>,
          paths[Page.LICENSE_ACTIVATION],
          false,
        ),
      ]),

      //  Журнал настроек
      getItem(settings.journals.title, 'settingsJournals', false, false, [
        getItem(
          <NavLink to={CategoryPath.ROTATION_INCIDENTS}>
            {settings.journals.rotations}
          </NavLink>,

          CategoryPath.ROTATION_INCIDENTS,
          false,
        ),
        // TODO: раскомментировать после релиза
        // getItem(
        //   <NavLink to="">{settings.journals.exports}</NavLink>,
        //   '/export',
        //   false,
        //   true,
        // ),
        getItem(
          <NavLink to={CategoryPath.STORAGE}>
            {settings.journals.storage}
          </NavLink>,
          CategoryPath.STORAGE,
          false,
        ),
      ]),
    ]),

    // ГОССОПКА
    getItem(
      <NavLink to={`${PagePath.ORGANIZATION_CARD}`}>{ncircc.title}</NavLink>,
      CategoryPath.NCIRCC,
      false,
    ),
  ];

  return (
    <Menu
      className={styles['menu']}
      defaultSelectedKeys={useCurrentMainMenuActiveKey()}
      mode="horizontal"
      items={items}
    />
  );
};
