import { TCrudRoute, TMenuItem } from "./types/App";
import { FaHome, FaMoneyBill, FaSellcast } from "react-icons/fa";
import React from "react";

const Dummy = React.lazy(() => import("./Pages/Home/Dummy"));

const Grade = React.lazy(() => import("./Pages/Admin/Grade/Page"));
const Curriculum = React.lazy(() => import("./Pages/Admin/Curriculum/Page"));
const Subject = React.lazy(() => import("./Pages/Admin/subject/Table/Page"));
const Tags = React.lazy(() => import("./Pages/Admin/Tags/Page"));
const Unit = React.lazy(() => import("./Pages/Admin/Unit/Page"));
const Lesson = React.lazy(() => import("./Pages/Admin/lesson/Page"));

const Question = React.lazy(() => import("./Pages/Admin/question/Page"));
const AddQuestionPage = React.lazy(
  () => import("./Pages/Admin/question/AddPage"),
);
const EditQuestionPage = React.lazy(
  () => import("./Pages/Admin/question/EditPage"),
);

const Report = React.lazy(() => import("./Pages/Admin/Report/Page"));
const Student = React.lazy(() => import("./Pages/Admin/Student/Page"));
const ReSeller = React.lazy(() => import("./Pages/Admin/Reseller/Page"));
const AddReSeller = React.lazy(() => import("./Pages/Admin/Reseller/Add/Page"));
const EditReSeller = React.lazy(() => import("./Pages/Admin/Reseller/Edit/Page"));

const User = React.lazy(() => import("./Pages/Admin/User/Page"));
const Param = React.lazy(() => import("./Pages/Admin/Param/Page"));

/// RESELLER ///
const Student_Package = React.lazy(() => import("./Pages/ReSeller/StudentPackage/Page"));


import { hasAbility } from "./utils/hasAbility";
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "./enums/abilities";
import { ParamsEnum } from "./enums/params";
import { TbCategory } from "react-icons/tb";
import { UserTypeEnum } from "./enums/UserType";

export const menuItems: TMenuItem[] = [
  {
    header: "page_header.dashboard",
    element: <Dummy />,
    icon: <TbCategory />,
    text: "sidebar.dashboard",
    path: "/",
    abilities: ABILITIES_ENUM?.PASS,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
    type:UserTypeEnum?.PASS
  },
  {
    header: "page_header.grade",
    element: <Grade />,
    icon: <FaMoneyBill />,
    text: "sidebar.grade",
    path: `/${ABILITIES_ENUM?.GRADE}`,
    abilities: ABILITIES_ENUM?.GRADE,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
  },
  {
    header: "page_header.tags",
    element: <Tags />,
    icon: <FaMoneyBill />,
    text: "sidebar.tags",
    path: `/${ABILITIES_ENUM?.TAG}`,
    abilities: ABILITIES_ENUM?.TAG,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
  },
  {
    header: "page_header.tags",
    element: <Report />,
    icon: <FaMoneyBill />,
    text: "sidebar.report",
    path: `/${ABILITIES_ENUM?.Report}`,
    abilities: ABILITIES_ENUM?.Report,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
  },
  {
    header: "page_header.student",
    element: <Student />,
    icon: <FaMoneyBill />,
    text: "sidebar.student",
    path: `/${ABILITIES_ENUM?.STUDENT}`,
    abilities: ABILITIES_ENUM?.STUDENT,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
   
  },
  {
    header: "page_header.reSeller",
    element: <ReSeller />,
    icon: <FaSellcast />,
    text: "sidebar.reseller",
    path: `/${ABILITIES_ENUM?.RE_SELLER}`,
    abilities: ABILITIES_ENUM?.RE_SELLER,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
  },
  {
    header: "page_header.user",
    element: <User />,
    icon: <FaSellcast />,
    text: "sidebar.user",
    path: `/${ABILITIES_ENUM?.USER}`,
    abilities: ABILITIES_ENUM?.USER,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
  },
  {
    header: "page_header.param",
    element: <Param />,
    icon: <FaSellcast />,
    text: "sidebar.param",
    path: `/${ABILITIES_ENUM?.PARAM}`,
    abilities: ABILITIES_ENUM?.PARAM,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
  },


  /// RESELLER /////

  {
    header: "page_header.student_package",
    element: <Student_Package />,
    icon: <FaSellcast />,
    text: "sidebar.student_package",
    path: `/${ABILITIES_ENUM?.Student_Package}`,
    abilities: ABILITIES_ENUM?.Student_Package,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
    type:UserTypeEnum.RE_SELLER
  },




  // {
  //   header: "page_header.tags",
  //   element: <Tags />,
  //   icon: <FaMoneyBill />,
  //   text: "sidebar.tags",
  //   path: `/${ABILITIES_ENUM?.TAG}`,
  //   abilities: ABILITIES_ENUM?.TAG,
  //   abilities_value: ABILITIES_VALUES_ENUM.INDEX,
  //   prevPath: 0,
  // },
  // {
  //   header: "page_header.subject",
  //   element: <Subject />,
  //   icon: <FaMoneyBill />,
  //   text: "sidebar.subject",
  //   path: `/${ABILITIES_ENUM?.SUBJECT}`,
  //   abilities: ABILITIES_ENUM?.SUBJECT,
  //   abilities_value: ABILITIES_VALUES_ENUM.INDEX,
  //   prevPath: 0,
  // },

  // {
  //   header: "page_header.package",
  //   element: <Package />,
  //   icon: <LuPackage />,
  //   text: "sidebar.package",
  //   path: `/${ABILITIES_ENUM?.Package}`,
  //   abilities: ABILITIES_ENUM?.Package,
  //   abilities_value: ABILITIES_VALUES_ENUM.INDEX,
  //   prevPath: 0,
  // },
  // {
  //   header: "page_header.subject",
  //   element: <Subject />,
  //   icon: <FaMoneyBill />,
  //   text: "sidebar.subject",
  //   path: `/${ABILITIES_ENUM?.SUBJECT}`,
  //   abilities: ABILITIES_ENUM?.SUBJECT,
  //   abilities_value: ABILITIES_VALUES_ENUM.INDEX,
  //   prevPath: 0,
  // },
  // {
  //   header: "page_header.tags",
  //   element: <Tags />,
  //   icon: <FaMoneyBill />,
  //   text: "sidebar.tags",
  //   path: `/${ABILITIES_ENUM?.TAG}`,
  //   abilities: ABILITIES_ENUM?.TAG,
  //   abilities_value: ABILITIES_VALUES_ENUM.INDEX,
  //   prevPath: 0,
  // },
];

