/**ใช้รวมไฟล์ย่อยๆ ของ api แต่ละไฟล์ */

/** API Metadata */
import testtest from "./api/test/api.test";
import retirementResign from "./api/leave/api.leave";
import placementTransfer from "./api/transfer/api.transfer";
import appeal from "./api/appeal/api.appeal";
import message from "./api/api.message";
import evaluate from "./api/evaluate/api.evaluate";
import support from "./api/support/api.support";
import org from "./api/org/api.org";
import scholarship from "./api/scholarship/api.scholarship";
import kpi from "./api/KPI/api.kpis";
import probation from "./api/probation/api.probation";
import development from "./api/api.development";

/** API reports  */
import reports from "./api/reports/api.report";

const API = {
  ...testtest,
  ...retirementResign,
  ...placementTransfer,
  ...message,
  ...evaluate,
  ...appeal,
  ...support,
  ...org,
  ...scholarship,
  ...kpi,
  ...probation,
  ...development,
  //reports
  ...reports,
};

const path = import.meta.env.VITE_MANUAL_URL ?? "";

/**
 * ไปหน้าคู่มือ
 * @param routeName route name
 * @param type type ขรก/ลูกจ้าง OFFICER PERM
 * @returns
 */
const generatePopupPath = (routeName: any, type: string) => {
  if (routeName.includes("organizationChart")) {
    return `${path}/chapter-1-user${type}-organization-chart`;
  }
  if (routeName.includes("registry") || routeName.includes("request-edit")) {
    return `${path}/chapter-2-user${type}-registry`;
  }
  if (routeName.includes("evaluate")) {
    return `${path}/chapter-3-user-evaluate`;
  }

  if (routeName.includes("leave") || routeName.includes("addAbsence")) {
    return `${path}/chapter-${type ? "3" : "4"}-user${type}-leave`;
  }

  if (routeName.includes("portfolio")) {
    return `${path}/chapter-5-user-portfolio`;
  }
  if (routeName.includes("transfer")) {
    return `${path}/chapter-6-user-transfer`;
  }
  if (routeName.includes("appealComplain")) {
    return `${path}/chapter-${type ? "4" : "7"}-user${type}-appeal-complain`;
  }
  if (routeName.includes("KPI-evaluator")) {
    return `${path}/chapter-9-user-KPI-evaluator`;
  }
  if (routeName.includes("scholarship")) {
    return `${path}/chapter-10-user-scholarship`;
  }
  if (routeName.includes("idp")) {
    return `${path}/chapter-11-user-Individual-development`;
  }
  if (routeName.includes("probation-reportMain")) {
    return `${path}/chapter-14-user-service-testing`;
  }
  if (routeName.includes("Retire")) {
    return `${path}/chapter-${type ? "6" : "12"}-user${type}-retire`;
  } else {
    return manualConfig[routeName as keyof typeof manualConfig];
  }
};

const manualConfig = {
  dashboard: `${path}/chapter-1-user-organization-chart`,
  leave: `${path}/chapter-4-user-leave`,
  organizationChart: `${path}/chapter-1-user-organization-chart`,
  registryMain: `${path}/chapter-2-user-registry`,
  addPortfolio: `${path}/chapter-5-user-portfolio`,
  addTransfer: `${path}/chapter-6-user-transfer`,
  KPIMain: `${path}/chapter-8-user-KPI`,
  KPIAdd: `${path}/chapter-8-user-KPI`,
  KPIEdit: `${path}/chapter-8-user-KPI`,
  KPIMainEvaluator: `${path}/chapter-9-user-KPI-evaluator`,
};

export default {
  API: API,
  generatePopupPath,
};
