import { b9 as A, dy as E, V as a, d1 as N, dz as M, P as b, bh as y, bi as u, bj as h, a0 as o, bg as l, bk as O, bl as j, bm as B, bY as K, bn as q, bp as L, bo as H, bX as V, dA as P, dB as Q, bv as _, bd as C, bL as J, bu as k, dC as z, dD as G, z as R, dE as U, cr as W, L as x, dF as X, dG as Y, dH as Z, c1 as I, O as w, d8 as $, dI as ee, dJ as te, dK as re, dL as oe, dM as ae } from "./684d2f28.js";
import { useContext as d } from "react";
import { CreateForm as ie } from "./0b7a6b02.js";
import { d as ne } from "./5dad11bf.js";
import "react-dom";
import "./f52ee168.js";
import "./de2e4e92.js";
import "./bf2ffa97.js";
import "./90e6d3f7.js";
import "./3eacf14a.js";
import "./a353f3e4.js";
import "./a6ed71f1.js";
const se = A.div`
  height: 100%;
  .ant-spin-nested-loading {
    height: 100%;
    .ant-spin-container {
      height: 100%;
    }
  }
`, me = [Z], ce = {
  initialData: Q,
  resetAfterSubmit: _,
  disabled: C,
  disableSubmit: C,
  loading: C,
  onEvent: J(me)
};
function de(e, t) {
  const {
    dispatch: r,
    layout: i,
    positionParams: n
  } = e.container.body[0].children.view.getView();
  let c = 0;
  const s = t.map(({
    column: m,
    compName: p
  }) => {
    const f = {
      i: "",
      h: oe(m.comp.type).h,
      w: n.cols,
      x: 0,
      y: c
    };
    return c = c + f.h, {
      item: {
        compType: m.comp.type,
        name: p,
        comp: {
          ...m.comp.compInitData,
          formDataKey: m.name,
          label: {
            text: m.label
          },
          required: m.required
        }
      },
      layoutItem: f
    };
  });
  r(w(ae(i, s)));
}
function le(e) {
  return {
    name: "submit",
    handler: {
      compType: "executeQuery",
      comp: {
        queryName: e
      }
    }
  };
}
function ue(e, t, r, i) {
  const {
    dispatch: n
  } = t, c = r.getNameGenerator(), s = e.columns.map((S) => {
    const T = c.genItemName("form" + I.upperFirst(S.comp.type));
    return {
      column: S,
      compName: T
    };
  });
  de(t, s);
  const m = e.tableName, p = m.substring(m.lastIndexOf(".") + 1), f = i + "SubmitTo" + p.split("_").map(I.upperFirst).join(""), g = c.genItemName(f);
  n(w($("onEvent", ee(le(g)))));
  const F = e.dataSourceTypeConfig.getQueryInitData(i, m, s), D = r.getQueriesComp();
  return D.dispatch(w(D.pushAction({
    ...F,
    id: te(),
    name: g,
    datasourceId: e.dataSourceId,
    triggerType: "manual",
    notification: {
      showSuccess: !0,
      showFail: !0
    }
  }))), r.setSelectedBottomRes(g, re.Query), "";
}
const pe = (e) => {
  const t = d(l), r = d(k);
  return /* @__PURE__ */ b(z, {
    children: [o("formComp.containerPlaceholder"), /* @__PURE__ */ a("br", {}), /* @__PURE__ */ a(ie, {
      onCreate: (i) => Promise.resolve(ue(i, e, t, r))
    })]
  });
}, he = /* @__PURE__ */ a(G, {
  spin: !0
}), fe = function() {
  return new E(ce, (e, t) => /* @__PURE__ */ a(N.Provider, {
    value: e.disabled,
    children: /* @__PURE__ */ a(se, {
      children: /* @__PURE__ */ a(ne, {
        indicator: he,
        spinning: e.loading,
        style: {
          height: "100%"
        },
        children: /* @__PURE__ */ a(M, {
          ...e,
          hintPlaceholder: /* @__PURE__ */ a(pe, {
            ...e,
            dispatch: t
          })
        })
      })
    })
  })).setPropertyViewFn((e) => /* @__PURE__ */ b(y, {
    children: [/* @__PURE__ */ a(u, {
      name: h.basic,
      children: e.resetAfterSubmit.propertyView({
        label: o("formComp.resetAfterSubmit")
      })
    }), (d(l).editorModeStatus === "logic" || d(l).editorModeStatus === "both") && /* @__PURE__ */ a(y, {
      children: /* @__PURE__ */ b(u, {
        name: h.interaction,
        children: [e.onEvent.getPropertyView(), O(e), e.disableSubmit.propertyView({
          label: o("formComp.disableSubmit")
        }), j(e), B(e)]
      })
    }), (d(l).editorModeStatus === "layout" || d(l).editorModeStatus === "both") && /* @__PURE__ */ a(y, {
      children: /* @__PURE__ */ a(u, {
        name: h.layout,
        children: e.container.getPropertyView()
      })
    }), (d(l).editorModeStatus === "logic" || d(l).editorModeStatus === "both") && /* @__PURE__ */ a(u, {
      name: h.advanced,
      children: e.initialData.propertyView({
        label: o("formComp.initialData")
      })
    }), (d(l).editorModeStatus === "layout" || d(l).editorModeStatus === "both") && /* @__PURE__ */ b(y, {
      children: [/* @__PURE__ */ a(u, {
        name: h.style,
        children: e.container.stylePropertyView()
      }), e.container.children.showHeader.getView() && /* @__PURE__ */ a(u, {
        name: "Header Style",
        children: e.container.headerStylePropertyView()
      }), e.container.children.showBody.getView() && /* @__PURE__ */ a(u, {
        name: "Body Style",
        children: e.container.bodyStylePropertyView()
      }), e.container.children.showFooter.getView() && /* @__PURE__ */ a(u, {
        name: "Footer Style",
        children: e.container.footerStylePropertyView()
      })]
    })]
  })).build();
}();
let v = class extends fe {
  onEventPropertyView(e) {
    return this.children.onEvent.propertyView({
      title: e
    });
  }
  traverseFormItems(e) {
    return R(this.getCompTree(), (t) => t.children.comp.children.formDataKey ? e(t) : !0);
  }
  validateFormItems() {
    return this.traverseFormItems((e) => {
      var r;
      return !((r = e.children.comp.exposingValues) != null && r.invalid);
    });
  }
  runMethodOfItems(...e) {
    const t = [];
    return this.traverseFormItems((r) => {
      var c;
      const i = r.children.comp.exposingMethods();
      for (const s of e) {
        const m = (c = i[s.name]) == null ? void 0 : c.func;
        if (m) {
          const p = s.getParams ? s.getParams(r) : [];
          if (p !== void 0)
            return t.push(Promise.resolve(m(...p))), !0;
        }
      }
      const n = r.children.compType.getView();
      return U.warn(o("form") + n + o("formComp.notSupportMethod") + e.map((s) => s.name)), !0;
    }), Promise.all(t).then(() => {
    });
  }
  setData(e, t) {
    const r = {
      ...t ?? this.children.initialData.getView(),
      ...e
    };
    return this.runMethodOfItems({
      name: "setValue",
      getParams: (i) => {
        var s;
        const n = ((s = i.children.comp.children.formDataKey) == null ? void 0 : s.getView()) || i.children.name.getView(), c = r[n];
        return c !== void 0 ? [c] : void 0;
      }
    }, {
      name: "resetValue"
    }, {
      name: "clearValue"
    });
  }
  reset() {
    return this.setData({});
  }
  submit() {
    return this.disableSubmit() ? Promise.reject("disableSubmit") : this.validateFormItems() ? this.children.onEvent.getView()("submit").then(() => this.children.resetAfterSubmit.getView() ? this.reset() : Promise.resolve()) : (W.error(o("formComp.notValidForm")), Promise.reject("formComp.notValidForm"));
  }
  disableSubmit() {
    return this.children.disabled.getView() || this.children.disableSubmit.getView();
  }
  reduce(e) {
    switch (e.type) {
      case x.UPDATE_NODES_V2: {
        const t = super.reduce(e);
        return t.children.initialData !== this.children.initialData && setTimeout(() => {
          this.dispatch(Y({
            type: "setData",
            initialData: e.value.initialData.value || {}
          }, !1));
        }), t;
      }
      case x.CUSTOM:
        if (X(e, "setData"))
          return this.setData({}, e.value.initialData), this;
    }
    return super.reduce(e);
  }
};
v = K(v, [{
  method: {
    name: "submit",
    description: o("export.submitDesc"),
    params: []
  },
  execute: (e, t) => e.submit()
}, {
  method: {
    name: "reset",
    description: o("formComp.resetDesc"),
    params: []
  },
  execute: (e, t) => e.reset()
}, {
  method: {
    name: "clear",
    description: o("formComp.clearDesc"),
    params: []
  },
  execute: (e, t) => e.runMethodOfItems({
    name: "clearValue"
  })
}, {
  method: {
    name: "setData",
    description: o("formComp.setDataDesc"),
    params: [{
      name: "data",
      type: "JSON"
    }]
  },
  execute: (e, t) => {
    if (t.length !== 1)
      return Promise.reject(o("formComp.valuesLengthError"));
    const r = t[0];
    return typeof r != "object" || r === null || Array.isArray(r) ? Promise.reject(o("formComp.valueTypeError")) : e.setData(r);
  }
}]);
const Fe = q(v, [...L, new H("loading", o("formComp.loadingDesc")), V({
  name: "data",
  desc: o("formComp.dataDesc"),
  depKeys: ["container"],
  func: (e) => {
    const t = {};
    return Object.entries(e.container).forEach(([r, i]) => {
      const n = i;
      n != null && n.hasOwnProperty("formDataKey") && (t[n.formDataKey || r] = n.value);
    }), t;
  }
}), V({
  name: "invalid",
  desc: o("export.invalidDesc"),
  depKeys: ["container"],
  func: (e) => {
    for (const [, t] of Object.entries(e.container)) {
      const r = t;
      if (r != null && r.hasOwnProperty("formDataKey") && r.invalid)
        return !0;
    }
    return !1;
  }
})]);
function Te(e, t) {
  return {
    container: {
      header: P([{
        item: {
          compType: "text",
          name: t.genItemName("formTitle"),
          comp: {
            text: "### " + o("formComp.formTitle")
          }
        },
        layoutItem: {
          i: "",
          h: 5,
          w: 24,
          x: 0,
          y: 0
        }
      }]),
      footer: P([{
        item: {
          compType: "button",
          name: t.genItemName("formButton"),
          comp: {
            text: o("button.submit"),
            type: "submit",
            form: e
          }
        },
        layoutItem: {
          i: "",
          h: 5,
          w: 10,
          x: 14,
          y: 0
        }
      }]),
      showHeader: !0,
      showFooter: !0
    }
  };
}
export {
  Fe as FormComp,
  Te as defaultFormData
};
