import { SplitScreenTypeEnums } from "../enums/unitySystemEnums.mjs";
import { UnityFluentIcon } from "../utilities/iconLibrary/UnityFluentIcon.mjs";
import { useActions } from "../hooks/useActions.mjs";
import { getIconFromName } from "../utilities/tree/TreeUtilities.mjs";
import { getUnityIconFromName } from "../utilities/iconLibrary/UnityIconLibrary.mjs";
import { StatusChip } from "../UI/dataDisplay/status/StatusChip.mjs";
import { CompleteReminderSwitch } from "./CompleteReminderSwitch.mjs";
import { c } from "react-compiler-runtime";
import React from "react";
import { Checkbox, Divider, FormControlLabel, LinearProgress, List, ListItem, ListItemSecondaryAction, ListItemText, Typography, makeStyles } from "@material-ui/core";
//#region src/reminders/RemindersCard.jsx
const useStyles = makeStyles((theme) => ({
	root: {},
	item: {
		display: "flex",
		"& .MuiListItem-container": { width: "100%" },
		"& .MuiListItem-container > .MuiListItem-button": {
			paddingLeft: 0,
			paddingRight: 0
		}
	}
}));
const RemindersCard = (props) => {
	const $ = c(19);
	const { reminders, setReminders, loading, getNodeToLoad, onLoadedNodeClick, getIcon: t0, updateRemindersAcknowledgement } = props;
	const getIcon = t0 === void 0 ? _temp : t0;
	const classes = useStyles(props);
	const { openSplitScreen } = useActions();
	let t1;
	if ($[0] !== updateRemindersAcknowledgement) {
		t1 = async (event, reminder) => {
			const updatedReminder = { ...reminder };
			updatedReminder.checked = event.target.checked;
			await updateRemindersAcknowledgement([updatedReminder]);
		};
		$[0] = updateRemindersAcknowledgement;
		$[1] = t1;
	} else t1 = $[1];
	const handleSwitchChange = t1;
	let t2;
	if ($[2] !== handleSwitchChange) {
		t2 = (reminder_0) => /* @__PURE__ */ React.createElement(FormControlLabel, {
			control: /* @__PURE__ */ React.createElement(CompleteReminderSwitch, {
				size: "small",
				checked: reminder_0?.acknowledged || false,
				onChange: (event_0) => handleSwitchChange(event_0, reminder_0)
			}),
			label: "Complete",
			style: { marginRight: 8 }
		});
		$[2] = handleSwitchChange;
		$[3] = t2;
	} else t2 = $[3];
	const getCompleteSwitch = t2;
	const getStatusLabel = _temp2;
	const getStatusColor = _temp3;
	let t3;
	if ($[4] !== reminders || $[5] !== setReminders) {
		t3 = (evt, reminder_1) => {
			const updatedReminders = [...reminders];
			updatedReminders.filter((r) => r.id === reminder_1.id)?.forEach((matchingReminder) => matchingReminder.checked = evt.target.checked);
			setReminders(updatedReminders);
		};
		$[4] = reminders;
		$[5] = setReminders;
		$[6] = t3;
	} else t3 = $[6];
	const handleReminderCheck = t3;
	let t4;
	if ($[7] !== getCompleteSwitch || $[8] !== onLoadedNodeClick || $[9] !== openSplitScreen) {
		t4 = (nodeToLoad, reminder_2) => {
			onLoadedNodeClick(nodeToLoad);
			openSplitScreen({
				open: true,
				action: null,
				type: SplitScreenTypeEnums.Reminders,
				params: {
					id: reminder_2?.id || "",
					additionalInputs: reminder_2 ? getCompleteSwitch(reminder_2) : null
				}
			});
		};
		$[7] = getCompleteSwitch;
		$[8] = onLoadedNodeClick;
		$[9] = openSplitScreen;
		$[10] = t4;
	} else t4 = $[10];
	const handleReminderClick = t4;
	let t5;
	if ($[11] !== classes || $[12] !== getIcon || $[13] !== getNodeToLoad || $[14] !== handleReminderCheck || $[15] !== handleReminderClick || $[16] !== loading || $[17] !== reminders) {
		t5 = loading ? /* @__PURE__ */ React.createElement(LinearProgress, null) : reminders?.length ? /* @__PURE__ */ React.createElement(List, { className: classes.root }, reminders.map((reminder_3) => {
			const icon = getIcon(reminder_3);
			const nodeToLoad_0 = getNodeToLoad(reminder_3);
			return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
				className: classes.item,
				key: reminder_3.id
			}, /* @__PURE__ */ React.createElement(Checkbox, {
				id: "udpRecord-RemindersCard-Checkbox",
				udprecordid: "udpRecord-RemindersCard-Checkbox",
				edge: "start",
				checked: reminder_3.checked || reminder_3.acknowledged,
				disableRipple: true,
				size: "small",
				onChange: (evt_0) => handleReminderCheck(evt_0, reminder_3),
				disabled: reminder_3.acknowledged
			}), /* @__PURE__ */ React.createElement(ListItem, {
				id: "udpRecord-ReminderCard-Item",
				udprecordid: "udpRecord-ReminderCard-Item",
				key: reminder_3.id,
				dense: true,
				subject: reminder_3.subject,
				removePadding: true,
				button: true,
				onClick: () => handleReminderClick(nodeToLoad_0, reminder_3)
			}, /* @__PURE__ */ React.createElement(ListItemText, null, /* @__PURE__ */ React.createElement("div", { style: { display: "block" } }, /* @__PURE__ */ React.createElement(Typography, { style: {
				lineHeight: "0.9rem",
				fontSize: "0.8rem"
			} }, reminder_3.subject)), /* @__PURE__ */ React.createElement(Typography, { style: {
				lineHeight: "0.8rem",
				fontSize: "0.7rem",
				fontWeight: 400,
				color: "rgba(0, 0, 0, 0.54)"
			} }, new Date(reminder_3.reminderDate).toDateString())), /* @__PURE__ */ React.createElement(ListItemSecondaryAction, null, /* @__PURE__ */ React.createElement(StatusChip, {
				status: getStatusColor(reminder_3.reminderDate),
				label: getStatusLabel(reminder_3.reminderDate),
				icon: /* @__PURE__ */ React.createElement(UnityFluentIcon, {
					type: icon?.type,
					icon: icon?.type === "unity" ? getUnityIconFromName(icon?.name || "") : getIconFromName(icon?.name || "")
				})
			})))), /* @__PURE__ */ React.createElement(Divider, { style: { height: 1 } }));
		})) : /* @__PURE__ */ React.createElement(Typography, null, "All Reminders Completed");
		$[11] = classes;
		$[12] = getIcon;
		$[13] = getNodeToLoad;
		$[14] = handleReminderCheck;
		$[15] = handleReminderClick;
		$[16] = loading;
		$[17] = reminders;
		$[18] = t5;
	} else t5 = $[18];
	return t5;
};
function _temp() {}
function _temp2(date) {
	const reminderDate = new Date(date).getTime();
	if (reminderDate >= Date.now() - 6048e5) return Math.floor((Date.now() - reminderDate) / 864e5);
	else if (reminderDate < Date.now() - 6048e5 && reminderDate >= Date.now() - 2592e6) return Math.floor((Date.now() - reminderDate) / 864e5);
	else if (reminderDate < Date.now() - 2592e6 && reminderDate >= Date.now() - 15552e6) return Math.floor((Date.now() - reminderDate) / 864e5);
	else if (reminderDate < Date.now() - 15552e6) return Math.floor((Date.now() - reminderDate) / 864e5);
}
function _temp3(date_0) {
	const reminderDate_0 = new Date(date_0).getTime();
	if (reminderDate_0 >= Date.now() - 6048e5) return "";
	else if (reminderDate_0 < Date.now() - 6048e5 && reminderDate_0 >= Date.now() - 2592e6) return "info";
	else if (reminderDate_0 < Date.now() - 2592e6 && reminderDate_0 >= Date.now() - 15552e6) return "warning";
	else if (reminderDate_0 < Date.now() - 15552e6) return "error";
}
//#endregion
export { RemindersCard };

//# sourceMappingURL=RemindersCard.mjs.map