import {
  isAdminUser,
  isApproveTier,
  isStandardUser,
} from "features/auth/utils";
import { LoginedPaths } from "./types";
import {
  ADMIN_ONLY_TABS,
  HEADER_MENUS,
  TIER1_TO_TIER4_ONLY_TABS,
  INVALID_ACCOUNT_TABS,
} from "./constants";
import { TIERS } from "../auth/constants";

// ログイン後のパスかどうか判定
export const isLoginPaths = (d: string): d is LoginedPaths => {
  // caseに入力補完で取りうるリテラルしか出なくする
  const type = d as LoginedPaths;
  switch (type) {
    case "/account":
    case "/user":
    case "/license":
    case "/dictations":
    case "/workflow":
    case "/partners":
    case "/xxx":
      return true;
    default: {
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      const _: never = type;
      return false;
    }
  }
};
// 権限、階層ごとに表示するヘッダーをわける
export const getFilteredMenus = () => {
  const isAdmin = isAdminUser();
  const isStandard = isStandardUser();
  const isTier5 = isApproveTier([TIERS.TIER5]);
  const tier1ToTier4 = isApproveTier([
    TIERS.TIER1,
    TIERS.TIER2,
    TIERS.TIER3,
    TIERS.TIER4,
  ]);

  if (tier1ToTier4) {
    if (isAdmin) {
      return HEADER_MENUS;
    }
    if (isStandard) {
      return HEADER_MENUS.filter(
        (item) => !ADMIN_ONLY_TABS.includes(item.label)
      );
    }
  }
  if (isTier5) {
    if (isAdmin) {
      return HEADER_MENUS.filter(
        (item) => !TIER1_TO_TIER4_ONLY_TABS.includes(item.label)
      );
    }
    if (isStandard) {
      return HEADER_MENUS.filter(
        (item) => !ADMIN_ONLY_TABS.includes(item.label)
      );
    }
  }
  // admin,standardでなく、第1～5階層でもないアカウントに表示する空のヘッダータブ
  return INVALID_ACCOUNT_TABS;
};
