import { jsx as o } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { useCallback as p, useMemo as s } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import O from "classnames";
import { BUTTON_LOADING_CLASSNAME as g, BUTTON_FULL_WIDTH_CLASSNAME as h, BUTTON_CONDENSED_CLASSNAME as u, ICON_BUTTON_CLASSNAME as M, ICON_BUTTON_CONTENT_CLASSNAME as U, BUTTON_ICON_LEFT_CLASSNAME as d, BUTTON_LABEL_CLASSNAME as D, BUTTON_LABEL_CENTERED_CLASSNAME as I, BUTTON_ICON_RIGHT_CLASSNAME as y } from "../constants.js";
import x from "../../Typography/Typography.js";
import { TypographyVariant as v, TypographyElement as F } from "../../Typography/types.js";
import { getModifierClasses as R } from "../../../../utils/preact/className.js";
import k from "../../Spinner/Spinner.js";
import { Fragment as G } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/dist/preact.module.js";
const b = (m, _, i, r, t, c, A) => {
  const { children: N, iconLeft: T, iconRight: e, iconButton: a = !1, fullWidth: S, condensed: E, state: n = "default" } = t, C = p(
    (L) => {
      c !== "submit" && L.preventDefault(), r || A?.(L);
    },
    [r, A, c]
  ), l = s(
    () => R(i, _, [i, m]),
    [i, _, m]
  ), f = s(
    () => ({
      ...t,
      className: O(l, {
        [M]: a,
        [u]: E,
        [h]: S,
        [g]: n === "loading"
      }),
      disabled: r || n === "loading"
    }),
    [l, E, r, S, a, t, n]
  ), B = s(
    () => a ? /* @__PURE__ */ o("div", { className: `${U}`, children: N }) : /* @__PURE__ */ o(G, { children: [
      n === "loading" && /* @__PURE__ */ o(k, { size: "x-small" }),
      T && /* @__PURE__ */ o("span", { className: d, children: T }),
      /* @__PURE__ */ o(
        x,
        {
          className: O(D, {
            [I]: t.align === "center"
          }),
          el: F.SPAN,
          variant: v.BODY,
          children: N
        }
      ),
      e && /* @__PURE__ */ o("span", { className: y, children: e })
    ] }),
    [N, a, T, e, t.align, n]
  );
  return { classes: l, click: C, allChildren: B, allProps: f };
};
export {
  b as default
};