export const CrudRoute: TCrudRoute[] = [
  {
    header: "page_header.Subject",
    element: <Subject />,
    path: `/${ABILITIES_ENUM?.GRADE}/:${ParamsEnum?.GRADE_ID}`,
    abilities: ABILITIES_ENUM?.SUBJECT,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 1,
  },

  {
    header: "page_header.unit",
    element: <Unit />,
    path: `/${ABILITIES_ENUM?.GRADE}/:${ParamsEnum?.GRADE_ID}/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}`,
    abilities: ABILITIES_ENUM?.UNIT,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 2,
  },
  {
    header: "page_header.lesson",
    element: <Lesson />,
    path: `/${ABILITIES_ENUM?.GRADE}/:${ParamsEnum?.GRADE_ID}/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}`,
    abilities: ABILITIES_ENUM?.LESSON,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 2,
  },

  {
    header: "page_header.question",
    element: <Question />,
    path: `/${ABILITIES_ENUM?.GRADE}/:${ParamsEnum?.GRADE_ID}/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}`,
    abilities: ABILITIES_ENUM?.QUESTION,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 2,
  },
  {
    header: "page_header.add_Question",
    element: <AddQuestionPage />,
    path: `/${ABILITIES_ENUM?.GRADE}/:${ParamsEnum?.GRADE_ID}/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}/${ABILITIES_ENUM?.QUESTION}/add`,
    abilities: ABILITIES_ENUM?.QUESTION,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 2,
  },
  {
    header: "page_header.edit_Question",
    element: <EditQuestionPage />,
    path: `/${ABILITIES_ENUM?.GRADE}/:${ParamsEnum?.GRADE_ID}/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}/${ABILITIES_ENUM?.QUESTION}/:${ParamsEnum?.QUESTION_ID}`,
    abilities: ABILITIES_ENUM?.QUESTION,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 2,
  },

  {
    header: "page_header.add_reseller",
    element: <AddReSeller />,
    path: `/${ABILITIES_ENUM?.RE_SELLER}/add`,
    abilities: ABILITIES_ENUM?.RE_SELLER,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
  },
  {
    header: "page_header.edit_reseller",
    element: <EditReSeller />,
    path: `/${ABILITIES_ENUM?.RE_SELLER}/:id`,
    abilities: ABILITIES_ENUM?.RE_SELLER,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
  },
];

export const AppRoutes: Record<string, string> = Object.fromEntries(
  menuItems.map((route) => [
    route.path,
    route.header ? route.header : route.text,
  ]),
);

export const CrudRoutes: any = Object.fromEntries(
  CrudRoute.map((route) => [route?.path, route?.header]),
);
export const search_array: { label: string; value: string }[] = menuItems
  ?.filter((item: TMenuItem) => {
    return hasAbility(item.abilities, item.abilities_value);
  })
  .map((item: TMenuItem) => ({
    label: item.header as string,
    value: item.path as string,
  }));

const AllRoute = [...menuItems, ...CrudRoute];

export const PrevRoutes: any = AllRoute.map((route) => ({
  path: route.path,
  prevPath: route.prevPath,
}));
