"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";
import Clock from "./Clock";
import { Box, Grid } from "@mui/material";
import { I18nProvider } from "@/i18n";

const pathToLabelMap: { [path: string]: string } = {
  "": "Overview",
  "/home": "User Workspace",
  "/projects": "Projects",
  "/projects/create": "Create Project",
  "/projects/create/sub": "Sub Project",
  "/projects/edit": "Edit Project",
  "/projects/edit/sub": "Sub Project",
  "/tasks": "Task Template",
  "/tasks/create": "Create Task Template",
  "/staffReimbursement": "Staff Reimbursement",
  "/settings/customer": "Client",
  "/settings/customer/create": "Create Client",
  "/settings/customer/edit": "Edit Client",
  "/settings/subsidiary": "Subsidiary",
  "/settings/subsidiary/create": "Create Subsidiary",
  "/settings/subsidiary/edit": "Edit Subsidiary",
  "/settings": "Settings",
  "/company": "Company",
  "/settings/department": "Department",
  "/settings/department/new": "Create Department",
  "/settings/department/edit": "Edit Department",
  "/settings/position": "Position",
  "/settings/position/edit": "Edit Position",
  "/settings/position/new": "Create Position",
  "/settings/company/edit": "Edit Company",
  "/settings/company/create": "Create Company",
  "/settings/salarys": "Salary",
  "/analytics/ProjectCashFlowReport": "Project Cash Flow Report",
  "/settings/holiday": "Holiday",
};

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

  // const { t } = useTranslation("customer");

  return (
    <Box
      display="flex"
      flexDirection={{ xs: "column-reverse", sm: "row"}}
      justifyContent={{ sm: "space-between" }}
    >
      <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}
                {/* {t(label)} */}
              </Typography>
            );
          } else {
            return (
              <MUILink
                underline="hover"
                color="inherit"
                key={index}
                component={Link}
                href={href || "/"}
              >
                {label}
              </MUILink>
            );
          }
        })}
      </Breadcrumbs>
      <Box width={{ xs: "100%", sm: "auto" }} marginBlockEnd={{ xs: 1, sm: 0 }}>
        <Clock variant="body2" />
      </Box>
    </Box>
  );
};

export default Breadcrumb;
