import { FluentButton } from "../../UI/inputs/buttons/FluentButton.mjs";
import { FluentTextFieldAutoComplete } from "../../UI/inputs/textField/FluentTextFieldAutoComplete.mjs";
import { FluentSearchField } from "../../UI/inputs/textField/FluentSearchField.mjs";
import { InquiryControlList } from "./InquiryControlList.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect, useState } from "react";
import { Popper, Typography, makeStyles, useTheme } from "@material-ui/core";
//#region src/inquiry/inquiryBar/InquiryNodeControls.jsx
const useStyles = makeStyles((theme) => ({
	root: {},
	upperWrapper: {
		paddingLeft: theme.spacing(1),
		paddingRight: theme.spacing(1)
	},
	button: {
		textTransform: "none",
		textDecorationLine: "underline",
		padding: 0,
		height: theme.spacing(3),
		"&:hover": { backgroundColor: "rgba(0, 0, 0, 0)" }
	},
	searchRow: {
		display: "inline-flex",
		width: "100%"
	},
	searchField: { width: "100%" },
	entitySelect: {},
	inputPropRoot: {
		height: theme.spacing(4),
		borderRadius: 0
	},
	inputPropInput: { marginTop: theme.spacing(-1.75) },
	formControl: {
		"& .MuiFormControl-marginDense": { marginTop: 7 },
		width: theme.spacing(9)
	},
	formLabelRoot: { marginTop: -7 }
}));
const AutoCompletePopper = (props) => {
	const $ = c(3);
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = { maxWidth: "fit-content" };
		$[0] = t0;
	} else t0 = $[0];
	let t1;
	if ($[1] !== props) {
		t1 = /* @__PURE__ */ React.createElement(Popper, {
			...props,
			style: t0,
			placement: "bottom-start"
		});
		$[1] = props;
		$[2] = t1;
	} else t1 = $[2];
	return t1;
};
const InquiryNodeControls = (props) => {
	const $ = c(84);
	let changeSideBarView;
	let children;
	let classProps;
	let clearAll;
	let clearSearchStr;
	let collapseAll;
	let entityList;
	let entityValue;
	let expandAll;
	let isPreloadedTree;
	let moveToTop;
	let otherProps;
	let remove;
	let setClearSearchStr;
	let setEntityValue;
	let switchTreeViewMode;
	let t0;
	let t1;
	let t2;
	let treeLoading;
	let treeViewMode;
	if ($[0] !== props) {
		({children, remove, expandAll, collapseAll, moveToTop, clearAll, switchTreeViewMode, treeViewMode, changeSideBarView, showSearch: t0, showControls: t1, hiddenControls: t2, classes: classProps, entityList, entityValue, setEntityValue, clearSearchStr, setClearSearchStr, isPreloadedTree, treeLoading, ...otherProps} = props);
		$[0] = props;
		$[1] = changeSideBarView;
		$[2] = children;
		$[3] = classProps;
		$[4] = clearAll;
		$[5] = clearSearchStr;
		$[6] = collapseAll;
		$[7] = entityList;
		$[8] = entityValue;
		$[9] = expandAll;
		$[10] = isPreloadedTree;
		$[11] = moveToTop;
		$[12] = otherProps;
		$[13] = remove;
		$[14] = setClearSearchStr;
		$[15] = setEntityValue;
		$[16] = switchTreeViewMode;
		$[17] = t0;
		$[18] = t1;
		$[19] = t2;
		$[20] = treeLoading;
		$[21] = treeViewMode;
	} else {
		changeSideBarView = $[1];
		children = $[2];
		classProps = $[3];
		clearAll = $[4];
		clearSearchStr = $[5];
		collapseAll = $[6];
		entityList = $[7];
		entityValue = $[8];
		expandAll = $[9];
		isPreloadedTree = $[10];
		moveToTop = $[11];
		otherProps = $[12];
		remove = $[13];
		setClearSearchStr = $[14];
		setEntityValue = $[15];
		switchTreeViewMode = $[16];
		t0 = $[17];
		t1 = $[18];
		t2 = $[19];
		treeLoading = $[20];
		treeViewMode = $[21];
	}
	const showSearch = t0 === void 0 ? true : t0;
	const showControls = t1 === void 0 ? true : t1;
	let t3;
	if ($[22] !== t2) {
		t3 = t2 === void 0 ? [] : t2;
		$[22] = t2;
		$[23] = t3;
	} else t3 = $[23];
	const hiddenControls = t3;
	const classes = useStyles(props);
	const [searchValue, setSearchValue] = useState("");
	const theme = useTheme();
	let t4;
	if ($[24] !== setEntityValue) {
		t4 = (value) => {
			setEntityValue(value);
		};
		$[24] = setEntityValue;
		$[25] = t4;
	} else t4 = $[25];
	const handleEntityChange = t4;
	let t5;
	if ($[26] === Symbol.for("react.memo_cache_sentinel")) {
		t5 = (event) => {
			setSearchValue(event.target.value);
		};
		$[26] = t5;
	} else t5 = $[26];
	const handleOnChange = t5;
	let t6;
	bb0: {
		if (!entityList) {
			let t7;
			if ($[27] === Symbol.for("react.memo_cache_sentinel")) {
				t7 = [];
				$[27] = t7;
			} else t7 = $[27];
			t6 = t7;
			break bb0;
		}
		let list;
		if ($[28] !== entityList) {
			list = [...entityList];
			list.unshift({
				value: "",
				label: "All"
			});
			$[28] = entityList;
			$[29] = list;
		} else list = $[29];
		t6 = list;
	}
	const updatedEntityList = t6;
	let t7;
	let t8;
	if ($[30] !== clearSearchStr || $[31] !== setClearSearchStr) {
		t7 = () => {
			if (clearSearchStr) {
				setSearchValue("");
				setClearSearchStr(false);
			}
		};
		t8 = [clearSearchStr, setClearSearchStr];
		$[30] = clearSearchStr;
		$[31] = setClearSearchStr;
		$[32] = t7;
		$[33] = t8;
	} else {
		t7 = $[32];
		t8 = $[33];
	}
	useEffect(t7, t8);
	let t9;
	if ($[34] !== classes || $[35] !== entityValue || $[36] !== handleEntityChange || $[37] !== hiddenControls.length || $[38] !== isPreloadedTree || $[39] !== otherProps || $[40] !== searchValue || $[41] !== showSearch || $[42] !== updatedEntityList) {
		t9 = showSearch && !isPreloadedTree && /* @__PURE__ */ React.createElement("div", { className: classes.searchRow }, /* @__PURE__ */ React.createElement("div", { className: classes.searchField }, /* @__PURE__ */ React.createElement(FluentSearchField, {
			id: "udpRecord-InquiryNodeControls-Search",
			udprecordid: "udpRecord-InquiryNodeControls-Search",
			value: searchValue,
			onChange: handleOnChange,
			...otherProps
		})), !!!hiddenControls.length && /* @__PURE__ */ React.createElement("div", { className: classes.entitySelect }, /* @__PURE__ */ React.createElement(FluentTextFieldAutoComplete, {
			id: "udpRecord-InquiryNodeControls-DropDown",
			udprecordid: "udpRecord-InquiryNodeControls-DropDown",
			variant: "filled",
			margin: "normal",
			size: "small",
			fullWidth: true,
			disableClearable: true,
			customPopper: AutoCompletePopper,
			inputProps: { disableUnderline: true },
			classes,
			options: updatedEntityList,
			optionKey: "label",
			value: entityValue || updatedEntityList[0],
			onChange: handleEntityChange
		})));
		$[34] = classes;
		$[35] = entityValue;
		$[36] = handleEntityChange;
		$[37] = hiddenControls.length;
		$[38] = isPreloadedTree;
		$[39] = otherProps;
		$[40] = searchValue;
		$[41] = showSearch;
		$[42] = updatedEntityList;
		$[43] = t9;
	} else t9 = $[43];
	const t10 = showControls ? "space-between" : "end";
	let t11;
	if ($[44] !== hiddenControls.length || $[45] !== theme) {
		t11 = !!hiddenControls?.length && theme.spacing(3);
		$[44] = hiddenControls.length;
		$[45] = theme;
		$[46] = t11;
	} else t11 = $[46];
	let t12;
	if ($[47] !== t10 || $[48] !== t11) {
		t12 = {
			display: "flex",
			justifyContent: t10,
			height: t11
		};
		$[47] = t10;
		$[48] = t11;
		$[49] = t12;
	} else t12 = $[49];
	let t13;
	if ($[50] !== classProps || $[51] !== clearAll || $[52] !== collapseAll || $[53] !== expandAll || $[54] !== hiddenControls || $[55] !== moveToTop || $[56] !== remove || $[57] !== showControls || $[58] !== switchTreeViewMode || $[59] !== treeViewMode) {
		t13 = showControls && /* @__PURE__ */ React.createElement(InquiryControlList, {
			remove,
			expandAll,
			collapseAll,
			moveToTop,
			clearAll,
			switchTreeViewMode,
			treeViewMode,
			hiddenControls,
			classes: classProps
		});
		$[50] = classProps;
		$[51] = clearAll;
		$[52] = collapseAll;
		$[53] = expandAll;
		$[54] = hiddenControls;
		$[55] = moveToTop;
		$[56] = remove;
		$[57] = showControls;
		$[58] = switchTreeViewMode;
		$[59] = treeViewMode;
		$[60] = t13;
	} else t13 = $[60];
	let t14;
	if ($[61] !== changeSideBarView || $[62] !== classes.button || $[63] !== hiddenControls.length || $[64] !== treeLoading) {
		t14 = !!!hiddenControls.length && changeSideBarView && !treeLoading && /* @__PURE__ */ React.createElement(FluentButton, {
			id: "udpRecord-InquiryNodeControls-AdvSearch",
			udprecordid: "udpRecord-InquiryNodeControls-AdvSearch",
			onClick: () => changeSideBarView(1),
			className: classes.button
		}, /* @__PURE__ */ React.createElement(Typography, { variant: "caption" }, "Adv. Search"));
		$[61] = changeSideBarView;
		$[62] = classes.button;
		$[63] = hiddenControls.length;
		$[64] = treeLoading;
		$[65] = t14;
	} else t14 = $[65];
	let t15;
	if ($[66] !== t12 || $[67] !== t13 || $[68] !== t14) {
		t15 = /* @__PURE__ */ React.createElement("div", { style: t12 }, t13, t14);
		$[66] = t12;
		$[67] = t13;
		$[68] = t14;
		$[69] = t15;
	} else t15 = $[69];
	let t16;
	if ($[70] !== classes.upperWrapper || $[71] !== t15 || $[72] !== t9) {
		t16 = /* @__PURE__ */ React.createElement("div", { className: classes.upperWrapper }, t9, t15);
		$[70] = classes.upperWrapper;
		$[71] = t15;
		$[72] = t9;
		$[73] = t16;
	} else t16 = $[73];
	let t17;
	if ($[74] !== hiddenControls.length || $[75] !== showControls) {
		t17 = showControls && /* @__PURE__ */ React.createElement("div", { style: { marginBottom: !!!hiddenControls.length ? 0 : 8 } });
		$[74] = hiddenControls.length;
		$[75] = showControls;
		$[76] = t17;
	} else t17 = $[76];
	let t18;
	if ($[77] !== children || $[78] !== classes.root) {
		t18 = /* @__PURE__ */ React.createElement("div", { className: classes.root }, children);
		$[77] = children;
		$[78] = classes.root;
		$[79] = t18;
	} else t18 = $[79];
	let t19;
	if ($[80] !== t16 || $[81] !== t17 || $[82] !== t18) {
		t19 = /* @__PURE__ */ React.createElement(React.Fragment, null, t16, t17, t18);
		$[80] = t16;
		$[81] = t17;
		$[82] = t18;
		$[83] = t19;
	} else t19 = $[83];
	return t19;
};
//#endregion
export { InquiryNodeControls };

//# sourceMappingURL=InquiryNodeControls.mjs.map