"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";

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": "Rough Schedule Setting",
  "/scheduling/rough": "Rough Scheduling",
  "/scheduling/detail": "Detail Scheduling",
};

const Breadcrumb = () => {
  const pathname = usePathname();
  const segments = pathname.split("/");

  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">
              {label}
            </Typography>
          );
        } else {
          return (
            <MUILink
              underline="hover"
              color="inherit"
              key={index}
              component={Link}
              href={href || "/"}
            >
              {label}
            </MUILink>
          );
        }
      })}
    </Breadcrumbs>
  );
};

export default Breadcrumb;
