import { t as e } from "./bpMliuchengdingyidexinxibiaokongzhiqi-DHqibwmz.mjs";
import { i as t, o as n, s as r, t as i } from "./guanlihoutailiuchengmoxing-BX8VRGil.mjs";
import { n as a, t as o } from "./selectedInfo-CT8ehCR8.mjs";
import { t as s } from "./step1-DkoTLlqN.mjs";
import { t as c } from "./step2-UTaTHaZM.mjs";
import { t as l } from "./step3-BJigV7TC.mjs";
import { t as u } from "./step4-Cm1UMOAO.mjs";
import { t as d } from "./stepHeader-Bu4yov3D.mjs";
import { useUserStore as f } from "pubinfo";
import { createBlock as p, createCommentVNode as m, createElementBlock as h, createElementVNode as g, createTextVNode as _, createVNode as v, defineComponent as y, isRef as b, onMounted as x, openBlock as S, provide as C, ref as w, unref as T, withCtx as E } from "vue";
import { useRoute as D, useRouter as O } from "vue-router";
import { Button as k, Space as A } from "ant-design-vue/es";
import { Modal as j, message as M } from "ant-design-vue";
//#region src/pages/flow-create/flow-model/create.vue?vue&type=script&setup=true&lang.ts
var N = {
	"py-10px": "",
	"px-10px": "",
	"w-full": "",
	"h-full": ""
}, P = {
	"w-full": "",
	"h-full": "",
	bg: "#ffffff",
	"rounded-8px": "",
	flex: "",
	"flex-col": ""
}, F = { class: "w-50% h-50px mx-auto pt-12px" }, I = {
	"flex-1": "",
	"overflow-y-auto": ""
}, L = {
	key: 0,
	class: "w-60% mx-auto mt-20px"
}, R = {
	key: 1,
	class: "w-60% mx-auto mt-20px"
}, z = {
	key: 3,
	class: "w-60% mx-auto mt-20px"
}, B = {
	"w-full": "",
	"h-60px": "",
	flex: "",
	"items-center": "",
	"justify-end": "",
	"border-t": "",
	"border-t-solid": "",
	"border-t-1px": "",
	"border-t-gray-200": "",
	"px-20px": ""
}, V = /* @__PURE__ */ y({
	name: "FlowModelCreate",
	__name: "create",
	setup(y) {
		let V = w(1), H = D(), U = O(), W = w("create"), G = w(), K = w(), q = w();
		function J(e) {
			V.value === 1 ? G.value?.validateForm().then(() => {
				V.value = e;
			}) : V.value === 2 ? K.value?.validateForm().then(() => {
				V.value = e;
			}) : V.value === 4 ? q.value?.validateStep4().then(() => {
				V.value = e;
			}) : V.value = e;
		}
		let Y = w({
			id: void 0,
			name: "",
			key: "",
			category: void 0,
			icon: void 0,
			description: "",
			type: 10,
			formType: 20,
			formId: "",
			formCustomCreatePath: "",
			formCustomViewPath: "",
			visible: !0,
			startUserType: 0,
			startUserIds: [],
			startDeptIds: [],
			managerUserIds: [],
			bpmnXml: "",
			bpmnXmlBase64: "",
			allowCancelRunningProcess: !0,
			allowWithdrawTask: !1,
			processIdRule: {
				enable: !1,
				prefix: "",
				infix: "",
				postfix: "",
				length: 5
			},
			autoApprovalType: 0,
			titleSetting: {
				enable: !1,
				title: ""
			},
			summarySetting: {
				enable: !1,
				summary: []
			},
			processBeforeTriggerSetting: null,
			processAfterTriggerSetting: null,
			taskBeforeTriggerSetting: null,
			taskAfterTriggerSetting: null,
			printTemplateSetting: { enable: !1 }
		});
		C("modelData", Y);
		let X = w(void 0);
		function Z() {
			if (H.params.id) X.value = H.params.id, W.value = H.params.type, W.value === "recovery" ? (M.info("当前为流程模型恢复模式，可修改已发布流程模型的信息并保存为新版本", 8), e({ id: X.value }).then((e) => {
				e.success && e.data && (e.data.type = e.data.modelType, e.data.id = e.data.modelId, Y.value = { ...e.data }, delete Y.value.modelType, delete Y.value.modelId, Y.value.formType = e.data.formType === null ? 10 : e.data.formType, Y.value.startUserType = Y.value.startUserIds?.length > 0 ? 1 : Y.value?.startDeptIds?.length > 0 ? 2 : 0);
			})) : i({ id: X.value }).then((e) => {
				if (e.success && e.data && (Y.value = { ...e.data }, Y.value.formType = e.data.formType === null ? 10 : e.data.formType, Y.value.startUserType = Y.value.startUserIds?.length > 0 ? 1 : Y.value?.startDeptIds?.length > 0 ? 2 : 0, W.value === "copy")) {
					Y.value.id = void 0, Y.value.bpmnXml && (Y.value.bpmnXml = Y.value.bpmnXml.replaceAll(`id="diagram_${Y.value.key}"`, `id="diagram_${Y.value.key}-copy"`).replaceAll(`id="${Y.value.key}" name="${Y.value.name}"`, `id="${Y.value.key}-copy" name="${Y.value.name}副本"`).replaceAll(`id="${Y.value.key}_di" bpmnElement="${Y.value.key}"`, `id="${Y.value.key}-copy_di" bpmnElement="${Y.value.key}-copy"`)), Y.value.name = `${Y.value.name}副本`, Y.value.key = `${Y.value.key}-copy`;
					let e = f().user;
					if (e) {
						let t = [e.userId], n = [{
							deptId: e.orgId,
							id: e.userId,
							nickname: e.account
						}];
						Y.value.managerUserIds = t, Y.value.managerUsers = n;
					}
				}
			});
			else {
				W.value = "create";
				let e = f().user;
				if (e) {
					let t = [e.userId], n = [{
						deptId: e.orgId,
						id: e.userId,
						nickname: e.account
					}];
					Y.value.managerUserIds = t, Y.value.managerUsers = n;
				}
			}
		}
		function Q() {
			Y.value.bpmnXml = Y.value.bpmnXml.replaceAll(`id="diagram_${Y.value.key}"`, `id="diagram_${Y.value.key}-copy"`).replaceAll(`id="${Y.value.key}" name="${Y.value.name}"`, `id="${Y.value.key}-copy" name="${Y.value.name}副本"`).replaceAll(`id="${Y.value.key}_di" bpmnElement="${Y.value.key}"`, `id="${Y.value.key}-copy_di" bpmnElement="${Y.value.key}-copy"`), Y.value.formType = Y.value.formType === 10 ? void 0 : Y.value.formType, (W.value === "create" || W.value === "copy") && t(Y.value).then((e) => {
				if (e.success) {
					Y.value.id = e.data, console.warn("流程模型保存成功，ID：", e.data);
					let t = W.value === "copy" ? "复制" : "新建";
					M.success(`${t}成功，可点击【发布】按钮，进行发布模型`), U.back();
				}
			}), W.value === "edit" && r(Y.value).then((e) => {
				e.success && (console.warn("流程模型保存成功"), M.success("修改成功，可点击【发布】按钮，进行发布模型"), U.back());
			});
		}
		function $() {
			Y.value.formType = Y.value.formType === 10 ? void 0 : Y.value.formType, r(Y.value).then((e) => {
				e.success && (console.warn("流程模型保存成功"), M.success("恢复成功，可点击【发布】按钮，进行发布模型"), U.back());
			});
		}
		async function ee() {
			j.confirm({
				title: "发布确认",
				content: "是否确认发布该流程？",
				onOk: async () => {
					Y.value.bpmnXml = Y.value.bpmnXml.replaceAll(`id="diagram_${Y.value.key}"`, `id="diagram_${Y.value.key}-copy"`).replaceAll(`id="${Y.value.key}" name="${Y.value.name}"`, `id="${Y.value.key}-copy" name="${Y.value.name}副本"`).replaceAll(`id="${Y.value.key}_di" bpmnElement="${Y.value.key}"`, `id="${Y.value.key}-copy_di" bpmnElement="${Y.value.key}-copy"`), Y.value.formType = Y.value.formType === 10 ? void 0 : Y.value.formType;
					let e = await (W.value === "create" || W.value === "copy" ? t : r)(Y.value);
					e.success && (W.value === "create" || W.value === "copy" ? (Y.value.id = e.data, console.warn("流程模型保存成功，ID：", e.data), W.value = "edit") : console.warn("流程模型保存成功")), n({ id: Y.value.id }).then((e) => {
						e.success && (M.success("发布成功"), U.back());
					});
				},
				onCancel() {}
			});
		}
		return x(() => {
			o().setSelectId(""), o().setSelectType(""), a().clearElements(), Z();
		}), (e, t) => {
			let n = k, r = A;
			return S(), h("div", N, [g("div", P, [
				g("div", F, [v(d, {
					current: T(V),
					onChange: J
				}, null, 8, ["current"])]),
				g("div", I, [
					T(V) === 1 ? (S(), h("div", L, [v(s, {
						ref_key: "baseInfoRef",
						ref: G,
						modelValue: T(Y),
						"onUpdate:modelValue": t[0] ||= (e) => b(Y) ? Y.value = e : null
					}, null, 8, ["modelValue"])])) : m("", !0),
					T(V) === 2 ? (S(), h("div", R, [v(c, {
						ref_key: "formInfoRef",
						ref: K,
						modelValue: T(Y),
						"onUpdate:modelValue": t[1] ||= (e) => b(Y) ? Y.value = e : null
					}, null, 8, ["modelValue"])])) : m("", !0),
					T(V) === 3 ? (S(), p(l, {
						key: 2,
						modelValue: T(Y),
						"onUpdate:modelValue": t[2] ||= (e) => b(Y) ? Y.value = e : null
					}, null, 8, ["modelValue"])) : m("", !0),
					T(V) === 4 ? (S(), h("div", z, [v(u, {
						ref_key: "step4Ref",
						ref: q,
						modelValue: T(Y),
						"onUpdate:modelValue": t[3] ||= (e) => b(Y) ? Y.value = e : null
					}, null, 8, ["modelValue"])])) : m("", !0)
				]),
				g("div", B, [v(r, null, {
					default: E(() => [
						v(n, { onClick: t[4] ||= (e) => T(U).back() }, {
							default: E(() => [...t[5] ||= [_(" 取消 ", -1)]]),
							_: 1
						}),
						T(W) === "recovery" ? m("", !0) : (S(), p(n, {
							key: 0,
							type: "primary",
							onClick: ee
						}, {
							default: E(() => [...t[6] ||= [_(" 发布 ", -1)]]),
							_: 1
						})),
						T(W) === "recovery" ? m("", !0) : (S(), p(n, {
							key: 1,
							type: "primary",
							onClick: Q
						}, {
							default: E(() => [...t[7] ||= [_(" 保存 ", -1)]]),
							_: 1
						})),
						T(W) === "recovery" ? (S(), p(n, {
							key: 2,
							type: "primary",
							onClick: $
						}, {
							default: E(() => [...t[8] ||= [_(" 恢复 ", -1)]]),
							_: 1
						})) : m("", !0)
					]),
					_: 1
				})])
			])]);
		};
	}
});
//#endregion
export { V as default };
