import { j as a } from "../../_virtual/jsx-runtime.js";
import s from "react";
import { getId as b } from "../../utils/index.js";
import { BreadcrumbWrapper as c, BreadcrumbItem as u, BreadcrumbChevron as g, BreadcrumbCurrentPage as h, BreadcrumbBackChevron as o } from "./styles.js";
function j(t) {
  const n = b(t["data-testid"]);
  if (t.breadcrumbs.length === 0)
    throw new Error("Breadcrumbs need at least one item to render.");
  function l(r) {
    return t.currentPage ? !0 : r + 1 < t.breadcrumbs.length;
  }
  function m() {
    const { length: r } = t.breadcrumbs;
    return t.breadcrumbs[r - 1];
  }
  switch (t.variant) {
    case "back":
      let r = function(e) {
        e.stopPropagation(), d && d.onClick && d.onClick(e);
      };
      const d = m();
      return /* @__PURE__ */ a.jsxs(
        c,
        {
          onClick: r,
          scrim: t.scrim,
          variant: "back",
          "data-testid": t["data-testid"],
          "data-trackid": t["data-trackid"],
          "aria-label": "breadcrumbs",
          children: [
            /* @__PURE__ */ a.jsx(
              o,
              {
                role: "img",
                "data-testid": n("back-chevron")
              }
            ),
            /* @__PURE__ */ a.jsx(
              u,
              {
                onClick: r,
                "data-testid": n("back-button"),
                children: d.label
              }
            )
          ]
        }
      );
    case "default":
    default:
      return /* @__PURE__ */ a.jsxs(
        c,
        {
          scrim: t.scrim,
          variant: "default",
          "data-testid": t["data-testid"],
          "data-trackid": t["data-trackid"],
          "aria-label": "breadcrumbs",
          children: [
            t.breadcrumbs.map((e, i) => /* @__PURE__ */ a.jsxs(s.Fragment, { children: [
              /* @__PURE__ */ a.jsx(
                u,
                {
                  target: e.href && t.target ? t.target : void 0,
                  as: e.href ? "a" : "button",
                  href: e.href,
                  onClick: e.href ? void 0 : e.onClick,
                  "data-testid": n(`item-${i}`),
                  children: e.label
                }
              ),
              l(i) && /* @__PURE__ */ a.jsx(
                g,
                {
                  role: "img",
                  "data-testid": n(`chevron-${i}`)
                }
              )
            ] }, `bc-${i}-${e.label}`)),
            t.currentPage && /* @__PURE__ */ a.jsx(
              h,
              {
                target: t.currentPageLink && t.target ? t.target : void 0,
                "aria-current": "page",
                "data-testid": n("current-page"),
                as: t.currentPageLink ? "a" : void 0,
                href: t.currentPageLink,
                children: t.currentPage
              }
            )
          ]
        }
      );
  }
}
export {
  j as Breadcrumb
};
