import '@das-fed/ui/packages/business-components/process-configuration/style.css';
import { withInstall as fe } from "@das-fed/utils/with-install/index";
import { ref as r, watch as H, defineComponent as me, computed as O, onUnmounted as ye, onDeactivated as ve, createElementBlock as q, openBlock as F, Fragment as Ce, createElementVNode as u, createCommentVNode as L, createVNode as l, unref as e, withCtx as s, createTextVNode as y, toDisplayString as p, isRef as W, withDirectives as ge } from "vue";
import { DasTable as we, DasTableColumn as K } from "@das-fed/ui/packages/components/table/index";
import { DasDialog as A } from "@das-fed/ui/packages/components/dialog/index";
import { DasButton as N } from "@das-fed/ui/packages/components/button/index";
import { DasMessage as B } from "@das-fed/ui/packages/components/message/index";
import { DasForm as be } from "@das-fed/ui/packages/components/form/index";
import { DasFormItem as U } from "@das-fed/ui/packages/components/form-item/index";
import { DasSpin as G } from "@das-fed/ui/packages/components/spin/index";
import { vOverlay as ke } from "@das-fed/ui/packages/components/overlay/index";
import { t as o, setI18nRule as _e } from "@das-fed/web/packages/i18n/index";
import { getProjectInfo as v } from "@das-fed/utils/common-info/index";
import { createService as Q } from "@das-fed/utils/api-services/src/create-service";
const X = "v1", E = Q(`/workflow/flow/def/${X}`), he = Q(`/workflow/runtime/instance/${X}`), De = E.post("/listJson"), Ne = E.post("/saveCopy"), xe = he.get("/getInstanceCountByDefKeys"), Ie = E.delete("/removeByDefIds"), ze = (f) => {
  const m = v().id ? v().id : "371344636432453", n = v().name ? v().name : o("AIoT项目"), d = r(!1), C = r(!1), x = r({
    defId: "",
    // 流程id
    defKey: "",
    // 流程别名
    name: "",
    // 流程名称
    typeId: "",
    // 所属项目名称
    typeName: n
    // 所属项目id
  }), h = r({
    defId: "",
    // 流程id
    defKey: "",
    // 流程别名
    name: ""
    // 流程名称
  }), w = r({
    name: [{ required: !0, message: o("必填"), trigger: "blur" }],
    defKey: [{ required: !0, message: o("必填"), trigger: "blur" }]
  });
  return {
    copyDialogShow: C,
    copyFormData: x,
    detailFormData: h,
    rules: w,
    copyDialogLoading: d,
    saveCopyProcess: async (S) => {
      var c;
      (c = f.value) == null || c.validate(async (g) => {
        if (g) {
          d.value = !0;
          const [k, z] = await Ne(x.value, {
            params: { destinationProject: m, project: m }
          }).run();
          if (k) {
            d.value = !1, B.error(z.message);
            return;
          }
          d.value = !1, B.success(o("复制成功")), C.value = !1, S();
        }
      }), H(
        () => C.value,
        (g) => {
          var k;
          g || (k = f.value) == null || k.resetField();
        }
      );
    },
    cancelCopy: async () => C.value = !1
  };
}, Ve = () => {
  const f = v().id ? v().id : "371344636432453", m = r(!1), n = r([]);
  return { deleteDialogShow: m, instanceCount: n, reqCount: async (h) => {
    const w = {
      defKeys: h,
      projectId: f
    }, [b, I] = await xe(w).run();
    n.value = I;
  }, deleteDefItem: async (h) => {
    const w = {
      cascade: !0,
      ids: h,
      project: f
    }, [b, I] = await Ie(w).run();
    b || (m.value = !1, B.success(o("删除成功")));
  }, cancelDelete: () => m.value = !1 };
}, Ke = { class: "das-process-configuration" }, Se = { class: "table-box" }, Pe = { class: "table-top" }, Te = { class: "operate" }, Re = { class: "table-content" }, $e = { class: "form-content" }, je = { class: "delete-dialog" }, qe = { class: "delete-text" }, Fe = { class: "delete-info-box" }, Le = {
  key: 0,
  class: "delete-info-text"
}, Ue = {
  key: 1,
  class: "delete-info-text"
}, Be = /* @__PURE__ */ me({
  __name: "index",
  props: {
    modelValue: { type: Boolean, default: !1 },
    title: { default: "" },
    bussinessName: { default: "contract" },
    defKey: { default: "" },
    defId: { default: "" },
    operation: {}
  },
  emits: ["update:modelValue", "processInfo", "cancelDialog", "operationClick"],
  setup(f, { emit: m }) {
    const n = f, d = m, C = O(() => n.title || o("选择流程")), x = window.location.origin, h = v().id ? v().id : "371344636432453";
    v().name ? v().name : o("AIoT项目");
    const w = r(""), b = r(""), I = r(), S = O(() => n.modelValue ? n.modelValue : !1), c = r([]), g = r(!1), k = r(0), { copyDialogShow: z, copyFormData: _, detailFormData: D, rules: Y, saveCopyProcess: Z, cancelCopy: ee, copyDialogLoading: ae } = ze(I), { deleteDialogShow: P, instanceCount: T, reqCount: oe, deleteDefItem: te, cancelDelete: le } = Ve(), ne = O(() => n.operation ?? [
      {
        label: o("编辑"),
        value: "edit"
        // 隐藏
        // hide: true,
      },
      {
        label: o("复制"),
        value: "copy"
        // 隐藏
        // hide: true,
      },
      {
        label: o("删除"),
        value: "delete"
        // 隐藏
        // hide: true,
      }
    ]), se = r([
      { text: o("已发布"), value: "deploy", type: "info" },
      { text: o("未发布"), value: "draft" },
      { text: o("禁用"), value: "forbidden", type: "danger" },
      { text: o("禁止实例"), value: "forbidden_instance", type: "warning" }
    ]), re = (i) => {
      const a = se.value.find((t) => t.value === i);
      return a == null ? void 0 : a.text;
    }, V = r(n.defKey), R = r(), ie = (i, a, t) => {
      R.value = a;
    }, J = async (i, a) => {
      if (i === "edit") {
        const t = JSON.stringify(a);
        window.open(`${x}/mvue/flowDesign?business=${n.bussinessName}&operate=edit&detail=${t}`);
      }
      i === "copy" && (z.value = !0, _.value.defId = a.defId, _.value.typeId = a.typeId, _.value.defKey = "", _.value.name = "", D.value.defId = a.defId, D.value.defKey = a.defKey, D.value.name = a.name), i === "delete" && (w.value = a.id, b.value = a.name, await oe(a.defKey), P.value = !0), d("operationClick", i, a);
    }, $ = async () => {
      k.value++, k.value === 1 && (g.value = !0);
      const i = {
        pageBean: { page: 1, pageSize: 1e4, total: 2 },
        sorter: [{ property: "createTime", direction: "DESC" }],
        querys: [
          { group: "main", operation: "IN", property: "businessTypeId", relation: "AND", value: n.bussinessName }
        ]
      }, [a, t] = await De(i, { params: { project: h } }).run();
      if (a) {
        g.value = !1;
        return;
      }
      g.value = !1, c.value = t.rows;
    }, de = () => {
      window.open(`${x}/mvue/flowDesign?business=${n.bussinessName}&operate=add`);
    }, ue = async () => {
      await Z($);
    }, pe = async () => {
      await te(w.value), await $();
    }, M = () => {
      c.value.map((a) => a.defKey).includes(n.defKey) ? d("cancelDialog", !1) : d("cancelDialog", !0), d("update:modelValue", !1);
    }, ce = () => {
      if (!c.value.map((a) => a.defKey).includes(V.value)) {
        B.warning(o("请选择流程"));
        return;
      }
      d("processInfo", R.value), d("update:modelValue", !1);
    };
    let j = r(0);
    return H(
      () => n.modelValue,
      async (i, a) => {
        i && (await $(), c.value.length > 0 && (n.defKey ? (V.value = n.defKey, R.value = c.value.find((t) => t.defKey === n.defKey)) : (V.value = c.value[0].defKey, R.value = c.value[0])), j.value = window.setInterval(() => {
          $();
        }, 1500)), i || (k.value = 0, window.clearInterval(j.value));
      }
    ), ye(() => {
      window.clearInterval(j.value);
    }), ve(() => {
      window.clearInterval(j.value);
    }), (i, a) => (F(), q(
      Ce,
      null,
      [
        u("div", Ke, [
          l(e(A), {
            modelValue: S.value,
            "onUpdate:modelValue": a[2] || (a[2] = (t) => S.value = t),
            loading: g.value,
            title: C.value,
            width: "1170px",
            height: "689px",
            "body-style": { "background-color": "#f2f2f2", padding: "10px" },
            onClose: M
          }, {
            footer: s(() => [
              u("div", null, [
                l(e(N), { onClick: M }, {
                  default: s(() => [
                    y(
                      p(e(o)("取消")),
                      1
                      /* TEXT */
                    )
                  ]),
                  _: 1
                  /* STABLE */
                }),
                l(e(N), {
                  btnType: "primary",
                  style: { "margin-left": "12px" },
                  onClick: ce
                }, {
                  default: s(() => [
                    y(
                      p(e(o)("确定")),
                      1
                      /* TEXT */
                    )
                  ]),
                  _: 1
                  /* STABLE */
                })
              ])
            ]),
            default: s(() => [
              l(e(G), { spinning: g.value }, {
                default: s(() => [
                  u("div", Se, [
                    u("div", Pe, [
                      u("div", Te, [
                        l(e(N), {
                          btnType: "primary-text",
                          size: "large",
                          block: "",
                          onClick: de
                        }, {
                          default: s(() => [
                            y(
                              p(e(o)("添加")),
                              1
                              /* TEXT */
                            )
                          ]),
                          _: 1
                          /* STABLE */
                        })
                      ])
                    ]),
                    u("div", Re, [
                      l(e(we), {
                        ref: "addTable",
                        "max-height": "100%",
                        "radio-selection": "",
                        hideSelectionText: !1,
                        operation: ne.value,
                        simpleEmpty: "",
                        "outer-border": "",
                        "row-key": "defKey",
                        data: c.value,
                        onOperationClick: J,
                        currentRodioSelection: V.value,
                        "onUpdate:currentRodioSelection": a[1] || (a[1] = (t) => V.value = t),
                        onRadioChange: ie
                      }, {
                        default: s(() => [
                          l(e(K), {
                            label: e(o)("流程名称"),
                            "content-type": "link",
                            onClickLink: a[0] || (a[0] = (t) => J("edit", t)),
                            prop: "name"
                          }, null, 8, ["label"]),
                          l(e(K), {
                            label: e(o)("流程key"),
                            prop: "defKey"
                          }, null, 8, ["label"]),
                          l(e(K), {
                            label: e(o)("流程描述"),
                            prop: "desc"
                          }, null, 8, ["label"]),
                          l(e(K), {
                            label: e(o)("状态"),
                            prop: "status"
                          }, {
                            default: s(({ row: t, $index: Je }) => [
                              y(
                                p(re(t.status)),
                                1
                                /* TEXT */
                              )
                            ]),
                            _: 1
                            /* STABLE */
                          }, 8, ["label"]),
                          l(e(K), {
                            label: e(o)("版本号"),
                            prop: "version"
                          }, null, 8, ["label"])
                        ]),
                        _: 1
                        /* STABLE */
                      }, 8, ["operation", "data", "currentRodioSelection"])
                    ])
                  ])
                ]),
                _: 1
                /* STABLE */
              }, 8, ["spinning"])
            ]),
            _: 1
            /* STABLE */
          }, 8, ["modelValue", "loading", "title"])
        ]),
        L(" 复制弹窗 "),
        l(e(A), {
          modelValue: e(z),
          "onUpdate:modelValue": a[7] || (a[7] = (t) => W(z) ? z.value = t : null),
          title: e(o)("复制流程"),
          size: "small",
          "body-style": { padding: "25px 60px", "box-sizing": "border-box" }
        }, {
          footer: s(() => [
            u("div", null, [
              l(e(N), { onClick: e(ee) }, {
                default: s(() => [
                  y(
                    p(e(o)("取消")),
                    1
                    /* TEXT */
                  )
                ]),
                _: 1
                /* STABLE */
              }, 8, ["onClick"]),
              l(e(N), {
                btnType: "primary",
                style: { "margin-left": "12px" },
                onClick: ue
              }, {
                default: s(() => [
                  y(
                    p(e(o)("确定")),
                    1
                    /* TEXT */
                  )
                ]),
                _: 1
                /* STABLE */
              })
            ])
          ]),
          default: s(() => [
            l(e(G), { spinning: e(ae) }, {
              default: s(() => [
                u("div", $e, [
                  l(e(be), {
                    alignType: "horizontal",
                    contentWidth: "230",
                    marginBottom: "30px",
                    marginRight: "26px",
                    ref_key: "editForm",
                    ref: I,
                    rules: e(Y)
                  }, {
                    default: s(() => [
                      l(e(U), {
                        label: e(o)("原流程名称"),
                        maxlength: "20",
                        modelValue: e(D).name,
                        "onUpdate:modelValue": a[3] || (a[3] = (t) => e(D).name = t),
                        disabled: ""
                      }, null, 8, ["label", "modelValue"]),
                      l(e(U), {
                        label: e(o)("原流程别名"),
                        maxlength: "20",
                        modelValue: e(D).defKey,
                        "onUpdate:modelValue": a[4] || (a[4] = (t) => e(D).defKey = t),
                        disabled: "",
                        marginRight: "0"
                      }, null, 8, ["label", "modelValue"]),
                      l(e(U), {
                        label: e(o)("新流程名称"),
                        maxlength: "20",
                        required: "",
                        prop: "name",
                        modelValue: e(_).name,
                        "onUpdate:modelValue": a[5] || (a[5] = (t) => e(_).name = t)
                      }, null, 8, ["label", "modelValue"]),
                      l(e(U), {
                        label: e(o)("新流程别名"),
                        maxlength: "20",
                        required: "",
                        prop: "defKey",
                        modelValue: e(_).defKey,
                        "onUpdate:modelValue": a[6] || (a[6] = (t) => e(_).defKey = t),
                        marginRight: "0"
                      }, null, 8, ["label", "modelValue"])
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["rules"])
                ])
              ]),
              _: 1
              /* STABLE */
            }, 8, ["spinning"])
          ]),
          _: 1
          /* STABLE */
        }, 8, ["modelValue", "title"]),
        L(" 删除弹窗 "),
        u("div", je, [
          l(e(A), {
            modelValue: e(P),
            "onUpdate:modelValue": a[8] || (a[8] = (t) => W(P) ? P.value = t : null),
            type: "feedback",
            height: "400px",
            feedType: "primary"
          }, {
            footer: s(() => [
              u("div", null, [
                l(e(N), { onClick: e(le) }, {
                  default: s(() => [
                    y(
                      p(e(o)("取消")),
                      1
                      /* TEXT */
                    )
                  ]),
                  _: 1
                  /* STABLE */
                }, 8, ["onClick"]),
                l(e(N), {
                  btnType: "primary",
                  style: { "margin-left": "12px" },
                  onClick: pe
                }, {
                  default: s(() => [
                    y(
                      p(e(o)("确定")),
                      1
                      /* TEXT */
                    )
                  ]),
                  _: 1
                  /* STABLE */
                })
              ])
            ]),
            default: s(() => [
              u("div", qe, [
                y(
                  p(e(o)("删除流程定义，对应的实例和任务会一起删除，")),
                  1
                  /* TEXT */
                ),
                a[9] || (a[9] = u(
                  "br",
                  null,
                  null,
                  -1
                  /* HOISTED */
                )),
                y(
                  p(e(o)("并且无法恢复")),
                  1
                  /* TEXT */
                )
              ]),
              a[10] || (a[10] = u(
                "div",
                { class: "split-line" },
                null,
                -1
                /* HOISTED */
              )),
              ge((F(), q("div", Fe, [
                e(T).length === 0 ? (F(), q(
                  "div",
                  Le,
                  p(e(o)("dasui-process-configuration-key1", b.value, 0, 0)),
                  1
                  /* TEXT */
                )) : L("v-if", !0),
                e(T).length > 0 ? (F(), q(
                  "div",
                  Ue,
                  p(e(o)(
                    "dasui-process-configuration-key1",
                    b.value,
                    e(T)[0].totalCount,
                    e(T)[0].runningCount
                  )),
                  1
                  /* TEXT */
                )) : L("v-if", !0)
              ])), [
                [e(ke)]
              ])
            ]),
            _: 1
            /* STABLE */
          }, 8, ["modelValue"])
        ])
      ],
      64
      /* STABLE_FRAGMENT */
    ));
  }
}), Oe = (f, m) => {
  const n = f.__vccOpts || f;
  for (const [d, C] of m)
    n[d] = C;
  return n;
}, Ae = /* @__PURE__ */ Oe(Be, [["__scopeId", "data-v-e0f8fce9"]]), Ee = {
  必填: { "zh-CN": "必填", en: "Required", _appCode: "framework" },
  复制成功: { "zh-CN": "复制成功", en: "Copied Successfully", _appCode: "framework" },
  删除成功: { "zh-CN": "删除成功", en: "Deleted Successfully", _appCode: "framework" },
  添加: { "zh-CN": "添加", en: "Add", _appCode: "framework" },
  流程名称: { "zh-CN": "流程名称", en: "Process Name", _appCode: "framework" },
  流程: { "zh-CN": "流程", en: "Process", _appCode: "framework" },
  流程描述: { "zh-CN": "流程描述", en: "Process Description", _appCode: "framework" },
  状态: { "zh-CN": "状态", en: "Status", _appCode: "framework" },
  版本号: { "zh-CN": "版本号", en: "Version Number", _appCode: "framework" },
  取消: { "zh-CN": "取消", en: "Cancel", _appCode: "framework" },
  确定: { "zh-CN": "确定", en: "OK", _appCode: "framework" },
  复制流程: { "zh-CN": "复制流程", en: "Copy Process", _appCode: "framework" },
  原流程名称: { "zh-CN": "原流程名称", en: "Original Process Name", _appCode: "framework" },
  原流程别名: { "zh-CN": "原流程别名", en: "Original Process Alias", _appCode: "framework" },
  新流程名称: { "zh-CN": "新流程名称", en: "New Process Name", _appCode: "framework" },
  新流程别名: { "zh-CN": "新流程别名", en: "New Process Alias", _appCode: "framework" },
  并且无法恢复: { "zh-CN": "并且无法恢复", en: "And cannot be recovered", _appCode: "framework" },
  选择流程: { "zh-CN": "选择流程", en: "Select Process", _appCode: "framework" },
  项目: { "zh-CN": "项目", en: "Project", _appCode: "framework" },
  编辑: { "zh-CN": "编辑", en: "Edit", _appCode: "framework" },
  复制: { "zh-CN": "复制", en: "Copy", _appCode: "framework" },
  删除: { "zh-CN": "删除", en: "Delete", _appCode: "framework" },
  已发布: { "zh-CN": "已发布", en: "Published", _appCode: "framework" },
  未发布: { "zh-CN": "未发布", en: "Unpublished", _appCode: "framework" },
  禁用: { "zh-CN": "禁用", en: "Disable", _appCode: "framework" },
  禁止实例: { "zh-CN": "禁止实例", en: "Disable Instance", _appCode: "framework" },
  请选择流程: { "zh-CN": "请选择流程", en: "Please select a process", _appCode: "framework" },
  "dasui-process-configuration-key1": {
    "zh-CN": "$0(共有实例：$1个，其中运行中的实例：$2个)",
    en: "$0(total instances: $1, running instances: $2)",
    _appCode: "framework"
  },
  流程key: { "zh-CN": "流程key", en: "Process Key", _appCode: "framework" },
  "删除流程定义，对应的实例和任务会一起删除，": {
    "zh-CN": "删除流程定义，对应的实例和任务会一起删除，",
    en: "Deleting the process definition will also delete the corresponding instances and tasks,",
    _appCode: "framework"
  }
};
_e(Ee);
const na = fe(Ae);
export {
  na as DasProcessConfiguration,
  na as default
};
