import { a3 as w, aC as P, aD as B, aE as E, a4 as r, U as z, H as a, am as s, aI as F, ad as l, I as f, ae as d, af as m, c0 as D, ag as M, c6 as N, ah as T, aj as W, c1 as j, w as h, X as b, aa as k, aH as L, bY as O, bX as R, P as U, S as A, fm as X, fn as Y, f9 as q, fo as G, an as J } from "./56c67d3b.js";
import { useState as S, useRef as V, useEffect as K, useContext as g } from "react";
import { Button100 as Q, ButtonStyleControl as Z } from "./0845e032.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: ${B(t.margin)};
      max-height: ${E(t.margin)};
    }
  `, et = w(X)`
  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(J.Provider, {
      value: e,
      children: n.onEventPropertyView(/* @__PURE__ */ l(f, {
        children: [/* @__PURE__ */ a(et, {
          onClick: () => t.setSelectedCompNames(/* @__PURE__ */ new Set([e]), "rightPanel"),
          children: e
        }), r("button.formButtonEvent")]
      }))
    });
}
class rt extends Y {
  getPropertyView() {
    const e = r("button.formToSubmit");
    return q({
      filterText: e
    }, /* @__PURE__ */ a(s.Consumer, {
      children: (n) => /* @__PURE__ */ l(f, {
        children: [/* @__PURE__ */ a(G, {
          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(b, "20px"),
  type: k(lt, ""),
  autoHeight: h(L, "fixed"),
  aspectRatio: h(b, "1 / 1"),
  onEvent: O,
  disabled: R,
  loading: R,
  form: rt,
  prefixIcon: U,
  style: Z,
  viewRef: A,
  restrictPaddingOnRotation: h(b, "controlButton")
};
let C = function() {
  return new z(ct, (t) => {
    const [e, n] = S(120), [u, ut] = S(0), y = V(null), v = V(null);
    K(() => {
      u && e && x();
    }, [u, e]);
    const I = (o, i) => {
      const c = y.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 = y.current, i = v.current;
      !(o != null && o.clientWidth) || !(o != null && o.clientHeight) || t.autoHeight || !e || I((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: y,
              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(f, {
    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(), D(t), M(t), N(t)]
    }), (g(s).editorModeStatus === "layout" || g(s).editorModeStatus === "both") && /* @__PURE__ */ l(f, {
      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 ft = T(C, [new W("loading", r("button.loadingDesc")), ...j]);
export {
  ft as ControlButton
};
