"use client";

import Breadcrumbs from "@mui/material/Breadcrumbs";
import Typography from "@mui/material/Typography";
import Link from "next/link";
import MUILink from "@mui/material/Link";
import { usePathname } from "next/navigation";
import { useTranslation } from "react-i18next";

const pathToLabelMap: { [path: string]: string } = {
  "": "Overview",
  "/projects": "Projects",
  "/projects/create": "Create Project",
  "/tasks": "Task Template",
  "/tasks/create": "Create Task Template",
  "/settings/qcItem": "Qc Item",
  "/settings/rss": "Demand Forecast Setting",
  "/scheduling/rough": "Demand Forecast",
  "/scheduling/rough/edit": "FG & Material Demand Forecast Detail",
  "/scheduling/detailed": "Detail Scheduling",
  "/scheduling/detailed/edit": "FG Production Schedule",
  "/inventory": "Inventory",
  "/settings/importTesting": "Import Testing",
  "/do": "Delivery Order",
  "/pickOrder": "Pick Order",
  "/po": "Purchase Order",
  "/dashboard": "dashboard",
  "/jo": "Job Order",
  "/jo/edit": "Edit Job Order",
};

const Breadcrumb = () => {
  const pathname = usePathname();
  const segments = pathname.split("/");
  const { t } = useTranslation("common");

  return (
    <Breadcrumbs>
      {segments.map((segment, index) => {
        const href = segments.slice(0, index + 1).join("/");
        const label = pathToLabelMap[href] || segment;

        if (index === segments.length - 1) {
          return (
            <Typography key={index} color="text.primary">
              {t(label)}
            </Typography>
          );
        } else {
          return (
            <MUILink
              underline="hover"
              color="inherit"
              key={index}
              component={Link}
              href={href || "/"}
            >
              {t(label)}
            </MUILink>
          );
        }
      })}
    </Breadcrumbs>
  );
};

export default Breadcrumb;
