import { c } from "react-compiler-runtime";
import React, { useState } from "react";
import { Chip, Divider, List, ListItem, ListItemText, TextField, makeStyles } from "@material-ui/core";
import { useTranslation } from "react-i18next";
//#region src/udp/ShortcutContent/ListSearch.jsx
const useStyles = makeStyles((theme) => ({
	root: {},
	input: {
		height: 34,
		padding: 0
	},
	formTextInput: { fontSize: 14 },
	labelRoot: { fontSize: 14 },
	chipContainer: { marginRight: theme.spacing(1) },
	divider: { width: "100%" }
}));
const ListSearch = (props) => {
	const $ = c(47);
	const { items, onClick, contentKey: t0, tagKey: t1, includeTags: t2, searchLabel: t3, maxHeight: t4 } = props;
	const contentKey = t0 === void 0 ? "content" : t0;
	const tagKey = t1 === void 0 ? "code" : t1;
	const includeTags = t2 === void 0 ? "false" : t2;
	const searchLabel = t3 === void 0 ? "Search" : t3;
	const maxHeight = t4 === void 0 ? 400 : t4;
	const [searchText, setSearchText] = useState("");
	const classes = useStyles(props);
	const { t } = useTranslation();
	let t5;
	bb0: {
		if (!items.length) {
			let t6;
			if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
				t6 = [];
				$[0] = t6;
			} else t6 = $[0];
			t5 = t6;
			break bb0;
		}
		let t6;
		if ($[1] !== contentKey || $[2] !== includeTags || $[3] !== items || $[4] !== searchText || $[5] !== tagKey) {
			t6 = items?.filter((item) => {
				if (item[contentKey]?.toLowerCase().includes(searchText?.toLowerCase())) return true;
				if (includeTags && item[tagKey]?.toLowerCase().includes(searchText?.toLowerCase())) return true;
				return false;
			});
			$[1] = contentKey;
			$[2] = includeTags;
			$[3] = items;
			$[4] = searchText;
			$[5] = tagKey;
			$[6] = t6;
		} else t6 = $[6];
		t5 = t6;
	}
	const filteredItems = t5;
	let t6;
	if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
		t6 = (event) => {
			setSearchText(event.target.value);
		};
		$[7] = t6;
	} else t6 = $[7];
	const handleSearchChange = t6;
	let t7;
	if ($[8] !== onClick) {
		t7 = (value) => {
			if (onClick) onClick(value);
		};
		$[8] = onClick;
		$[9] = t7;
	} else t7 = $[9];
	const handleOnClick = t7;
	const t8 = classes.root;
	const t9 = `${searchLabel}`;
	let t10;
	if ($[10] !== t || $[11] !== t9) {
		t10 = t(t9);
		$[10] = t;
		$[11] = t9;
		$[12] = t10;
	} else t10 = $[12];
	const t11 = classes?.input;
	const t12 = classes?.formTextInput;
	let t13;
	if ($[13] !== t11 || $[14] !== t12) {
		t13 = { classes: {
			root: t11,
			input: t12
		} };
		$[13] = t11;
		$[14] = t12;
		$[15] = t13;
	} else t13 = $[15];
	const t14 = classes?.labelRoot;
	let t15;
	if ($[16] !== t14) {
		t15 = { classes: { root: t14 } };
		$[16] = t14;
		$[17] = t15;
	} else t15 = $[17];
	let t16;
	if ($[18] !== searchText || $[19] !== t10 || $[20] !== t13 || $[21] !== t15) {
		t16 = /* @__PURE__ */ React.createElement(TextField, {
			label: t10,
			value: searchText,
			onChange: handleSearchChange,
			fullWidth: true,
			variant: "outlined",
			size: "small",
			margin: "dense",
			InputProps: t13,
			InputLabelProps: t15
		});
		$[18] = searchText;
		$[19] = t10;
		$[20] = t13;
		$[21] = t15;
		$[22] = t16;
	} else t16 = $[22];
	let t17;
	if ($[23] !== maxHeight) {
		t17 = {
			maxHeight,
			overflow: "auto",
			overflowX: "hidden"
		};
		$[23] = maxHeight;
		$[24] = t17;
	} else t17 = $[24];
	let t18;
	if ($[25] !== classes.chipContainer || $[26] !== classes.divider || $[27] !== contentKey || $[28] !== filteredItems || $[29] !== handleOnClick || $[30] !== includeTags || $[31] !== tagKey) {
		let t19;
		if ($[33] !== classes.chipContainer || $[34] !== classes.divider || $[35] !== contentKey || $[36] !== handleOnClick || $[37] !== includeTags || $[38] !== tagKey) {
			t19 = (item_0, index) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ListItem, {
				button: true,
				onClick: () => handleOnClick(item_0[contentKey]),
				key: index,
				disableGutters: true
			}, includeTags && /* @__PURE__ */ React.createElement("div", { className: classes.chipContainer }, /* @__PURE__ */ React.createElement(Chip, {
				label: item_0[tagKey],
				color: "primary",
				variant: "outlined"
			})), /* @__PURE__ */ React.createElement(ListItemText, { primary: item_0[contentKey] })), /* @__PURE__ */ React.createElement("div", { className: classes.divider }, /* @__PURE__ */ React.createElement(Divider, { orientation: "horizontal" })));
			$[33] = classes.chipContainer;
			$[34] = classes.divider;
			$[35] = contentKey;
			$[36] = handleOnClick;
			$[37] = includeTags;
			$[38] = tagKey;
			$[39] = t19;
		} else t19 = $[39];
		t18 = filteredItems.map(t19);
		$[25] = classes.chipContainer;
		$[26] = classes.divider;
		$[27] = contentKey;
		$[28] = filteredItems;
		$[29] = handleOnClick;
		$[30] = includeTags;
		$[31] = tagKey;
		$[32] = t18;
	} else t18 = $[32];
	let t19;
	if ($[40] !== t17 || $[41] !== t18) {
		t19 = /* @__PURE__ */ React.createElement(List, { style: t17 }, t18);
		$[40] = t17;
		$[41] = t18;
		$[42] = t19;
	} else t19 = $[42];
	let t20;
	if ($[43] !== classes.root || $[44] !== t16 || $[45] !== t19) {
		t20 = /* @__PURE__ */ React.createElement("div", { className: t8 }, t16, t19);
		$[43] = classes.root;
		$[44] = t16;
		$[45] = t19;
		$[46] = t20;
	} else t20 = $[46];
	return t20;
};
//#endregion
export { ListSearch };

//# sourceMappingURL=ListSearch.mjs.map