import { jsx as n, jsxs as d } from "react/jsx-runtime";
import l from "react";
import { B as T } from "./button-BEJnxXsL.es.js";
import { I as z } from "./icon-button-CosIm3oY.es.js";
import { M as u } from "./menu-Zlnps1eW.es.js";
import { I as O } from "./icon-DJsVh7VR.es.js";
import { createSlotRecipeContext as j } from "@chakra-ui/react";
import { n as r, u as k } from "./normalize-messages-D5T4I93D.es.js";
import { KeyboardArrowDown as F } from "@commercetools/nimbus-icons";
const { withProvider: G, withContext: m } = /* @__PURE__ */ j({
  key: "splitButton"
}), K = /* @__PURE__ */ G("div", "root"), L = /* @__PURE__ */ m("div", "buttonGroup"), V = /* @__PURE__ */ m("button", "primaryButton"), $ = /* @__PURE__ */ m("button", "dropdownTrigger"), W = { noActionsAvailable: "No actions available" }, q = { noActionsAvailable: "Keine Aktionen verfügbar" }, H = { noActionsAvailable: "No hay acciones disponibles" }, J = { noActionsAvailable: "Aucune action disponible" }, Q = { noActionsAvailable: "Não há ações disponíveis" }, U = {
  en: /* @__PURE__ */ r(W),
  de: /* @__PURE__ */ r(q),
  es: /* @__PURE__ */ r(H),
  "fr-FR": /* @__PURE__ */ r(J),
  "pt-BR": /* @__PURE__ */ r(Q)
}, X = (b) => {
  const S = k(U), {
    size: v = "md",
    variant: f = "solid",
    colorPalette: D,
    isDisabled: h = !1,
    "aria-label": y,
    onAction: a,
    isOpen: C,
    defaultOpen: P,
    onOpenChange: _,
    icon: g
  } = b, A = { size: v, variant: f, colorPalette: D }, B = (t) => {
    if (!l.isValidElement(t) || !t.props) return !1;
    const o = t.props;
    return "id" in o && typeof o.id == "string";
  }, I = (t) => !l.isValidElement(t) || !t.props ? !1 : "children" in t.props, c = b.children, M = (t) => {
    let o = !1;
    return l.Children.forEach(t, (i) => {
      if (!o) {
        if (B(i) && !i.props.isDisabled) {
          o = !0;
          return;
        }
        I(i) && (o = M(i.props.children));
      }
    }), o;
  }, w = () => {
    const t = [], o = (p) => {
      l.Children.forEach(p, (s) => {
        B(s) && t.push({
          content: s.props.children,
          isDisabled: s.props.isDisabled || !1,
          actionId: s.props.id
        }), I(s) && o(s.props.children);
      });
    };
    return o(c), t.find((p) => !p.isDisabled) || t[0] || {
      content: S.format("noActionsAvailable"),
      isDisabled: !0,
      actionId: null
    };
  }, x = M(c), e = w(), R = () => {
    !e.isDisabled && e.actionId && a && a(e.actionId);
  }, E = h || e.isDisabled, N = h || !x;
  return /* @__PURE__ */ n(K, { variant: f, "data-mode": "split", children: /* @__PURE__ */ d(L, { children: [
    /* @__PURE__ */ n(V, { asChild: !0, children: /* @__PURE__ */ d(
      T,
      {
        ...A,
        isDisabled: E,
        onPress: R,
        children: [
          g && /* @__PURE__ */ n(O, { children: g }),
          e.content
        ]
      }
    ) }),
    /* @__PURE__ */ d(
      u.Root,
      {
        trigger: "press",
        isOpen: C,
        defaultOpen: P,
        onOpenChange: _,
        placement: "bottom end",
        selectionMode: "none",
        onAction: a ? (t) => a(String(t)) : void 0,
        children: [
          /* @__PURE__ */ n(u.Trigger, { asChild: !0, children: /* @__PURE__ */ n($, { asChild: !0, children: /* @__PURE__ */ n(
            z,
            {
              ...A,
              "aria-label": y,
              isDisabled: N,
              children: /* @__PURE__ */ n(F, {})
            }
          ) }) }),
          /* @__PURE__ */ n(u.Content, { children: c })
        ]
      }
    )
  ] }) });
};
X.displayName = "SplitButton";
export {
  X as S
};
//# sourceMappingURL=split-button-C94SY3qF.es.js.map
