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