import { TFunction } from "i18next";

import { AbilitySiteYell } from "src/site/Site";

import m00 from "src/assets/m00.png";
import m01 from "src/assets/m01.png";
import m10 from "src/assets/m10.png";
import m11 from "src/assets/m11.png";
import m12 from "src/assets/m12.png";
import m14 from "src/assets/m14.png";
import m111 from "src/assets/m111.png";
import m113 from "src/assets/m113.png";
import m20 from "src/assets/m20.png";
import m21 from "src/assets/m21.png";
import m22 from "src/assets/m22.png";
import m23 from "src/assets/m23.png";
import m30 from "src/assets/m30.png";
import m31 from "src/assets/m31.png";
import m32 from "src/assets/m32.png";
import m33 from "src/assets/m33.png";
import m34 from "src/assets/m34.png";
import m40 from "src/assets/m40.png";
import m41 from "src/assets/m41.png";
import m42 from "src/assets/m42.png";
import m43 from "src/assets/m43.png";
import m44 from "src/assets/m44.png";
import m45 from "src/assets/m45.png";
import m47 from "src/assets/m47.png";
import m50 from "src/assets/m50.png";
import m51 from "src/assets/m51.png";
import m53 from "src/assets/m53.png";
import m54 from "src/assets/m54.png";
import m55 from "src/assets/m55.png";
import m60 from "src/assets/m60.png";
import m61 from "src/assets/m61.png";
import m70 from "src/assets/m70.png";
import m74 from "src/assets/m74.png";
import m75 from "src/assets/m75.png";
import m76 from "src/assets/m76.png";
import m77 from "src/assets/m77.png";
import m78 from "src/assets/m78.png";
import m79 from "src/assets/m79.png";
import m80 from "src/assets/m80.png";
import m81 from "src/assets/m81.png";
import m710 from "src/assets/m710.png";
import m711 from "src/assets/m711.png";
import m712 from "src/assets/m712.png";
import m713 from "src/assets/m713.png";
import m714 from "src/assets/m714.png";
import m715 from "src/assets/m715.png";
import m716 from "src/assets/m716.png";
import m120 from "src/assets/m120.png";
import m121 from "src/assets/m121.png";

export const m0 = [m00, m01];
export const m1 = [
  m10,
  m11,
  m12,
  "",
  m14,
  "",
  "",
  "",
  "",
  "",
  "",
  m111,
  "",
  m113,
  "",
];
export const m2 = [m20, m21, m22, m23];
export const m3 = [m30, m31, m32, m33, m34];
export const m4 = [m40, m41, m42, m43, m44, m45, "", m47];
export const m5 = [m50, m51, "", m53, m54, m55];
export const m6 = [m60, m61];
export const m7 = [
  m70,
  "",
  "",
  "",
  m74,
  m75,
  m76,
  m77,
  m78,
  m79,
  m710,
  m711,
  m712,
  m713,
  m714,
  m715,
  m716,
];
export const m8 = [m80, m81];
export const _m12 = [m120, m121];

export const formatText = (value: number) => {
  return Number(value.toFixed(2))
    .toString()
    .replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};

export const getGenreText = (genre: string) =>
  genre.length === 0 || genre.startsWith("#") ? genre : `#${genre}`;

export const getAbilityUpText = (
  t: TFunction,
  { inputMode, ability }: AbilitySiteYell,
) => {
  let inputModeText = "";
  switch (inputMode) {
    case 10:
      inputModeText = "⑤K";
      break;
    case 11:
      inputModeText = "⑦K";
      break;
    case 9:
      inputModeText = "9K";
      break;
  }
  return ability < 0.01
    ? `${inputModeText} < 0.01 Point ↑`
    : `${inputModeText} ${ability.toFixed(2)} Point ↑`;
};

export const toDate = (date: number) => {
  const dateText = new Date(date);
  return `${dateText.toLocaleDateString()} ${dateText.toLocaleTimeString()}`;
};

export const getSiteName = (siteName: string, t: TFunction) => {
  switch (siteName) {
    case "@Comment":
      return t("commentSiteName");
    case "@Default":
      return t("defaultSiteName");
    case "@Platform":
      return t("platformSiteName");
    default:
      return siteName;
  }
};

export const getQuitStatusValue = (
  point: number,
  stand: number,
): {
  quitCss: "S+" | "S" | "A+" | "A" | "B" | "C" | "D";
  quit: string;
} => {
  const quitCss =
    point < 0.8
      ? "D"
      : point < 0.85
        ? "C"
        : point < 0.9
          ? "B"
          : point < 0.95
            ? "A"
            : stand < 900000
              ? "A+"
              : point < 1.0
                ? "S"
                : "S+";

  return {
    quitCss,
    quit: quitCss,
  };
};

export const getDefaultAvatarID = (avatarID: string) =>
  avatarID.substring(avatarID.indexOf("@") + 1);

export const getHitPointsClass = (hitPointsMode: number) => {
  switch (hitPointsMode) {
    case 0:
      return "level2";
    case 2:
      return "level4";
    case 3:
    case 5:
      return "level5";
    case 4:
      return "level1";
    default:
      return "stand";
  }
};
