import { ConfigService } from "../configService/index.mjs";
import { SplitScreenTypeEnums } from "../enums/unitySystemEnums.mjs";
import { useUser } from "../utilities/auth/useUser.mjs";
import { useCatalogStore } from "../stores/catalogStore.mjs";
import { useShellStore } from "../stores/shellStore.mjs";
import { useActionState, useActions } from "../hooks/useActions.mjs";
import { useAxiosGet } from "../utilities/useAxiosGet.mjs";
import { PageContainer } from "../page/PageContainer/PageContainer.mjs";
import { DraggableSidebarTemplate } from "../UI/templates/DraggableSidebarTemplate.mjs";
import { SidebarHeader } from "../UI/dataDisplay/typography/SidebarHeader.mjs";
import { EntitySideBarContent } from "./sidebar/EntitySideBarContent.mjs";
import { useBuildEnvironment } from "../shell/ui/useBuildEnvironment.mjs";
import { c } from "react-compiler-runtime";
import React, { Suspense, lazy, useEffect, useRef, useState } from "react";
import { Card, CardContent, Slide, makeStyles } from "@material-ui/core";
import PropTypes from "prop-types";
import { useTranslation } from "react-i18next";
import { Skeleton } from "@material-ui/lab";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
//#region src/actions/ActionSplitScreen.jsx
const NotesScreen = lazy(() => import("../notes/NotesScreen.mjs").then((m) => ({ default: m.NotesScreen })));
const RemindersScreen = lazy(() => import("../reminders/RemindersScreen.mjs").then((m) => ({ default: m.RemindersScreen })));
const SPEED_DIAL_ACTIONS = [SplitScreenTypeEnums.Notes, SplitScreenTypeEnums.Reminders];
const useStyles = makeStyles((theme) => ({
	splitScreen: {
		width: "100%",
		height: ({ shellHidden, appRibbonSpace }) => `calc(100vh - ${shellHidden ? 0 : 56}px - ${appRibbonSpace}px)`,
		marginTop: (props) => props.forPage ? "" : props.shellHidden ? 0 : 56
	},
	card: {
		height: "100%",
		overflowY: "auto",
		background: (props) => SPEED_DIAL_ACTIONS.includes(props.type) ? theme?.getThemeData()?.mode === "dark" ? theme.palette.grey[700] : "#f4f4f4" : ""
	},
	cardContent: {
		padding: (props) => SPEED_DIAL_ACTIONS.includes(props.type) ? 0 : "",
		"&:last-child": { paddingBottom: (props) => SPEED_DIAL_ACTIONS.includes(props.type) ? 0 : "" },
		height: `calc(100% - 40px)`
	},
	title: {
		display: "flex",
		flex: 1,
		alignItems: "center",
		marginLeft: theme.spacing(1.5)
	},
	dataRoot: { marginTop: theme.spacing(2) },
	skeletonButton: { height: (props) => props.forPage ? "calc(84vh - 70px)" : "84vh" },
	sidebarRoot: { padding: (props) => SPEED_DIAL_ACTIONS.includes(props.type) ? 0 : "" },
	actionButton: { marginRight: (props) => SPEED_DIAL_ACTIONS.includes(props.type) ? 0 : "" }
}));
const ActionSplitScreen = (props) => {
	const $ = c(133);
	let action;
	let actionPanel;
	let body;
	let executeAction;
	let menuNodeList;
	let open;
	let otherProps;
	let params;
	let refreshTree;
	let selectedNode;
	let selectedNodeObj;
	let selectedNodeParent;
	let sidebarEntity;
	let t0;
	let t1;
	let t2;
	if ($[0] !== props) {
		({body, open, action, type: t0, params, executeAction, actionPanel, selectedNodeObj, menuNodeList, sidebarEntity, forPage: t1, forPageContainer: t2, selectedNode, selectedNodeParent, refreshTree, ...otherProps} = props);
		$[0] = props;
		$[1] = action;
		$[2] = actionPanel;
		$[3] = body;
		$[4] = executeAction;
		$[5] = menuNodeList;
		$[6] = open;
		$[7] = otherProps;
		$[8] = params;
		$[9] = refreshTree;
		$[10] = selectedNode;
		$[11] = selectedNodeObj;
		$[12] = selectedNodeParent;
		$[13] = sidebarEntity;
		$[14] = t0;
		$[15] = t1;
		$[16] = t2;
	} else {
		action = $[1];
		actionPanel = $[2];
		body = $[3];
		executeAction = $[4];
		menuNodeList = $[5];
		open = $[6];
		otherProps = $[7];
		params = $[8];
		refreshTree = $[9];
		selectedNode = $[10];
		selectedNodeObj = $[11];
		selectedNodeParent = $[12];
		sidebarEntity = $[13];
		t0 = $[14];
		t1 = $[15];
		t2 = $[16];
	}
	const type = t0 === void 0 ? SplitScreenTypeEnums.Entity : t0;
	const forPage = t1 === void 0 ? false : t1;
	const forPageContainer = t2 === void 0 ? false : t2;
	const shellHidden = useShellStore(_temp);
	const currentContainerId = useShellStore(_temp2);
	const t3 = useBuildEnvironment() ? 25 : 0;
	let t4;
	if ($[17] !== props || $[18] !== shellHidden || $[19] !== t3) {
		t4 = {
			shellHidden,
			...props,
			appRibbonSpace: t3
		};
		$[17] = props;
		$[18] = shellHidden;
		$[19] = t3;
		$[20] = t4;
	} else t4 = $[20];
	const classes = useStyles(t4);
	const [width, setWidth] = useState(0);
	const { t } = useTranslation();
	const { openSplitScreen, openPageSplitScreen, openPageContainerSplitScreen } = useActions();
	const actionState = useActionState();
	const user = useUser();
	const formRef = useRef(null);
	const currentApiCatalogId = useCatalogStore(_temp3);
	let t5;
	if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
		t5 = {};
		$[21] = t5;
	} else t5 = $[21];
	const [t6] = useAxiosGet(ConfigService.tenantV1ApiUrl, `page/${action?.parameters?.pageId}`, t5, !!!action?.parameters?.pageId, false);
	const { data: page, loading: loadingPage } = t6;
	const entityName = actionPanel ? actionPanel.entityName : actionState?.inquiryParams[currentContainerId || 0]?.selectedNode?.properties?.catalogReturnObject;
	let t7;
	if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
		t7 = {};
		$[22] = t7;
	} else t7 = $[22];
	const [t8] = useAxiosGet(ConfigService.integrationV2ApiUrl, `apiCatalog/${currentApiCatalogId}/catalogObject/${entityName}`, t7, !!!currentApiCatalogId || !!!entityName, false);
	const { data: catalogObject } = t8;
	let t9;
	if ($[23] !== catalogObject?.properties) {
		t9 = catalogObject?.properties ?? [];
		$[23] = catalogObject?.properties;
		$[24] = t9;
	} else t9 = $[24];
	const entityAttributes = t9;
	const openScreen = forPage ? forPageContainer ? openPageContainerSplitScreen : openPageSplitScreen : openSplitScreen;
	let t10;
	if ($[25] !== openScreen || $[26] !== params) {
		t10 = () => {
			if (params?.closeSplitScreenAction) params.closeSplitScreenAction();
			openScreen({
				open: false,
				action: null,
				type: null
			});
			setWidth(0);
		};
		$[25] = openScreen;
		$[26] = params;
		$[27] = t10;
	} else t10 = $[27];
	const closeSplitScreen = t10;
	let t11;
	if ($[28] !== params || $[29] !== type) {
		t11 = () => {
			bb95: switch (type) {
				case SplitScreenTypeEnums.Notes:
					formRef?.current.form.submit();
					break bb95;
				case SplitScreenTypeEnums.Page:
					params?.onSubmit();
					break bb95;
				case SplitScreenTypeEnums.Reminders:
					formRef?.current.form.submit();
					break bb95;
				default:
			}
		};
		$[28] = params;
		$[29] = type;
		$[30] = t11;
	} else t11 = $[30];
	const onSubmitAction = t11;
	let content = null;
	bb0: switch (type) {
		case SplitScreenTypeEnums.Entity: {
			let t12;
			if ($[31] !== action || $[32] !== closeSplitScreen || $[33] !== currentApiCatalogId || $[34] !== entityAttributes || $[35] !== entityName || $[36] !== executeAction || $[37] !== menuNodeList || $[38] !== selectedNodeObj || $[39] !== sidebarEntity) {
				t12 = /* @__PURE__ */ React.createElement(EntitySideBarContent, {
					action,
					executeAction,
					entityAttributes,
					selectedNodeObj,
					apiCatalogId: currentApiCatalogId,
					entityName,
					sidebarEntity,
					menuNodeList,
					closeSplitScreen
				});
				$[31] = action;
				$[32] = closeSplitScreen;
				$[33] = currentApiCatalogId;
				$[34] = entityAttributes;
				$[35] = entityName;
				$[36] = executeAction;
				$[37] = menuNodeList;
				$[38] = selectedNodeObj;
				$[39] = sidebarEntity;
				$[40] = t12;
			} else t12 = $[40];
			content = t12;
			break bb0;
		}
		case SplitScreenTypeEnums.Notes: {
			let t12;
			if ($[41] !== classes.skeletonButton) {
				t12 = /* @__PURE__ */ React.createElement(Skeleton, {
					variant: "rect",
					className: classes.skeletonButton
				});
				$[41] = classes.skeletonButton;
				$[42] = t12;
			} else t12 = $[42];
			const t13 = params?.id;
			const t14 = params?.reloadNotes;
			let t15;
			if ($[43] !== t13 || $[44] !== t14) {
				t15 = /* @__PURE__ */ React.createElement(NotesScreen, {
					formRef,
					shortcutContentFinderEnabled: true,
					id: t13,
					reloadNotes: t14
				});
				$[43] = t13;
				$[44] = t14;
				$[45] = t15;
			} else t15 = $[45];
			let t16;
			if ($[46] !== t12 || $[47] !== t15) {
				t16 = /* @__PURE__ */ React.createElement(Suspense, { fallback: t12 }, t15);
				$[46] = t12;
				$[47] = t15;
				$[48] = t16;
			} else t16 = $[48];
			content = t16;
			break bb0;
		}
		case SplitScreenTypeEnums.Page:
			if (page) {
				const t12 = action?.actionId;
				const t13 = page?.pageId;
				const t14 = selectedNode?.properties?.searchValue;
				let t15;
				if ($[49] !== action?.parameters?.requiredFieldMapping) {
					t15 = action?.parameters?.requiredFieldMapping || {};
					$[49] = action?.parameters?.requiredFieldMapping;
					$[50] = t15;
				} else t15 = $[50];
				const t16 = selectedNode?.nodeObj;
				const t17 = selectedNodeParent?.nodeObj;
				const t18 = selectedNode?.inquiryParams;
				let t19;
				if ($[51] !== refreshTree || $[52] !== t13 || $[53] !== t14 || $[54] !== t15 || $[55] !== t16 || $[56] !== t17 || $[57] !== t18) {
					t19 = {
						pageId: t13,
						contentId: t14,
						requiredFieldsMap: t15,
						nodeObj: t16,
						parentNodeObj: t17,
						inquiryParams: t18,
						refreshTree
					};
					$[51] = refreshTree;
					$[52] = t13;
					$[53] = t14;
					$[54] = t15;
					$[55] = t16;
					$[56] = t17;
					$[57] = t18;
					$[58] = t19;
				} else t19 = $[58];
				let t20;
				if ($[59] !== page || $[60] !== t12 || $[61] !== t19 || $[62] !== user) {
					t20 = /* @__PURE__ */ React.createElement(DndProvider, { backend: HTML5Backend }, /* @__PURE__ */ React.createElement(PageContainer, {
						user,
						key: t12,
						pageData: page,
						widgetParams: t19,
						disableMargins: true
					}));
					$[59] = page;
					$[60] = t12;
					$[61] = t19;
					$[62] = user;
					$[63] = t20;
				} else t20 = $[63];
				content = t20;
			} else if (loadingPage) {
				let t12;
				if ($[64] !== classes.skeletonButton) {
					t12 = /* @__PURE__ */ React.createElement(Skeleton, {
						variant: "rect",
						className: classes.skeletonButton
					});
					$[64] = classes.skeletonButton;
					$[65] = t12;
				} else t12 = $[65];
				content = t12;
			} else content = params?.content || null;
			break bb0;
		case SplitScreenTypeEnums.Reminders: {
			let t12;
			if ($[66] !== classes.skeletonButton) {
				t12 = /* @__PURE__ */ React.createElement(Skeleton, {
					variant: "rect",
					className: classes.skeletonButton
				});
				$[66] = classes.skeletonButton;
				$[67] = t12;
			} else t12 = $[67];
			const t13 = params?.id;
			const t14 = params?.reloadReminders;
			let t15;
			if ($[68] !== t13 || $[69] !== t14) {
				t15 = /* @__PURE__ */ React.createElement(RemindersScreen, {
					formRef,
					shortcutContentFinderEnabled: true,
					id: t13,
					reloadReminders: t14
				});
				$[68] = t13;
				$[69] = t14;
				$[70] = t15;
			} else t15 = $[70];
			let t16;
			if ($[71] !== t12 || $[72] !== t15) {
				t16 = /* @__PURE__ */ React.createElement(Suspense, { fallback: t12 }, t15);
				$[71] = t12;
				$[72] = t15;
				$[73] = t16;
			} else t16 = $[73];
			content = t16;
			break bb0;
		}
		default:
	}
	const cardContent = content;
	let title;
	bb1: switch (type) {
		case SplitScreenTypeEnums.Entity: {
			const t12 = `${entityName} Details`;
			let t13;
			if ($[74] !== t || $[75] !== t12) {
				t13 = t(t12);
				$[74] = t;
				$[75] = t12;
				$[76] = t13;
			} else t13 = $[76];
			title = t13;
			break bb1;
		}
		case SplitScreenTypeEnums.Notes: {
			let t12;
			if ($[77] !== t) {
				t12 = t("Add Note");
				$[77] = t;
				$[78] = t12;
			} else t12 = $[78];
			title = t12;
			break bb1;
		}
		case SplitScreenTypeEnums.Reminders: {
			let t12;
			if ($[79] !== t) {
				t12 = t("Add Reminder");
				$[79] = t;
				$[80] = t12;
			} else t12 = $[80];
			title = t12;
			break bb1;
		}
		default: title = params?.headerTitle || "";
	}
	const headerTitle = title;
	let label = "";
	bb2: switch (type) {
		case SplitScreenTypeEnums.Notes: {
			let t12;
			if ($[81] !== t) {
				t12 = t("Save Note");
				$[81] = t;
				$[82] = t12;
			} else t12 = $[82];
			label = t12;
			break bb2;
		}
		case SplitScreenTypeEnums.Page: {
			const t12 = params?.buttonLabel;
			let t13;
			if ($[83] !== t || $[84] !== t12) {
				t13 = t(t12);
				$[83] = t;
				$[84] = t12;
				$[85] = t13;
			} else t13 = $[85];
			label = t13;
			break bb2;
		}
		case SplitScreenTypeEnums.Reminders: {
			let t12;
			if ($[86] !== t) {
				t12 = t("Save Reminder");
				$[86] = t;
				$[87] = t12;
			} else t12 = $[87];
			label = t12;
			break bb2;
		}
		default:
	}
	const buttonLabelVal = label;
	let t12;
	if ($[88] !== open || $[89] !== params?.initialWidth) {
		t12 = () => {
			if (open) setWidth(params?.initialWidth ?? 420);
		};
		$[88] = open;
		$[89] = params?.initialWidth;
		$[90] = t12;
	} else t12 = $[90];
	let t13;
	if ($[91] !== open || $[92] !== params) {
		t13 = [open, params];
		$[91] = open;
		$[92] = params;
		$[93] = t13;
	} else t13 = $[93];
	useEffect(t12, t13);
	const t14 = !open;
	const t15 = params?.maxWidth;
	let t16;
	if ($[94] === Symbol.for("react.memo_cache_sentinel")) {
		t16 = {
			top: false,
			right: false,
			bottom: false,
			left: true,
			topRight: false,
			bottomRight: false,
			bottomLeft: false,
			topLeft: false
		};
		$[94] = t16;
	} else t16 = $[94];
	let t17;
	if ($[95] !== buttonLabelVal || $[96] !== classes.actionButton || $[97] !== classes.sidebarRoot || $[98] !== closeSplitScreen || $[99] !== headerTitle || $[100] !== onSubmitAction || $[101] !== otherProps || $[102] !== params?.additionalInputs || $[103] !== params?.buttonIcon || $[104] !== params?.buttonProgress || $[105] !== params?.buttonVariant || $[106] !== params?.hideHeader || $[107] !== params?.secondaryButtonIcon || $[108] !== params?.secondaryButtonLabel || $[109] !== params?.secondaryButtonProgress || $[110] !== params?.secondaryButtonVariant || $[111] !== params?.secondaryOnSubmit) {
		t17 = !params?.hideHeader && /* @__PURE__ */ React.createElement(SidebarHeader, {
			onClose: closeSplitScreen,
			title: headerTitle,
			buttonLabel: buttonLabelVal,
			buttonProgress: params?.buttonProgress,
			buttonVariant: params?.buttonVariant,
			buttonIcon: params?.buttonIcon,
			onSubmit: onSubmitAction,
			secondaryButtonLabel: params?.secondaryButtonLabel,
			secondaryButtonProgress: params?.secondaryButtonProgress,
			secondaryButtonVariant: params?.secondaryButtonVariant,
			secondaryButtonIcon: params?.secondaryButtonIcon,
			secondaryOnSubmit: params?.secondaryOnSubmit,
			additionalInputs: params?.additionalInputs || null,
			classes: {
				root: classes.sidebarRoot,
				actionButton: classes.actionButton
			},
			...otherProps
		});
		$[95] = buttonLabelVal;
		$[96] = classes.actionButton;
		$[97] = classes.sidebarRoot;
		$[98] = closeSplitScreen;
		$[99] = headerTitle;
		$[100] = onSubmitAction;
		$[101] = otherProps;
		$[102] = params?.additionalInputs;
		$[103] = params?.buttonIcon;
		$[104] = params?.buttonProgress;
		$[105] = params?.buttonVariant;
		$[106] = params?.hideHeader;
		$[107] = params?.secondaryButtonIcon;
		$[108] = params?.secondaryButtonLabel;
		$[109] = params?.secondaryButtonProgress;
		$[110] = params?.secondaryButtonVariant;
		$[111] = params?.secondaryOnSubmit;
		$[112] = t17;
	} else t17 = $[112];
	let t18;
	if ($[113] !== cardContent || $[114] !== classes.cardContent) {
		t18 = /* @__PURE__ */ React.createElement(CardContent, { className: classes.cardContent }, cardContent);
		$[113] = cardContent;
		$[114] = classes.cardContent;
		$[115] = t18;
	} else t18 = $[115];
	let t19;
	if ($[116] !== classes.card || $[117] !== t17 || $[118] !== t18) {
		t19 = /* @__PURE__ */ React.createElement(Card, {
			square: true,
			elevation: 4,
			className: classes.card
		}, t17, t18);
		$[116] = classes.card;
		$[117] = t17;
		$[118] = t18;
		$[119] = t19;
	} else t19 = $[119];
	let t20;
	if ($[120] !== classes.splitScreen || $[121] !== t19) {
		t20 = /* @__PURE__ */ React.createElement("div", { className: classes.splitScreen }, t19);
		$[120] = classes.splitScreen;
		$[121] = t19;
		$[122] = t20;
	} else t20 = $[122];
	let t21;
	if ($[123] !== open || $[124] !== t20) {
		t21 = /* @__PURE__ */ React.createElement(Slide, {
			in: open,
			direction: "left"
		}, t20);
		$[123] = open;
		$[124] = t20;
		$[125] = t21;
	} else t21 = $[125];
	let t22;
	if ($[126] === Symbol.for("react.memo_cache_sentinel")) {
		t22 = { zIndex: 1e3 };
		$[126] = t22;
	} else t22 = $[126];
	let t23;
	if ($[127] !== body || $[128] !== t14 || $[129] !== t15 || $[130] !== t21 || $[131] !== width) {
		t23 = /* @__PURE__ */ React.createElement(DraggableSidebarTemplate, {
			removePadding: false,
			width,
			setWidth,
			handleToggleClick: _temp4,
			hide: t14,
			expanded: false,
			maxWidth: t15,
			enable: t16,
			body,
			sidebar: t21,
			splitScreenStyle: t22
		});
		$[127] = body;
		$[128] = t14;
		$[129] = t15;
		$[130] = t21;
		$[131] = width;
		$[132] = t23;
	} else t23 = $[132];
	return t23;
};
ActionSplitScreen.propTypes = {
	body: PropTypes.object,
	open: PropTypes.bool,
	action: PropTypes.object,
	executeAction: PropTypes.func,
	entityName: PropTypes.string,
	entityAttributes: PropTypes.array,
	selectedNodeObj: PropTypes.object,
	menuNodeList: PropTypes.array,
	showError: PropTypes.func
};
function _temp(state) {
	return state.shellHidden;
}
function _temp2(state_0) {
	return state_0.currentContainerId;
}
function _temp3(state_1) {
	return state_1.currentApiCatalogId;
}
function _temp4() {}
//#endregion
export { ActionSplitScreen };

//# sourceMappingURL=ActionSplitScreen.mjs.map