import { useUser } from "../auth/useUser.mjs";
import { ChatBotContext } from "./ChatBotContext.mjs";
import { c } from "react-compiler-runtime";
import React, { useState } from "react";
//#region src/utilities/chatBot/ChatBotProvider.tsx
var MessageStatus = /* @__PURE__ */ function(MessageStatus) {
	MessageStatus[MessageStatus["Sent"] = 0] = "Sent";
	MessageStatus[MessageStatus["Delivered"] = 1] = "Delivered";
	MessageStatus[MessageStatus["Error"] = -1] = "Error";
	return MessageStatus;
}(MessageStatus || {});
const ChatBotProvider = (t0) => {
	const $ = c(11);
	const { children } = t0;
	(/* @__PURE__ */ new Date()).toLocaleString([], {
		hour: "2-digit",
		minute: "2-digit",
		hour12: true
	});
	let t1;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t1 = [];
		$[0] = t1;
	} else t1 = $[0];
	const [messageHistory, setMessageHistory] = useState(t1);
	const user = useUser();
	let t2;
	if ($[1] !== user?.id) {
		const createMessage = (messageContent, createdBy, messageText_0) => {
			return {
				createdAt: (/* @__PURE__ */ new Date()).toLocaleString([], {
					hour: "2-digit",
					minute: "2-digit",
					hour12: true
				}),
				createdBy,
				messageContent,
				messageText: messageText_0,
				messageStatus: MessageStatus.Sent,
				outgoing: createdBy.id === user?.id
			};
		};
		t2 = (messageContent_0, createdBy_0, messageText_1) => {
			const newMessage_0 = createMessage(messageContent_0, createdBy_0, messageText_1);
			setMessageHistory((prevState) => [...prevState, newMessage_0]);
		};
		$[1] = user?.id;
		$[2] = t2;
	} else t2 = $[2];
	const addMessage = t2;
	let t3;
	if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
		t3 = (messageContent_1, createdBy_1) => {
			setMessageHistory(_temp);
		};
		$[3] = t3;
	} else t3 = $[3];
	const removeMessageHistory = t3;
	let t4;
	if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
		t4 = () => {
			setMessageHistory(_temp3);
		};
		$[4] = t4;
	} else t4 = $[4];
	const removeLoadingMessage = t4;
	let t5;
	if ($[5] !== addMessage || $[6] !== messageHistory) {
		t5 = {
			messageHistory,
			addMessage,
			removeMessageHistory,
			removeLoadingMessage
		};
		$[5] = addMessage;
		$[6] = messageHistory;
		$[7] = t5;
	} else t5 = $[7];
	let t6;
	if ($[8] !== children || $[9] !== t5) {
		t6 = /* @__PURE__ */ React.createElement(ChatBotContext.Provider, { value: t5 }, children);
		$[8] = children;
		$[9] = t5;
		$[10] = t6;
	} else t6 = $[10];
	return t6;
};
function _temp() {
	return [];
}
function _temp2(message) {
	return !message.createdBy.loading;
}
function _temp3(prevState_0) {
	return prevState_0.filter(_temp2);
}
//#endregion
export { ChatBotProvider };

//# sourceMappingURL=ChatBotProvider.mjs.map