import { FluentTextFieldAutoComplete } from "../../UI/inputs/textField/FluentTextFieldAutoComplete.mjs";
import { FluentIconButton } from "../../UI/inputs/buttons/FluentIconButton.mjs";
import { c } from "react-compiler-runtime";
import React, { useState } from "react";
import { TextField, makeStyles } from "@material-ui/core";
import { DropdownIcon, TextFieldIcon } from "@fluentui/react-icons";
import { useTranslation } from "react-i18next";
//#region src/dataBrowser/forms/RequiredFieldsMappingField.jsx
const useStyles = makeStyles((theme) => ({
	root: {
		display: "flex",
		alignItems: "center"
	},
	requiredFieldContainer: {
		width: "100%",
		display: "flex",
		alignItems: "center"
	},
	input: {
		height: 34,
		padding: 0
	},
	formTextInput: { fontSize: 14 },
	labelRoot: { fontSize: 14 }
}));
const RequiredFieldsMappingField = (props) => {
	const $ = c(55);
	const { requiredField, onRequiredFieldChange, options, optionLabelDisplayFunction, groupBy } = props;
	const [state, setState] = useState(requiredField);
	const [isTextField, setIsTextField] = useState(!!!requiredField.propertyValue);
	const classes = useStyles(props);
	const { t } = useTranslation();
	let t0;
	if ($[0] !== state) {
		t0 = (key, value, t1) => {
			const merge = t1 === void 0 ? false : t1;
			let updatedState = { ...state };
			if (merge) updatedState = {
				...updatedState,
				...value
			};
			else updatedState[key] = value;
			setState(updatedState);
		};
		$[0] = state;
		$[1] = t0;
	} else t0 = $[1];
	const handleStateChange = t0;
	let t1;
	if ($[2] !== handleStateChange) {
		t1 = (evt) => {
			handleStateChange(evt.target.name, evt.target.value);
		};
		$[2] = handleStateChange;
		$[3] = t1;
	} else t1 = $[3];
	const handleInputChange = t1;
	let t2;
	if ($[4] !== handleStateChange || $[5] !== onRequiredFieldChange || $[6] !== requiredField.id) {
		t2 = (evt_0) => {
			if (evt_0.target.name === "strValue" && !!evt_0.target.value) {
				onRequiredFieldChange(requiredField.id, {
					propertyValue: "",
					strValue: evt_0.target.value
				}, "strValue", true);
				handleStateChange("propertyValue", {
					propertyValue: "",
					strValue: evt_0.target.value
				}, true);
			} else onRequiredFieldChange(requiredField.id, evt_0.target.value, evt_0.target.name);
		};
		$[4] = handleStateChange;
		$[5] = onRequiredFieldChange;
		$[6] = requiredField.id;
		$[7] = t2;
	} else t2 = $[7];
	const handleOnBlur = t2;
	let t3;
	if ($[8] !== handleStateChange || $[9] !== onRequiredFieldChange || $[10] !== requiredField.id) {
		t3 = (value_0) => {
			onRequiredFieldChange(requiredField.id, {
				propertyValue: value_0,
				strValue: ""
			}, "propertyValue", true);
			handleStateChange("propertyValue", {
				propertyValue: value_0,
				strValue: ""
			}, true);
		};
		$[8] = handleStateChange;
		$[9] = onRequiredFieldChange;
		$[10] = requiredField.id;
		$[11] = t3;
	} else t3 = $[11];
	const handleRequiredFieldChange = t3;
	let t4;
	if ($[12] !== isTextField) {
		t4 = () => {
			setIsTextField(!isTextField);
		};
		$[12] = isTextField;
		$[13] = t4;
	} else t4 = $[13];
	const handleButtonClick = t4;
	let field;
	if (isTextField) {
		let t5;
		if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
			t5 = { width: "100%" };
			$[14] = t5;
		} else t5 = $[14];
		let t6;
		if ($[15] !== t) {
			t6 = t("Value");
			$[15] = t;
			$[16] = t6;
		} else t6 = $[16];
		const t7 = state?.strValue || "";
		let t8;
		if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
			t8 = { width: 200 };
			$[17] = t8;
		} else t8 = $[17];
		let t9;
		if ($[18] !== classes.formTextInput || $[19] !== classes.input) {
			t9 = { classes: {
				root: classes.input,
				input: classes.formTextInput
			} };
			$[18] = classes.formTextInput;
			$[19] = classes.input;
			$[20] = t9;
		} else t9 = $[20];
		let t10;
		if ($[21] !== classes.labelRoot) {
			t10 = { classes: { root: classes.labelRoot } };
			$[21] = classes.labelRoot;
			$[22] = t10;
		} else t10 = $[22];
		let t11;
		if ($[23] !== handleInputChange || $[24] !== handleOnBlur || $[25] !== t10 || $[26] !== t6 || $[27] !== t7 || $[28] !== t9) {
			t11 = /* @__PURE__ */ React.createElement("div", { style: t5 }, /* @__PURE__ */ React.createElement(TextField, {
				name: "strValue",
				id: "strValue",
				onChange: handleInputChange,
				onBlur: handleOnBlur,
				label: t6,
				value: t7,
				fullWidth: true,
				variant: "outlined",
				margin: "dense",
				size: "small",
				style: t8,
				InputProps: t9,
				InputLabelProps: t10
			}));
			$[23] = handleInputChange;
			$[24] = handleOnBlur;
			$[25] = t10;
			$[26] = t6;
			$[27] = t7;
			$[28] = t9;
			$[29] = t11;
		} else t11 = $[29];
		field = t11;
	} else {
		let t5;
		if ($[30] === Symbol.for("react.memo_cache_sentinel")) {
			t5 = { width: "100%" };
			$[30] = t5;
		} else t5 = $[30];
		let t6;
		if ($[31] !== t) {
			t6 = t("Value");
			$[31] = t;
			$[32] = t6;
		} else t6 = $[32];
		const t7 = state?.propertyValue || "";
		let t8;
		if ($[33] !== options) {
			t8 = options || [];
			$[33] = options;
			$[34] = t8;
		} else t8 = $[34];
		const t9 = optionLabelDisplayFunction ? "" : "name";
		let t10;
		if ($[35] === Symbol.for("react.memo_cache_sentinel")) {
			t10 = { width: 200 };
			$[35] = t10;
		} else t10 = $[35];
		let t11;
		if ($[36] !== groupBy || $[37] !== handleRequiredFieldChange || $[38] !== optionLabelDisplayFunction || $[39] !== t6 || $[40] !== t7 || $[41] !== t8 || $[42] !== t9) {
			t11 = /* @__PURE__ */ React.createElement("div", { style: t5 }, /* @__PURE__ */ React.createElement(FluentTextFieldAutoComplete, {
				name: "propertyValue",
				id: "propertyValue",
				label: t6,
				onChange: handleRequiredFieldChange,
				optionLabelDisplayFunction,
				value: t7,
				options: t8,
				optionKey: t9,
				groupBy,
				variant: "outlined",
				margin: "dense",
				style: t10
			}));
			$[36] = groupBy;
			$[37] = handleRequiredFieldChange;
			$[38] = optionLabelDisplayFunction;
			$[39] = t6;
			$[40] = t7;
			$[41] = t8;
			$[42] = t9;
			$[43] = t11;
		} else t11 = $[43];
		field = t11;
	}
	const t5 = isTextField ? DropdownIcon : TextFieldIcon;
	let t6;
	if ($[44] !== classes.icon || $[45] !== handleButtonClick || $[46] !== t5) {
		t6 = /* @__PURE__ */ React.createElement(FluentIconButton, {
			className: classes.icon,
			icon: t5,
			onClick: handleButtonClick
		});
		$[44] = classes.icon;
		$[45] = handleButtonClick;
		$[46] = t5;
		$[47] = t6;
	} else t6 = $[47];
	let t7;
	if ($[48] !== classes.requiredFieldContainer || $[49] !== field || $[50] !== t6) {
		t7 = /* @__PURE__ */ React.createElement("div", { className: classes.requiredFieldContainer }, field, t6);
		$[48] = classes.requiredFieldContainer;
		$[49] = field;
		$[50] = t6;
		$[51] = t7;
	} else t7 = $[51];
	let t8;
	if ($[52] !== classes.root || $[53] !== t7) {
		t8 = /* @__PURE__ */ React.createElement("div", { className: classes.root }, t7);
		$[52] = classes.root;
		$[53] = t7;
		$[54] = t8;
	} else t8 = $[54];
	return t8;
};
//#endregion
export { RequiredFieldsMappingField };

//# sourceMappingURL=RequiredFieldsMappingField.mjs.map