import * as p from "react";
import F from "../../../classnames/index.mjs";
import O from "../../../rc-util/es/Children/toArray.mjs";
import G from "../../../rc-util/es/pickAttrs.mjs";
import { cloneElement as H } from "../_util/reactNode.mjs";
import { devUseWarning as J } from "../_util/warning.mjs";
import "../config-provider/index.mjs";
import Q, { InternalBreadcrumbItem as X } from "./BreadcrumbItem.mjs";
import R from "./BreadcrumbSeparator.mjs";
import Y from "./style/index.mjs";
import Z from "./useItemRender.mjs";
import ee from "./useItems.mjs";
import { ConfigContext as re } from "../config-provider/context.mjs";
var te = globalThis && globalThis.__rest || function(r, a) {
  var o = {};
  for (var e in r)
    Object.prototype.hasOwnProperty.call(r, e) && a.indexOf(e) < 0 && (o[e] = r[e]);
  if (r != null && typeof Object.getOwnPropertySymbols == "function")
    for (var n = 0, e = Object.getOwnPropertySymbols(r); n < e.length; n++)
      a.indexOf(e[n]) < 0 && Object.prototype.propertyIsEnumerable.call(r, e[n]) && (o[e[n]] = r[e[n]]);
  return o;
};
const oe = (r, a) => {
  if (a === void 0)
    return a;
  let o = (a || "").replace(/^\//, "");
  return Object.keys(r).forEach((e) => {
    o = o.replace(`:${e}`, r[e]);
  }), o;
}, f = (r) => {
  const {
    prefixCls: a,
    separator: o = "/",
    style: e,
    className: n,
    rootClassName: P,
    routes: b,
    items: E,
    children: d,
    itemRender: S,
    params: v = {}
  } = r, j = te(r, ["prefixCls", "separator", "style", "className", "rootClassName", "routes", "items", "children", "itemRender", "params"]), {
    getPrefixCls: x,
    direction: A,
    breadcrumb: m
  } = p.useContext(re);
  let y;
  const l = x("breadcrumb", a), [k, w, T] = Y(l), i = ee(E, b);
  if (process.env.NODE_ENV !== "production") {
    const s = J("Breadcrumb");
    if (s.deprecated(!b, "routes", "items"), !i || i.length === 0) {
      const c = O(d);
      s.deprecated(c.length === 0, "Breadcrumb.Item and Breadcrumb.Separator", "items"), c.forEach((t) => {
        t && process.env.NODE_ENV !== "production" && s(t.type && (t.type.__ANT_BREADCRUMB_ITEM === !0 || t.type.__ANT_BREADCRUMB_SEPARATOR === !0), "usage", "Only accepts Breadcrumb.Item and Breadcrumb.Separator as it's children");
      });
    }
  }
  const D = Z(l, S);
  if (i && i.length > 0) {
    const s = [], c = E || b;
    y = i.map((t, u) => {
      const {
        path: $,
        key: g,
        type: M,
        menu: B,
        overlay: I,
        onClick: U,
        className: z,
        separator: K,
        dropdownProps: W
      } = t, h = oe(v, $);
      h !== void 0 && s.push(h);
      const _ = g ?? u;
      if (M === "separator")
        return /* @__PURE__ */ p.createElement(R, {
          key: _
        }, K);
      const N = {}, q = u === i.length - 1;
      B ? N.menu = B : I && (N.overlay = I);
      let {
        href: C
      } = t;
      return s.length && h !== void 0 && (C = `#/${s.join("/")}`), /* @__PURE__ */ p.createElement(X, Object.assign({
        key: _
      }, N, G(t, {
        data: !0,
        aria: !0
      }), {
        className: z,
        dropdownProps: W,
        href: C,
        separator: q ? "" : o,
        onClick: U,
        prefixCls: l
      }), D(t, v, c, s, C));
    });
  } else if (d) {
    const s = O(d).length;
    y = O(d).map((c, t) => {
      if (!c)
        return c;
      const u = t === s - 1;
      return H(c, {
        separator: u ? "" : o,
        key: t
      });
    });
  }
  const V = F(l, m == null ? void 0 : m.className, {
    [`${l}-rtl`]: A === "rtl"
  }, n, P, w, T), L = Object.assign(Object.assign({}, m == null ? void 0 : m.style), e);
  return k(/* @__PURE__ */ p.createElement("nav", Object.assign({
    className: V,
    style: L
  }, j), /* @__PURE__ */ p.createElement("ol", null, y)));
};
f.Item = Q;
f.Separator = R;
process.env.NODE_ENV !== "production" && (f.displayName = "Breadcrumb");
const ye = f;
export {
  ye as default
};
