import { defineComponent as w, reactive as b, watch as v, ref as y, onMounted as D, resolveComponent as l, openBlock as h, createElementBlock as g, createElementVNode as r, toDisplayString as I, createVNode as u, createCommentVNode as k, withCtx as F } from "vue";
import { h as C, d as S, _ as R } from "./index.14fbe0a4.js";
import "ant-design-vue";
import "axios";
import "vue-router";
const Z = w({
  name: "SanZhiFormRenderOa",
  props: {
    business: {
      type: [Object],
      default: () => ({})
    },
    hasHeader: {
      type: [Boolean],
      default: !0
    }
  },
  emits: ["handleBtn", "handleInfo"],
  setup(n, { emit: i }) {
    const o = b({
      params: {},
      business: {},
      workflow: {},
      formConfig: {},
      formData: {},
      loading: !1
    });
    v(
      () => n.business,
      (e) => {
        for (let t in e) {
          const a = e[t];
          if (o.business[t] !== a) {
            o.business = { ...n.business }, s();
            return;
          }
        }
      },
      { deep: !0 }
    );
    function p(e) {
      o.loading = !0, S("apis").getFormData(e).then((t) => {
        const { data: a } = t;
        o.workflow = a || {}, o.formConfig = a.form || {}, o.formData = a.formData || {}, i("handleInfo", a);
      }).finally(() => {
        o.loading = !1;
      });
    }
    const c = y(null);
    async function d() {
      try {
        return await c.value.getFormData();
      } catch (e) {
        return console.log(e), {};
      }
    }
    async function f(e) {
      const t = await d();
      i("handleBtn", { button: e, formData: t });
    }
    function s() {
      const { flowId: e, taskId: t, instanceId: a } = n.business, m = C(), _ = {
        flowId: e || m.flowId,
        taskId: t || m.taskId,
        instanceId: a || m.instanceId
      };
      o.params = _, p(_);
    }
    return D(() => {
      s();
    }), { state: o, preFormRef: c, getFormData: d, handleBtn: f };
  }
});
const B = { class: "form-render-oa" }, A = {
  key: 0,
  class: "header"
}, O = { class: "title" }, $ = { class: "actions-box" }, j = { class: "oa-main" }, N = { class: "main-content" };
function V(n, i, o, p, c, d) {
  const f = l("SanZhiWorkflowActions"), s = l("SanZhiFormRender"), e = l("a-spin");
  return h(), g("div", B, [
    n.hasHeader ? (h(), g("div", A, [
      r("div", O, I(n.state.formConfig.name), 1),
      r("div", $, [
        u(f, {
          business: n.state.params
        }, null, 8, ["business"])
      ])
    ])) : k("", !0),
    r("div", j, [
      u(e, {
        spinning: n.state.loading
      }, {
        default: F(() => [
          r("div", N, [
            u(s, {
              ref: "preFormRef",
              "form-json": n.state.formConfig,
              "form-data": n.state.formData
            }, null, 8, ["form-json", "form-data"])
          ])
        ]),
        _: 1
      }, 8, ["spinning"])
    ])
  ]);
}
const L = /* @__PURE__ */ R(Z, [["render", V], ["__scopeId", "data-v-e43237c5"]]);
export {
  L as default
};
