import { X as w, av as P, aw as I, ax as E, Y as r, U as z, F as a, af as s, aB as F, a6 as l, G as b, a7 as d, a8 as m, bJ as N, a9 as D, bK as M, aa as L, ac as T, bL as W, w as h, S as y, a3 as O, aA as j, bH as k, bI as R, L as A, N as U, bP as G, bM as J, bN as K, bO as X, ag as Y } from "./603b75d9.js";
import { useState as S, useRef as V, useEffect as q, useContext as g } from "react";
import { Button100 as Q, ButtonStyleControl as Z } from "./1774f380.js";
import "react-dom";
const _ = w.div`
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  ${(t) => t.$style && tt(t.$style)}
`, tt = (t) => P`
    button {
      border: ${t.borderWidth} ${t.borderStyle} ${t.border};
      border-radius: ${t.radius};
      margin: ${t.margin};
      rotate: ${t.rotation};
      padding: ${t.padding};
      max-width: ${I(t.margin)};
      max-height: ${E(t.margin)};
    }
  `, et = w(G)`
  font-size: 13px;
  margin-right: 4px;
`, nt = w.div`
  display: flex;

  ${(t) => t.$style && ot(t.$style)}
`;
function ot(t) {
  return P`
    svg {
      width: ${t.size} !important;
      height: ${t.size} !important;
    }
  `;
}
function it(t) {
  return t.uiCompInfoList().filter((e) => e.type === "form").map((e) => ({
    label: e.name,
    value: e.name
  }));
}
function p(t, e) {
  const n = t == null ? void 0 : t.getUICompByName(e);
  if (n && n.children.compType.getView() === "form")
    return n.children.comp;
}
function at(t, e) {
  const n = p(t, e);
  if (n)
    return /* @__PURE__ */ a(Y.Provider, {
      value: e,
      children: n.onEventPropertyView(/* @__PURE__ */ l(b, {
        children: [/* @__PURE__ */ a(et, {
          onClick: () => t.setSelectedCompNames(/* @__PURE__ */ new Set([e]), "rightPanel"),
          children: e
        }), r("button.formButtonEvent")]
      }))
    });
}
class rt extends J {
  getPropertyView() {
    const e = r("button.formToSubmit");
    return K({
      filterText: e
    }, /* @__PURE__ */ a(s.Consumer, {
      children: (n) => /* @__PURE__ */ l(b, {
        children: [/* @__PURE__ */ a(X, {
          label: e,
          value: this.value,
          options: it(n),
          onChange: (u) => this.dispatchChangeValueAction(u),
          allowClear: !0
        }), at(n, this.value)]
      })
    }));
  }
}
const lt = [{
  label: r("button.default"),
  value: ""
}, {
  label: r("button.submit"),
  value: "submit"
}];
function H(t) {
  return !t;
}
function st(t, e) {
  const n = p(t, e);
  n && n.submit();
}
const ct = {
  iconSize: h(y, "20px"),
  type: O(lt, ""),
  autoHeight: h(j, "fixed"),
  aspectRatio: h(y, "1 / 1"),
  onEvent: k,
  disabled: R,
  loading: R,
  form: rt,
  prefixIcon: A,
  style: Z,
  viewRef: U,
  restrictPaddingOnRotation: h(y, "controlButton")
};
let C = function() {
  return new z(ct, (t) => {
    const [e, n] = S(120), [u, ut] = S(0), f = V(null), v = V(null);
    q(() => {
      u && e && x();
    }, [u, e]);
    const B = (o, i) => {
      const c = f.current, $ = c == null ? void 0 : c.getElementsByTagName("button")[0];
      c.style.height = o, c.style.width = i, $.style.height = o, $.style.width = i;
    }, x = () => {
      const o = f.current, i = v.current;
      !(o != null && o.clientWidth) || !(o != null && o.clientHeight) || t.autoHeight || !e || B((i == null ? void 0 : i.clientHeight) + "px", (i == null ? void 0 : i.clientWidth) + "px");
    };
    return /* @__PURE__ */ a(s.Consumer, {
      children: (o) => /* @__PURE__ */ a(F, {
        onResize: x,
        render: () => {
          var i;
          return /* @__PURE__ */ a(_, {
            ref: v,
            $style: t.style,
            children: /* @__PURE__ */ a("div", {
              ref: f,
              style: t.autoHeight ? {
                width: "100%",
                height: "100%"
              } : void 0,
              children: /* @__PURE__ */ a(Q, {
                ref: t.viewRef,
                $buttonStyle: t.style,
                loading: t.loading,
                style: t.autoHeight ? {
                  width: "100%",
                  height: "100%",
                  aspectRatio: t.aspectRatio,
                  borderRadius: t.style.radius
                } : {
                  aspectRatio: t.aspectRatio,
                  borderRadius: t.style.radius
                },
                disabled: t.disabled || !H(t.type) && ((i = p(o, t.form)) == null ? void 0 : i.disableSubmit()),
                onClick: () => H(t.type) ? t.onEvent("click") : st(o, t.form),
                children: t.prefixIcon && /* @__PURE__ */ a(nt, {
                  $style: {
                    ...t.style,
                    size: t.iconSize
                  },
                  children: t.prefixIcon
                })
              })
            })
          });
        }
      })
    });
  }).setPropertyViewFn((t) => /* @__PURE__ */ l(b, {
    children: [/* @__PURE__ */ a(d, {
      name: m.basic,
      children: t.prefixIcon.propertyView({
        label: r("button.icon")
      })
    }), (g(s).editorModeStatus === "logic" || g(s).editorModeStatus === "both") && /* @__PURE__ */ l(d, {
      name: m.interaction,
      children: [t.onEvent.getPropertyView(), N(t), D(t), M(t)]
    }), (g(s).editorModeStatus === "layout" || g(s).editorModeStatus === "both") && /* @__PURE__ */ l(b, {
      children: [/* @__PURE__ */ l(d, {
        name: m.layout,
        children: [t.autoHeight.getPropertyView(), t.iconSize.propertyView({
          label: r("button.iconSize")
        })]
      }), /* @__PURE__ */ l(d, {
        name: m.style,
        children: [t.style.getPropertyView(), t.aspectRatio.propertyView({
          label: r("style.aspectRatio")
        })]
      })]
    })]
  })).build();
}();
C = class extends C {
  autoHeight() {
    return this.children.autoHeight.getView();
  }
};
const bt = L(C, [new T("loading", r("button.loadingDesc")), ...W]);
export {
  bt as ControlButton
};
