import { formatDateToLocaleString } from "../input/DateUtilities.mjs";
import { UnitStateType, UnitTypeEnums } from "../../enums/workflowEnums.mjs";
import { DateTime } from "luxon";
//#region src/utilities/workflow/workflowUtilities.js
const getWorkflowTaskIconByActionType = (type) => {
	let iconName = "ClipboardListIcon";
	switch (type) {
		case UnitTypeEnums.Rest:
			iconName = "CloudImportExportIcon";
			break;
		case UnitTypeEnums.Sms:
			iconName = "MessageFillIcon";
			break;
		case UnitTypeEnums.Mail:
			iconName = "MailSolidIcon";
			break;
		case UnitTypeEnums.Scene:
			iconName = "ReleaseGateIcon";
			break;
		default: break;
	}
	return iconName;
};
const getWorkflowTaskStateIconByStateType = (type) => {
	let iconName = "";
	switch (type) {
		case UnitStateType.Initial:
			iconName = "StopwatchIcon";
			break;
		case UnitStateType.Started:
			iconName = "ProgressLoopOuterIcon";
			break;
		case UnitStateType.Completed:
			iconName = "CheckMarkIcon";
			break;
		case UnitStateType.Cancelled:
			iconName = "CancelIcon";
			break;
		case UnitStateType.Failed:
		default:
			iconName = "ErrorBadgeIcon";
			break;
	}
	return iconName;
};
const getWorkflowTaskStateIconColorByStateType = (type) => {
	let color = "";
	switch (type) {
		case UnitStateType.Initial:
			color = "#ffa726";
			break;
		case UnitStateType.Started:
			color = "#29b6f6";
			break;
		case UnitStateType.Completed:
			color = "#66bb6a";
			break;
		case UnitStateType.Cancelled:
			color = "#f44336";
			break;
		case UnitStateType.Failed:
		default:
			color = "#f44336";
			break;
	}
	return color;
};
const SELECTABLE_NODE_TYPES = [
	UnitTypeEnums.Sms,
	UnitTypeEnums.Mail,
	UnitTypeEnums.Scene
];
const transformWorkflowPlayTree = (node) => {
	if (!node) return null;
	const label = node.name || "";
	const expanded = "expanded";
	const startedAt = node.startedAt ? formatDateToLocaleString(node.startedAt, DateTime.DATETIME_SHORT) : null;
	const updatedNode = {
		id: node.id,
		parentId: node.parentId,
		isExpanded: expanded,
		isSelectable: !!node.type && SELECTABLE_NODE_TYPES.includes(node.type),
		properties: {
			defaultIcon: {
				type: "",
				name: getWorkflowTaskIconByActionType(node.type),
				color: ""
			},
			conditionalIcon: {
				type: "",
				name: !!node.type && getWorkflowTaskStateIconByStateType(node.state),
				color: !!node.type && getWorkflowTaskStateIconColorByStateType(node.state)
			},
			nodeLabel: label,
			nodeSubLabel: node.parentId ? node.description : startedAt || "",
			state: node.state,
			type: node.type,
			interruptPages: node.interruptPages,
			playSceneId: node.playSceneId,
			startedAt: node.startedAt,
			endedAt: node.endedAt,
			dueDate: node.dueDate,
			variables: node.variables,
			sms: node.type === UnitTypeEnums.Sms ? {
				templateData: node.templateData,
				to: node.to,
				from: node.from,
				body: node.body
			} : null,
			email: node.type === UnitTypeEnums.Mail ? {
				templateData: node.templateData,
				to: node.to,
				from: node.from,
				subject: node.subject,
				text: node.text,
				html: node.html
			} : null
		},
		children: []
	};
	for (const child of node.children) {
		const updatedChild = transformWorkflowPlayTree(child);
		if (updatedChild) updatedNode.children.push(updatedChild);
	}
	return updatedNode;
};
//#endregion
export { transformWorkflowPlayTree };

//# sourceMappingURL=workflowUtilities.mjs.map