import { jsx as o, jsxs as c, Fragment as k } from "react/jsx-runtime";
import { useRef as C, useState as x, useLayoutEffect as D, useEffect as G, Children as w, isValidElement as N, Fragment as P } from "react";
import I from "../../hooks/useResizeObserver.js";
import K from "../../hooks/useMergeRefs.js";
import m from "../../utils/classNames.js";
import U from "../button/ToggleButton.js";
import V from "../collapse/Collapse.js";
import $ from "../card/Card.js";
import q from "./TableSearch.js";
import J from "./TableToolbarColumn.js";
const Q = 544, X = (r) => N(r) && r.type === J, B = (r) => {
  const e = [];
  for (const l of w.toArray(r)) {
    if (N(l) && l.type === P) {
      const t = B(l.props.children);
      if (!t)
        return null;
      e.push(...t);
      continue;
    }
    if (!X(l))
      return null;
    e.push(l);
  }
  return e;
}, F = (r, e) => w.toArray(r).some((l) => N(l) ? l.type === e ? !0 : F(l.props.children, e) : !1), v = (r) => {
  if (!r)
    return !1;
  const e = Array.from(r.children);
  if (e.length < 2)
    return !1;
  const l = (e[0]?.offsetTop ?? 0) + (e[0]?.offsetHeight ?? 0);
  return e.some((t) => t.offsetTop + t.offsetHeight !== l);
}, ie = (r) => {
  const {
    className: e,
    collapseCardClassName: l,
    children: t,
    responsiveCollapseBreakpoint: H = Q,
    disableResponsiveCollapse: _ = !1
  } = r, R = C(null), T = C(null), y = C(null), [M, S] = x(!1), [f, A] = x(!1), [W, , { inlineSize: z }] = I(), [p, , { inlineSize: j }] = I(), L = K(R, W), i = !_ && z !== void 0 && z <= H, u = B(t), s = (u ?? []).filter((a) => a.props.horizontalAlign !== "right"), n = (u ?? []).filter((a) => a.props.horizontalAlign === "right"), d = n.findIndex(
    (a) => F(a.props.children, q)
  ), h = d >= 0 ? n[d] : void 0, E = h ? n.filter((a, g) => g !== d) : n, b = i && E.length > 0, O = b && /* @__PURE__ */ o("div", { className: "table-toolbar-mobile-toggle", children: /* @__PURE__ */ o(
    U,
    {
      active: f,
      "aria-label": f ? "Hide toolbar filters" : "Show toolbar filters",
      bsStyle: "default",
      iconName: "rioglyph-option-horizontal",
      iconOnly: !0,
      onClick: A
    }
  ) });
  return D(() => {
    if (i) {
      S(!1);
      return;
    }
    const a = R.current;
    a?.classList.add("table-toolbar-measuring");
    const g = v(p.current) || v(T.current) || v(y.current);
    a?.classList.remove("table-toolbar-measuring"), S(g);
  }, [t, i, s.length, n.length, j]), G(() => {
    (!i || !b) && A(!1);
  }, [b, i]), u?.length ? i ? /* @__PURE__ */ o("div", { className: m("table-toolbar", "table-toolbar-mobile", e), ref: L, children: /* @__PURE__ */ c("div", { className: "table-toolbar-container table-toolbar-container-mobile", ref: p, children: [
    h ? /* @__PURE__ */ c(k, { children: [
      s.length > 0 && /* @__PURE__ */ o("div", { className: "table-toolbar-mobile-primary", children: /* @__PURE__ */ o("div", { className: "table-toolbar-group-left table-toolbar-group-left-mobile", children: s }) }),
      /* @__PURE__ */ c("div", { className: "table-toolbar-mobile-search-row", children: [
        /* @__PURE__ */ o("div", { className: "table-toolbar-mobile-search", children: h }),
        O
      ] })
    ] }) : /* @__PURE__ */ c("div", { className: "table-toolbar-mobile-primary", children: [
      s.length > 0 && /* @__PURE__ */ o("div", { className: "table-toolbar-group-left table-toolbar-group-left-mobile", children: s }),
      O
    ] }),
    b && /* @__PURE__ */ o(V, { open: f, timeout: 220, children: /* @__PURE__ */ o($, { className: m("table-toolbar-mobile-collapse-card", l), children: /* @__PURE__ */ o("div", { className: "table-toolbar-mobile-collapse", children: E }) }) })
  ] }) }) : /* @__PURE__ */ o(
    "div",
    {
      className: m("table-toolbar", M && "table-toolbar-has-wrap", e),
      ref: L,
      children: /* @__PURE__ */ c("div", { className: "table-toolbar-container", ref: p, children: [
        s.length > 0 && /* @__PURE__ */ o("div", { className: "table-toolbar-group-left", ref: T, children: s }),
        n.length > 0 && /* @__PURE__ */ o("div", { className: "table-toolbar-group-right", ref: y, children: n })
      ] })
    }
  ) : /* @__PURE__ */ o("div", { className: m("table-toolbar", e), children: t });
};
export {
  J as TableToolbarColumn,
  ie as default
};
//# sourceMappingURL=TableToolbar.js.map
