import { ClickOpenEnums } from "../../../../enums/pageEnums.mjs";
import { SideSheet } from "../../../surfaces/SideSheet.mjs";
import { FluentDialog } from "../../../feedback/FluentDialog.mjs";
import { IconButtonWithTooltip } from "../../../inputs/buttons/IconButtonWithToolTip.mjs";
import { c } from "react-compiler-runtime";
import React, { memo, useState } from "react";
import { makeStyles } from "@material-ui/core";
import { Skeleton } from "@material-ui/lab";
//#region src/UI/templates/ui/renderers/ActionsRenderer.jsx
const useStyles = makeStyles((theme) => ({
	icon: { margin: theme.spacing(.5) },
	iconButtonStyle: {
		width: `${theme.spacing(3)}px !important`,
		height: `${theme.spacing(3)}px !important`,
		background: "#fff",
		borderRadius: 25,
		padding: 6
	},
	circularSkeleton: { borderRadius: "50%" }
}));
const ActionItem = memo((props) => {
	const $ = c(9);
	const { icon, title, onClick, disabled, businessObjectKey: t0 } = props;
	const classes = useStyles();
	const t1 = "udpRecord-ActionsRenderer-" + title;
	const t2 = "udpRecord-ActionsRenderer-" + title;
	let t3;
	if ($[0] !== classes.icon || $[1] !== classes.iconButtonStyle || $[2] !== disabled || $[3] !== icon || $[4] !== onClick || $[5] !== t1 || $[6] !== t2 || $[7] !== title) {
		t3 = /* @__PURE__ */ React.createElement(IconButtonWithTooltip, {
			title,
			className: classes.icon,
			size: "small",
			onClick,
			disabled,
			icon,
			fluentIconClassName: classes.iconButtonStyle,
			id: t1,
			udprecordid: t2
		});
		$[0] = classes.icon;
		$[1] = classes.iconButtonStyle;
		$[2] = disabled;
		$[3] = icon;
		$[4] = onClick;
		$[5] = t1;
		$[6] = t2;
		$[7] = title;
		$[8] = t3;
	} else t3 = $[8];
	return t3;
});
const ActionsRenderer = memo((props) => {
	const $ = c(41);
	const { data: value, actionList } = props;
	const classes = useStyles();
	const [sheetOpen, setSheetOpen] = useState(false);
	const [sheetItem, setSheetItem] = useState(null);
	const [dialogItem, setDialogItem] = useState(null);
	const [dialogOpen, setDialogOpen] = useState(false);
	const [, setIsLoading] = useState(false);
	const [, setSideSheetWidth] = useState(600);
	const [sideSheetButtonLabel, setSideSheetButtonLabel] = useState("");
	const [sideSheetOnSubmit, setSideSheetOnSubmit] = useState(_temp2);
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = (sheetView) => {
			setSheetItem(sheetView);
			setSheetOpen(true);
		};
		$[0] = t0;
	} else t0 = $[0];
	const openSheet = t0;
	let t1;
	if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
		t1 = (dialogView) => {
			setDialogItem(dialogView);
			setDialogOpen(true);
		};
		$[1] = t1;
	} else t1 = $[1];
	const openDialog = t1;
	let t2;
	if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
		t2 = () => {
			setSheetOpen(false);
		};
		$[2] = t2;
	} else t2 = $[2];
	const closeSheet = t2;
	let t3;
	if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
		t3 = () => {
			setDialogOpen(false);
		};
		$[3] = t3;
	} else t3 = $[3];
	const closeDialog = t3;
	let t4;
	if ($[4] !== value) {
		t4 = (actionItem) => {
			if (actionItem.opens === ClickOpenEnums.SideSheet) {
				const valuePropName = actionItem?.view?.properties?.valuePropName;
				if (valuePropName) actionItem.view.properties[valuePropName] = value;
				const closeSideSheetPropName = actionItem?.view?.properties?.closeSideSheetPropName;
				if (closeSideSheetPropName) actionItem.view.properties[closeSideSheetPropName] = closeSheet;
			}
			const properties = actionItem?.view?.properties || {};
			return {
				id: actionItem.id,
				title: actionItem.title || "",
				width: actionItem?.view?.width,
				children: actionItem?.view?.component({
					...properties,
					setSideSheetWidth,
					setSideSheetButtonLabel,
					setSideSheetOnSubmit
				})
			};
		};
		$[4] = value;
		$[5] = t4;
	} else t4 = $[5];
	const getSheetView = t4;
	let t5;
	if ($[6] !== value) {
		t5 = (actionItem_0) => {
			if (actionItem_0.opens === ClickOpenEnums.Dialog) {
				const handleActionTwo = async () => {
					if (actionItem_0?.view?.properties?.actionTwo) {
						setIsLoading(true);
						await actionItem_0?.view?.properties?.actionTwo(value);
						setIsLoading(false);
					}
					closeDialog();
				};
				return {
					id: actionItem_0.id,
					title: actionItem_0?.title || "",
					closeDialog,
					message: actionItem_0?.view?.properties?.message,
					labelOne: actionItem_0?.view?.properties?.labelOne,
					actionTwo: handleActionTwo,
					labelTwo: actionItem_0?.view?.properties?.labelTwo
				};
			}
		};
		$[6] = value;
		$[7] = t5;
	} else t5 = $[7];
	const getDialogView = t5;
	let t6;
	if ($[8] !== actionList || $[9] !== classes || $[10] !== getDialogView || $[11] !== getSheetView || $[12] !== value) {
		let t7;
		if ($[14] !== classes || $[15] !== getDialogView || $[16] !== getSheetView || $[17] !== value) {
			t7 = (item, index) => {
				let onClick_0 = () => item.onClick(value);
				let title = item.title;
				let disabled = item.disabled;
				if (item.opens === ClickOpenEnums.SideSheet) {
					const sheetView_0 = getSheetView(item);
					onClick_0 = () => openSheet(sheetView_0);
				}
				if (item.opens === ClickOpenEnums.Dialog) {
					const dialogView_0 = getDialogView(item);
					onClick_0 = () => openDialog(dialogView_0);
				}
				if (item.getTitle) title = item.getTitle(value);
				if (item.checkDisabled) disabled = item.checkDisabled(value);
				return /* @__PURE__ */ React.createElement(React.Fragment, null, item.loading && /* @__PURE__ */ React.createElement("div", { style: {
					display: "inline-flex",
					marginRight: 10
				} }, /* @__PURE__ */ React.createElement(Skeleton, {
					className: classes.circularSkeleton,
					width: 24,
					height: 40
				})), !item.loading && /* @__PURE__ */ React.createElement(ActionItem, {
					key: `${item.id}-${index}`,
					title,
					icon: item.icon,
					onClick: onClick_0,
					disabled,
					businessObjectKey: value?.businessObjectKey
				}));
			};
			$[14] = classes;
			$[15] = getDialogView;
			$[16] = getSheetView;
			$[17] = value;
			$[18] = t7;
		} else t7 = $[18];
		t6 = actionList.map(t7);
		$[8] = actionList;
		$[9] = classes;
		$[10] = getDialogView;
		$[11] = getSheetView;
		$[12] = value;
		$[13] = t6;
	} else t6 = $[13];
	const displayActions = t6;
	const t7 = sheetItem?.title;
	const t8 = sheetItem?.width || 600;
	const t9 = sheetItem?.children;
	let t10;
	if ($[19] !== t9) {
		t10 = /* @__PURE__ */ React.createElement("div", null, t9);
		$[19] = t9;
		$[20] = t10;
	} else t10 = $[20];
	let t11;
	if ($[21] !== sheetOpen || $[22] !== sideSheetButtonLabel || $[23] !== sideSheetOnSubmit || $[24] !== t10 || $[25] !== t7 || $[26] !== t8) {
		t11 = /* @__PURE__ */ React.createElement(SideSheet, {
			open: sheetOpen,
			onClose: closeSheet,
			title: t7,
			width: t8,
			buttonLabel: sideSheetButtonLabel,
			onSubmit: sideSheetOnSubmit
		}, t10);
		$[21] = sheetOpen;
		$[22] = sideSheetButtonLabel;
		$[23] = sideSheetOnSubmit;
		$[24] = t10;
		$[25] = t7;
		$[26] = t8;
		$[27] = t11;
	} else t11 = $[27];
	const t12 = dialogItem?.title;
	const t13 = dialogItem?.message;
	const t14 = dialogItem?.closeDialog;
	const t15 = dialogItem?.labelOne;
	const t16 = dialogItem?.actionTwo;
	const t17 = dialogItem?.labelTwo;
	const t18 = dialogItem?.isLoading;
	let t19;
	if ($[28] !== dialogOpen || $[29] !== t12 || $[30] !== t13 || $[31] !== t14 || $[32] !== t15 || $[33] !== t16 || $[34] !== t17 || $[35] !== t18) {
		t19 = /* @__PURE__ */ React.createElement(FluentDialog, {
			open: dialogOpen,
			handleClose: closeDialog,
			title: t12,
			message: t13,
			actionOne: t14,
			labelOne: t15,
			actionTwo: t16,
			labelTwo: t17,
			progress: t18
		});
		$[28] = dialogOpen;
		$[29] = t12;
		$[30] = t13;
		$[31] = t14;
		$[32] = t15;
		$[33] = t16;
		$[34] = t17;
		$[35] = t18;
		$[36] = t19;
	} else t19 = $[36];
	let t20;
	if ($[37] !== displayActions || $[38] !== t11 || $[39] !== t19) {
		t20 = /* @__PURE__ */ React.createElement("div", null, displayActions, t11, t19);
		$[37] = displayActions;
		$[38] = t11;
		$[39] = t19;
		$[40] = t20;
	} else t20 = $[40];
	return t20;
});
ActionItem.displayName = "ActionItem";
ActionsRenderer.displayName = "ActionsRenderer";
function _temp() {
	return console.warn("onSubmit not set");
}
function _temp2() {
	return _temp;
}
//#endregion
export { ActionsRenderer };

//# sourceMappingURL=ActionsRenderer.mjs.map