import { ConfigService } from "../configService/index.mjs";
import { apiMutate } from "../utilities/useAxiosMutate.mjs";
import { useCatalogStore } from "../stores/catalogStore.mjs";
import { useShellStore } from "../stores/shellStore.mjs";
import { useActions } from "../hooks/useActions.mjs";
import { useAxiosGet } from "../utilities/useAxiosGet.mjs";
import { InquiryContainer } from "./InquiryContainer.mjs";
import { useAuthedUser } from "../utilities/auth/useAuthedUser.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect, useState } from "react";
import { CircularProgress, makeStyles } from "@material-ui/core";
//#region src/inquiry/Inquiry.jsx
const useStyles = makeStyles((theme) => ({ loadingContent: {
	flex: 1,
	display: "flex",
	flexDirection: "column",
	alignItems: "center",
	justifyContent: "center",
	height: (props) => props.loadingHeight ? props.loadingHeight : "calc(100vh - 160px)"
} }));
/**
* Required Props:
* user - current unity user
* productId - current product id of application
* litnHistory (loaded inquiry tree node history) - array of tree node objects to be used in the recently loaded nodes
* litnHistoryLoading - request status of the litnHistory request
* tree - tree object which contains the tree structure and its properties
* treeLoading - request status of tree request
* treeError - error status of tree request
* treeId - id of the tree that's being loaded (retreived from URL)
* catalogObjects - array of catalog items and it's relationship and properties
* executeQueryAdHoc - search callback
* executeQueryWithParameters - search callback with extra parameters
* executeGetDetailedTree - callback to get detailed tree information for the associated tree
* executeAddRecentlyLoadedNodes - callback to add loaded nodes to history
* pageData - data for the page to be displayed in inquiry
* pageLoading - boolean value for if a page is loading
* pageError - error status of page request
* setPageId - setter for setting pageId when it changes
* pageId - id of page
* initialSearchValue - query parameter representing a value to search upon loading of this inquiry page
* promotedEntities - promoted entities for the catalog used in the inquiry tree
* promotedMethods - promoted methods for the catalog used in the inquiry tree
*
* @param {*} props
* @returns Inquiry
*/
const Inquiry = (props) => {
	const $ = c(54);
	const { treeId, searchValue, autoCollapseNav: t0, useNewUdpTab: t1, containerId: t2 } = props;
	const autoCollapseNav = t0 === void 0 ? true : t0;
	const useNewUdpTab = t1 === void 0 ? true : t1;
	const containerId = t2 === void 0 ? "" : t2;
	const classes = useStyles(props);
	const user = useAuthedUser();
	const { location } = props;
	let t3;
	if ($[0] !== location?.pathname || $[1] !== treeId) {
		t3 = treeId || location?.pathname?.replace("/inquiry/", "");
		$[0] = location?.pathname;
		$[1] = treeId;
		$[2] = t3;
	} else t3 = $[2];
	const udpTreeId = t3;
	const searchParamStr = location?.search;
	let t4;
	if ($[3] !== searchParamStr || $[4] !== searchValue) {
		const searchParams = new URLSearchParams(searchParamStr);
		t4 = searchValue || (searchParams.has("searchValue") === true ? searchParams.get("searchValue") : "");
		$[3] = searchParamStr;
		$[4] = searchValue;
		$[5] = t4;
	} else t4 = $[5];
	const initialSearchValue = t4;
	const [pageId, setPageId] = useState(null);
	const { setCatalogEntities, setCatalogPromotedEntities, setActionPanels, setInquiryParams } = useActions();
	const currentApiCatalogId = useCatalogStore(_temp);
	const promotedMethodEntitiesMap = useCatalogStore(_temp2);
	const setCurrentContainerId = useShellStore(_temp3);
	let t5;
	if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
		t5 = {};
		$[6] = t5;
	} else t5 = $[6];
	const [t6, refetchLitnHistory] = useAxiosGet(ConfigService.integrationV1ApiUrl, `inquirytree/loadedInquiryTreeNodes?inquiryTreeId=${udpTreeId}&userId=${user.id}&productId=${ConfigService.config.UNITY_PRODUCT_ID}`, t5, !!!udpTreeId, false);
	const { data: litnHistory, loading: litnHistoryLoading } = t6;
	let t7;
	if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
		t7 = {};
		$[7] = t7;
	} else t7 = $[7];
	const [t8] = useAxiosGet(ConfigService.integrationV1ApiUrl, `inquirytree/${udpTreeId}/detailed`, t7, !!!udpTreeId, false);
	const { data: tree, loading: treeLoading, error: treeError } = t8;
	const executeQueryAdHoc = _temp4;
	const executeQueryWithParameters = _temp5;
	const executeGetDetailedTree = _temp6;
	let t9;
	if ($[8] !== refetchLitnHistory || $[9] !== udpTreeId || $[10] !== user.id) {
		t9 = async (data_1) => {
			await apiMutate(ConfigService.integrationV1ApiUrl, `inquirytree/${udpTreeId}/loadedInquiryTreeNodes/user/${user.id}/product/${ConfigService.config.UNITY_PRODUCT_ID}`, { method: "post" }, data_1);
			refetchLitnHistory();
		};
		$[8] = refetchLitnHistory;
		$[9] = udpTreeId;
		$[10] = user.id;
		$[11] = t9;
	} else t9 = $[11];
	const executeAddRecentlyLoadedNodes = t9;
	let t10;
	if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
		t10 = {};
		$[12] = t10;
	} else t10 = $[12];
	const [t11] = useAxiosGet(ConfigService.tenantV1ApiUrl, `page/${pageId}`, t10, !!!pageId, false);
	const { data: page, loading: pageLoading, error: pageError } = t11;
	let t12;
	if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
		t12 = {};
		$[13] = t12;
	} else t12 = $[13];
	const [t13] = useAxiosGet(ConfigService.integrationV2ApiUrl, `apiCatalog/${currentApiCatalogId}/inquiryTree/${treeId}/withDescendants?modelsOnly=true`, t12, !currentApiCatalogId || !treeId, true);
	const { data: catalogObjects } = t13;
	let t14;
	bb0: {
		if (!currentApiCatalogId || !promotedMethodEntitiesMap) {
			t14 = null;
			break bb0;
		}
		let t15;
		if ($[14] !== currentApiCatalogId || $[15] !== promotedMethodEntitiesMap) {
			t15 = promotedMethodEntitiesMap[currentApiCatalogId] || [];
			$[14] = currentApiCatalogId;
			$[15] = promotedMethodEntitiesMap;
			$[16] = t15;
		} else t15 = $[16];
		t14 = t15;
	}
	const promotedEntities = t14;
	let t15;
	let t16;
	if ($[17] !== catalogObjects || $[18] !== setCatalogEntities) {
		t15 = () => {
			if (catalogObjects) setCatalogEntities(catalogObjects);
		};
		t16 = [setCatalogEntities, catalogObjects];
		$[17] = catalogObjects;
		$[18] = setCatalogEntities;
		$[19] = t15;
		$[20] = t16;
	} else {
		t15 = $[19];
		t16 = $[20];
	}
	useEffect(t15, t16);
	let t17;
	let t18;
	if ($[21] !== promotedEntities || $[22] !== setCatalogPromotedEntities) {
		t17 = () => {
			if (promotedEntities) setCatalogPromotedEntities(promotedEntities);
		};
		t18 = [setCatalogPromotedEntities, promotedEntities];
		$[21] = promotedEntities;
		$[22] = setCatalogPromotedEntities;
		$[23] = t17;
		$[24] = t18;
	} else {
		t17 = $[23];
		t18 = $[24];
	}
	useEffect(t17, t18);
	let t19;
	let t20;
	if ($[25] !== containerId || $[26] !== setActionPanels || $[27] !== setCurrentContainerId || $[28] !== setInquiryParams) {
		t19 = () => {
			if (containerId) setCurrentContainerId(containerId);
			return () => {
				if (containerId) {
					setCurrentContainerId(null);
					setActionPanels(null, containerId);
					setInquiryParams(null, containerId);
				}
			};
		};
		t20 = [
			setActionPanels,
			setCurrentContainerId,
			containerId,
			setInquiryParams
		];
		$[25] = containerId;
		$[26] = setActionPanels;
		$[27] = setCurrentContainerId;
		$[28] = setInquiryParams;
		$[29] = t19;
		$[30] = t20;
	} else {
		t19 = $[29];
		t20 = $[30];
	}
	useEffect(t19, t20);
	if (treeLoading && !treeError) {
		let t21;
		if ($[31] === Symbol.for("react.memo_cache_sentinel")) {
			t21 = /* @__PURE__ */ React.createElement(CircularProgress, { size: 64 });
			$[31] = t21;
		} else t21 = $[31];
		let t22;
		if ($[32] !== classes.loadingContent) {
			t22 = /* @__PURE__ */ React.createElement("div", { className: classes.loadingContent }, t21);
			$[32] = classes.loadingContent;
			$[33] = t22;
		} else t22 = $[33];
		return t22;
	}
	let t21;
	if ($[34] !== autoCollapseNav || $[35] !== catalogObjects || $[36] !== containerId || $[37] !== currentApiCatalogId || $[38] !== executeAddRecentlyLoadedNodes || $[39] !== initialSearchValue || $[40] !== litnHistory || $[41] !== litnHistoryLoading || $[42] !== page || $[43] !== pageError || $[44] !== pageId || $[45] !== pageLoading || $[46] !== promotedEntities || $[47] !== tree || $[48] !== treeError || $[49] !== treeLoading || $[50] !== udpTreeId || $[51] !== useNewUdpTab || $[52] !== user) {
		t21 = /* @__PURE__ */ React.createElement(InquiryContainer, {
			user,
			productId: ConfigService.config.UNITY_PRODUCT_ID,
			litnHistory,
			litnHistoryLoading,
			tree,
			treeLoading,
			treeError,
			treeId: udpTreeId,
			catalogObjects,
			executeQueryAdHoc,
			executeQueryWithParameters,
			executeGetDetailedTree,
			executeAddRecentlyLoadedNodes,
			pageData: page,
			pageLoading,
			pageError,
			setPageId,
			pageId,
			initialSearchValue,
			promotedEntities,
			apiCatalogId: currentApiCatalogId,
			autoCollapseNav,
			useNewUdpTab,
			containerId
		});
		$[34] = autoCollapseNav;
		$[35] = catalogObjects;
		$[36] = containerId;
		$[37] = currentApiCatalogId;
		$[38] = executeAddRecentlyLoadedNodes;
		$[39] = initialSearchValue;
		$[40] = litnHistory;
		$[41] = litnHistoryLoading;
		$[42] = page;
		$[43] = pageError;
		$[44] = pageId;
		$[45] = pageLoading;
		$[46] = promotedEntities;
		$[47] = tree;
		$[48] = treeError;
		$[49] = treeLoading;
		$[50] = udpTreeId;
		$[51] = useNewUdpTab;
		$[52] = user;
		$[53] = t21;
	} else t21 = $[53];
	return t21;
};
function _temp(state) {
	return state.currentApiCatalogId;
}
function _temp2(state_0) {
	return state_0.promotedMethodEntitiesMap;
}
function _temp3(state_1) {
	return state_1.setCurrentContainerId;
}
async function _temp4(data, apiMethodId) {
	return apiMutate(ConfigService.integrationV1ApiUrl, `apimethod/executeQueryAdHoc/${apiMethodId}`, { method: "post" }, data);
}
async function _temp5(data_0, apiMethodId_0) {
	return apiMutate(ConfigService.integrationV1ApiUrl, `apimethod/executeQueryWithParameters/${apiMethodId_0}`, { method: "post" }, data_0);
}
async function _temp6(treeId_0) {
	return apiMutate(ConfigService.integrationV1ApiUrl, `inquirytree/${treeId_0}/detailed`, { method: "get" });
}
//#endregion
export { Inquiry };

//# sourceMappingURL=Inquiry.mjs.map