import { TCrudRoute, TMenuItem } from "./types/App";
import { FaHome, FaKey, FaMoneyBill, FaSellcast, FaUserGraduate } from "react-icons/fa";
import { LuPackage } from "react-icons/lu";
import React from "react";
const Dummy = React.lazy(() => import("./Pages/Home/Dummy"));

const Subject = React.lazy(() => import("./Pages/subject/Table/Page"));

const Tags = React.lazy(() => import("./Pages/Tags/Page"));
const Grade = React.lazy(() => import("./Pages/Grade/Page"));
const Package = React.lazy(() => import("./Pages/Package/Page"));
const Curriculum = React.lazy(() => import("./Pages/Curriculum/Page"));
const PackageItemPage = React.lazy(() => import("./Pages/Package/PackageItem/Page"));
const ReSeller = React.lazy(() => import("./Pages/ReSeller/Page"));
const StudentPackage = React.lazy(() => import("./Pages/studentPackage/Page"));
const Student = React.lazy(() => import("./Pages/Student/Page"));

const Unit = React.lazy(() => import("./Pages/Unit/Page"));
const Lesson = React.lazy(() => import("./Pages/lesson/Page"));
const Question = React.lazy(() => import("./Pages/question/Page"));
const AddQuestionPage = React.lazy(() => import("./Pages/question/AddPage"));
const EditQuestionPage = React.lazy(() => import("./Pages/question/EditPage"));
const AddPackagePage = React.lazy(() => import("./Pages/Package/Model/AddModel"));
const EditPackagePage = React.lazy(() => import("./Pages/Package/Model/EditModel"));


const AddPackageItemPage = React.lazy(() => import("./Pages/Package/PackageItem/Model/AddModel"));
const EditPackageItemPage = React.lazy(() => import("./Pages/Package/PackageItem/Model/EditModel"));

import { hasAbility } from "./utils/hasAbility";
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "./enums/abilities";
import { ParamsEnum } from "./enums/params";
import { BsPeople } from "react-icons/bs";

export const menuItems: TMenuItem[] = [
  {
    header: "page_header.dashboard",
    element: <Dummy />,
    icon: <FaHome />,
    text: "sidebar.dashboard",
    path: "/",
    abilities: ABILITIES_ENUM?.PASS,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
    
  },
  {
    header: "page_header.grade",
    element: <Grade />,
    icon: <FaUserGraduate />,
    text: "sidebar.grade",
    path: `/${ABILITIES_ENUM?.GRADE}`,
    abilities: ABILITIES_ENUM?.GRADE,
    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: <FaKey />,
    text: "sidebar.tags",
    path: `/${ABILITIES_ENUM?.TAG}`,
    abilities: ABILITIES_ENUM?.TAG,
    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.student",
    element: <Student />,
    icon: <FaSellcast />,
    text: "sidebar.student",
    path: `/${ABILITIES_ENUM?.STUDENT}`,
    abilities: ABILITIES_ENUM?.STUDENT,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 0,
  },
  // {
  //   header: "page_header.studentPackage",
  //   element: <StudentPackage />,
  //   icon: <BsPeople />,
  //   text: "sidebar.studentPackage",
  //   path: `/${ABILITIES_ENUM?.STUDENT_PACKAGE}`,
  //   abilities: ABILITIES_ENUM?.STUDENT_PACKAGE,
  //   abilities_value: ABILITIES_VALUES_ENUM.INDEX,
  //   prevPath: 0,
  // },
];

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

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

  {
    header: "page_header.lesson_details",
    element: <Question />,
    path: `/${ABILITIES_ENUM?.GRADE}/:${ParamsEnum?.GRADE_ID}/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.CURRICULUM}/:${ParamsEnum?.CURRICULUM_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?.CURRICULUM}/:${ParamsEnum?.CURRICULUM_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?.CURRICULUM}/:${ParamsEnum?.CURRICULUM_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_package",
    element: <AddPackagePage />,
    path: `/${ABILITIES_ENUM?.Package}/add`,
    abilities: ABILITIES_ENUM?.Package,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 1,
  },
  {
    header: "page_header.edit_package",
    element: <EditPackagePage />,
    path: `/${ABILITIES_ENUM?.Package}/:${ParamsEnum?.PACKAGE_ID}`,
    abilities: ABILITIES_ENUM?.Package,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 1,
  },


  {
    header: "page_header.package_item",
    element: <PackageItemPage />,
    path: `/${ABILITIES_ENUM?.Package}/:${ParamsEnum?.PACKAGE_ID}/${ABILITIES_ENUM?.PACKAGE_ITEM}`,
    abilities: ABILITIES_ENUM?.PACKAGE_ITEM,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 1,
  },
 
  {
    header: "page_header.add_package_item",
    element: <AddPackageItemPage />,
    path: `/${ABILITIES_ENUM?.Package}/:${ParamsEnum?.PACKAGE_ID}/${ABILITIES_ENUM?.PACKAGE_ITEM}/add`,
    abilities: ABILITIES_ENUM?.PACKAGE_ITEM,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 1,
  },
  {
    header: "page_header.edit_package_item",
    element: <EditPackageItemPage />,
    path: `/${ABILITIES_ENUM?.Package}/:${ParamsEnum?.PACKAGE_ID}/${ABILITIES_ENUM?.PACKAGE_ITEM}/:${ParamsEnum?.PACKAGE_ITEM_ID}`,
    abilities: ABILITIES_ENUM?.PACKAGE_ITEM,
    abilities_value: ABILITIES_VALUES_ENUM.INDEX,
    prevPath: 1,
  },

];

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,
}));
