import { getEllipseColor } from "../../utilities/style/colorConverter.mjs";
import { AmbientCardTitle } from "../surfaces/cards/AmbientCard/AmbientCardTitle.mjs";
import { useItemSubCard } from "../../hooks/useItemSubCard.mjs";
import { EmptyStateDisplay } from "../dataDisplay/EmptyStateDisplay.mjs";
import { c } from "react-compiler-runtime";
import React, { useState } from "react";
import { Box, Divider, Fade, Grow, IconButton, List, ListItem, ListItemAvatar, ListItemText, Typography, makeStyles, useTheme } from "@material-ui/core";
import { DateTime } from "luxon";
import clsx from "clsx";
import { PropTypes as PropTypes$1 } from "prop-types";
import { useTranslation } from "react-i18next";
import { grey } from "@material-ui/core/colors";
import KeyboardArrowLeftIcon from "@material-ui/icons/esm/KeyboardArrowLeft";
//#region src/UI/widgets/ItemsWidgetCard.jsx
const useStyles = makeStyles((theme) => ({
	mainContainer: {
		backgroundColor: theme.palette.background.paper,
		padding: "0px",
		gap: "0px",
		order: 3,
		alignSelf: "stretch"
	},
	secondaryContainer: {
		backgroundColor: theme.palette.background.paper,
		padding: "0px",
		gap: "0px",
		order: 0,
		alignSelf: "stretch",
		flexGrow: 0,
		width: "100%"
	},
	listItemPrimary: {
		fontSize: "14px",
		fontWeight: 600
	},
	listItemSecondary: {
		fontSize: "12px",
		fontWeight: 400,
		color: grey[500]
	},
	listContainer: {
		width: "100%",
		backgroundColor: theme.palette.background.paper,
		padding: "0px"
	},
	listItem: {
		display: "flex",
		flexDirection: "row",
		alignItems: "flex-start",
		padding: "8px 16px"
	},
	listItemAvatar: { minWidth: "32px" },
	listItemText: { margin: 0 },
	itemContainer: { paddingRight: "5px" },
	emptyStateDisplay: {
		marginTop: theme.spacing(1),
		marginBottom: theme.spacing(1)
	}
}));
/**
* `ItemsWidgetCard` component
*/
const ItemsWidgetCard = (props) => {
	const $ = c(59);
	const [checked, setChecked] = useState(false);
	const [cardItemData, setCardItemData] = useState();
	const { cardData, subCardsList: t0, style, headerColor, emptyStatePrimaryText, emptyStateImageSrc, emptyStateIconSize, emptyStateImageWidth, emptyStateClassName, emptyStateIcon, title: t1, subCardTypeField: t2 } = props;
	let t3;
	if ($[0] !== t0) {
		t3 = t0 === void 0 ? {} : t0;
		$[0] = t0;
		$[1] = t3;
	} else t3 = $[1];
	const subCardsList = t3;
	const title = t1 === void 0 ? "Account Items" : t1;
	const subCardTypeField = t2 === void 0 ? "type" : t2;
	const { SubCard, setSubCardType, subCardType, getSubCardInfo } = useItemSubCard(subCardsList);
	const classes = useStyles();
	const theme = useTheme();
	const { t } = useTranslation();
	let t4;
	if ($[2] !== setSubCardType || $[3] !== subCardTypeField) {
		t4 = (accountItem) => {
			setCardItemData(accountItem);
			setSubCardType(accountItem?.[subCardTypeField] || "");
			setChecked(_temp);
		};
		$[2] = setSubCardType;
		$[3] = subCardTypeField;
		$[4] = t4;
	} else t4 = $[4];
	const handleChange = t4;
	const t5 = classes.mainContainer;
	let t6;
	if ($[5] !== style) {
		t6 = {
			...style,
			height: "100%"
		};
		$[5] = style;
		$[6] = t6;
	} else t6 = $[6];
	let t7;
	if ($[7] !== headerColor || $[8] !== theme) {
		t7 = headerColor && getEllipseColor(theme, headerColor, "light");
		$[7] = headerColor;
		$[8] = theme;
		$[9] = t7;
	} else t7 = $[9];
	let t8;
	if ($[10] !== headerColor || $[11] !== theme) {
		t8 = theme.palette.getContrastText(getEllipseColor(theme, headerColor, "light"));
		$[10] = headerColor;
		$[11] = theme;
		$[12] = t8;
	} else t8 = $[12];
	let t9;
	if ($[13] !== t7 || $[14] !== t8) {
		t9 = {
			gap: "8px",
			width: "100%",
			padding: "8px",
			backgroundColor: t7,
			color: t8
		};
		$[13] = t7;
		$[14] = t8;
		$[15] = t9;
	} else t9 = $[15];
	let t10;
	if ($[16] !== handleChange || $[17] !== subCardType) {
		t10 = subCardType !== "" && /* @__PURE__ */ React.createElement(IconButton, {
			"aria-label": "delete",
			size: "small",
			onClick: () => handleChange(""),
			style: { marginLeft: "10px" },
			id: "udpRecord-ItemsWidgetCard-delete",
			udprecordid: "udpRecord-ItemsWidgetCard-delete"
		}, /* @__PURE__ */ React.createElement(KeyboardArrowLeftIcon, { fontSize: "inherit" }));
		$[16] = handleChange;
		$[17] = subCardType;
		$[18] = t10;
	} else t10 = $[18];
	const t11 = subCardType !== "" ? subCardType : title;
	let t12;
	if ($[19] !== headerColor || $[20] !== theme) {
		t12 = headerColor && getEllipseColor(theme, headerColor, "light");
		$[19] = headerColor;
		$[20] = theme;
		$[21] = t12;
	} else t12 = $[21];
	let t13;
	if ($[22] !== t12) {
		t13 = { backgroundColor: t12 };
		$[22] = t12;
		$[23] = t13;
	} else t13 = $[23];
	let t14;
	if ($[24] !== t11 || $[25] !== t13) {
		t14 = /* @__PURE__ */ React.createElement(AmbientCardTitle, {
			title: t11,
			style: t13
		});
		$[24] = t11;
		$[25] = t13;
		$[26] = t14;
	} else t14 = $[26];
	let t15;
	if ($[27] !== t10 || $[28] !== t14 || $[29] !== t9) {
		t15 = /* @__PURE__ */ React.createElement(Box, {
			display: "flex",
			flexDirection: "row",
			alignItems: "center",
			style: t9
		}, t10, t14);
		$[27] = t10;
		$[28] = t14;
		$[29] = t9;
		$[30] = t15;
	} else t15 = $[30];
	let t16;
	if ($[31] !== SubCard || $[32] !== cardData || $[33] !== cardItemData || $[34] !== checked || $[35] !== classes.emptyStateDisplay || $[36] !== classes.itemContainer || $[37] !== classes.listContainer || $[38] !== classes.listItem || $[39] !== classes.listItemAvatar || $[40] !== classes.listItemPrimary || $[41] !== classes.listItemSecondary || $[42] !== classes.listItemText || $[43] !== classes.secondaryContainer || $[44] !== emptyStateClassName || $[45] !== emptyStateIcon || $[46] !== emptyStateIconSize || $[47] !== emptyStateImageSrc || $[48] !== emptyStateImageWidth || $[49] !== emptyStatePrimaryText || $[50] !== getSubCardInfo || $[51] !== handleChange || $[52] !== t) {
		t16 = !checked ? /* @__PURE__ */ React.createElement(Grow, {
			in: !checked,
			style: {
				transformOrigin: "0 0 0",
				width: "100%"
			},
			...!checked ? { timeout: 500 } : {},
			mountOnEnter: true,
			unmountOnExit: true
		}, /* @__PURE__ */ React.createElement(Box, {
			display: "flex",
			flexDirection: "column",
			alignItems: "flex-start",
			className: classes.secondaryContainer
		}, /* @__PURE__ */ React.createElement(List, { className: classes.listContainer }, cardData?.length > 0 ? cardData?.map((cardItem, index) => {
			const { defaultColor, textColor, backgroundColor, icon: Icon } = getSubCardInfo(cardItem?.accountItemName);
			return /* @__PURE__ */ React.createElement(React.Fragment, { key: `${cardItem?.name}-${index}` }, /* @__PURE__ */ React.createElement(ListItem, {
				button: true,
				className: classes.listItem,
				style: { backgroundColor },
				onClick: () => handleChange(cardItem),
				id: "udpRecord-ItemsWidgetCard-ListItem-" + cardItem?.name.replace(/\s+/g, "") + "-" + cardItem?.businessObjectKey,
				udprecordid: "udpRecord-ItemsWidgetCard-ListItem-" + cardItem?.name.replace(/\s+/g, "") + "-" + cardItem?.businessObjectKey
			}, /* @__PURE__ */ React.createElement(ListItemAvatar, { className: classes.listItemAvatar }, /* @__PURE__ */ React.createElement(Icon, {
				color: defaultColor,
				width: "22px",
				height: "22px"
			})), /* @__PURE__ */ React.createElement(ListItemText, {
				className: classes.listItemText,
				primary: /* @__PURE__ */ React.createElement(Typography, {
					variant: "subtitle2",
					className: classes?.listItemPrimary,
					style: { color: textColor }
				}, cardItem?.name),
				secondary: /* @__PURE__ */ React.createElement(Typography, {
					variant: "caption",
					className: classes?.listItemSecondary
				}, cardItem?.date ? DateTime.fromJSDate(new Date(cardItem?.date)).isValid ? DateTime.fromJSDate(new Date(cardItem?.date)).toFormat("MMM dd, yyyy") : "Invalid date" : "Date field is empty")
			}), /* @__PURE__ */ React.createElement(Box, {
				display: "flex",
				flexDirection: "column",
				justifyContent: "center",
				alignItems: "flex-end",
				className: classes.itemContainer
			}, /* @__PURE__ */ React.createElement(Typography, {
				variant: "subtitle2",
				className: classes.listItemPrimary
			}, `$${cardItem?.amount || 0}`))), /* @__PURE__ */ React.createElement(Divider, null));
		}) : /* @__PURE__ */ React.createElement("div", { className: clsx(classes.emptyStateDisplay, emptyStateClassName) }, /* @__PURE__ */ React.createElement(EmptyStateDisplay, {
			primaryText: emptyStatePrimaryText ?? t("No results found"),
			icon: emptyStateIcon,
			iconSize: emptyStateIconSize,
			imageSrc: emptyStateImageSrc,
			imageWidth: emptyStateImageWidth
		}))))) : /* @__PURE__ */ React.createElement(Fade, {
			in: checked,
			style: {
				transformOrigin: "0 0 0",
				width: "100%"
			},
			...checked ? { timeout: 1e3 } : {},
			mountOnEnter: true,
			unmountOnExit: true
		}, /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(SubCard, { cardInfo: cardItemData })));
		$[31] = SubCard;
		$[32] = cardData;
		$[33] = cardItemData;
		$[34] = checked;
		$[35] = classes.emptyStateDisplay;
		$[36] = classes.itemContainer;
		$[37] = classes.listContainer;
		$[38] = classes.listItem;
		$[39] = classes.listItemAvatar;
		$[40] = classes.listItemPrimary;
		$[41] = classes.listItemSecondary;
		$[42] = classes.listItemText;
		$[43] = classes.secondaryContainer;
		$[44] = emptyStateClassName;
		$[45] = emptyStateIcon;
		$[46] = emptyStateIconSize;
		$[47] = emptyStateImageSrc;
		$[48] = emptyStateImageWidth;
		$[49] = emptyStatePrimaryText;
		$[50] = getSubCardInfo;
		$[51] = handleChange;
		$[52] = t;
		$[53] = t16;
	} else t16 = $[53];
	let t17;
	if ($[54] !== classes.mainContainer || $[55] !== t15 || $[56] !== t16 || $[57] !== t6) {
		t17 = /* @__PURE__ */ React.createElement(Box, {
			display: "flex",
			flexDirection: "column",
			alignItems: "flex-start",
			flexGrow: "1",
			className: t5,
			style: t6
		}, t15, t16);
		$[54] = classes.mainContainer;
		$[55] = t15;
		$[56] = t16;
		$[57] = t6;
		$[58] = t17;
	} else t17 = $[58];
	return t17;
};
ItemsWidgetCard.propTypes = {
	cardData: PropTypes$1.array.isRequired,
	subCardsList: PropTypes$1.object.isRequired,
	style: PropTypes$1.object
};
function _temp(prev) {
	return !prev;
}
//#endregion
export { ItemsWidgetCard };

//# sourceMappingURL=ItemsWidgetCard.mjs.map