import {
  SIDEBAR_COLLAPSED_WIDTH,
  SIDEBAR_WIDTH,
} from '@material-hu/components/design-system/Sidebar/constants';

import { SUB_MENU_WIDTH } from 'src/constants/sidebar';
import { SPORTS_POOL_PATHS } from 'src/pages/dashboard/sportsPool/routes';

export const NAVBAR_HEIGHT = SIDEBAR_COLLAPSED_WIDTH;

export const getSidebarStatus = () =>
  JSON.parse(localStorage.getItem('sidebarStatus') || 'false');

export const setSidebarStatus = (value: boolean) =>
  localStorage.setItem('sidebarStatus', JSON.stringify(value));

export const getPaddingDashboardLayout = (
  isSidebarCollapsed: boolean,
  isSubMenuOpened: boolean,
  isGroups: boolean,
  isSidebarDisabled: boolean,
) => {
  if (isSidebarDisabled) return 0;
  if (isSubMenuOpened && isGroups)
    return isSidebarCollapsed
      ? SIDEBAR_COLLAPSED_WIDTH + SUB_MENU_WIDTH
      : SIDEBAR_WIDTH + SUB_MENU_WIDTH;
  if (isSidebarCollapsed) return SIDEBAR_COLLAPSED_WIDTH;

  return SIDEBAR_WIDTH;
};

export const hiddenSidebarPath = (pathname: string) =>
  [
    /\/groups\/\d+\/configuration/,
    /\/groups\/create/,
    /\/feed\/live-stream/,
    /\/feed\/pending-posts/,
    /\/groups\/[0-9]+\/live-stream/,
    /\/performance\/[0-9]+/,
    /\/people-experience\/surveys\/[0-9]+/,
    /\/goals\/new/,
    /\/goals\/[0-9]+/,
    /\/goals\/[0-9]+'\/edit/,
    /\/goals\/team\/[0-9]+/,
    /\/shifts\/repository/,
    /\/courses\/[0-9]+\/lessons\/[0-9]+/,
    /\/courses\/[0-9]+\/sign/,
    /\/courses\/[0-9]+\/completion/,
    /\/sessions\/[0-9]+/,
    /\/paths\/[0-9]+\/completion/,
    /\/events\/new/,
    /\/events\/[0-9]+\/edit/,
    /\/events\/[0-9]+\/live-stream/,
    /\/documents\/pending\/files\/[0-9]+/,
    /\/documents\/[0-9]+\/files\/[0-9]+/,
    /\/requests-banbajio\/loan/,
    /\/requests-banbajio\/advancePayment/,
    /\/requests-banbajio\/mortgageLibrary/,
    /\/employee-lifecycle\/onboardings\/[0-9]+\/steps(?:\/[0-9]+\/tasks(?:\/[0-9]+)?)?$/,
    /\/employee-lifecycle\/form\/[^/]+\/[^/]+(?:\/[^/]+)?(\/(?:results|success))?$/,
    /\/people-experience\/manager\/surveys\/[0-9]+\/results-experimental/,
    /^\/surveys\/[0-9]+/,
    new RegExp(
      `\\/${SPORTS_POOL_PATHS.ROOT}\\/${SPORTS_POOL_PATHS.COMPETITIONS}\\/[0-9]+`,
    ),
  ].some(rgx => pathname.match(rgx));

export const disableSidebarPath = (pathname: string) =>
  [
    /feed\/[0-9]+\/insights/,
    /feed\/pinned-posts/,
    /groups\/[0-9]+\/pinned-posts/,
    /agent-workspace/,
    /service-portal\/service-items/,
    /service-portal\/requests/,
    /groups\/[0-9]+\/post\/[0-9]+\/insights/,
    /communication\/create-post-draft/,
    /communication\/drafts\/[0-9]+/,
    /communication\/drafts\/[0-9]+\/edit/,
    /key-updates/,
    /feed\/[0-9]+\/share/,
    /groups\/[0-9]+\/post\/[0-9]+\/share/,
    /people-experience\/manager\/surveys\/[0-9]+\/results/,
    /time-tracking\/collaborators\/[0-9]+/,
    /service-portal\/approvals/,
    /notifications-config/,
  ].some(rgx => pathname.match(rgx));

export const collapsedSidebarPath = (pathname: string) =>
  [/\/library(\/|$)/].some(rgx => pathname.match(rgx));
