import { Field } from "../../../utilities/form/Field.mjs";
import { IconButtonWithTooltip } from "../buttons/IconButtonWithToolTip.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect, useState } from "react";
import { TextField } from "@material-ui/core";
import { AddIcon } from "@fluentui/react-icons";
//#region src/UI/inputs/textField/KeyValueTextField.jsx
const KeyValueTextField = (props) => {
	const $ = c(17);
	const { previousValues, fieldName } = props;
	const [numFields, setNumFields] = useState(1);
	let t0;
	if ($[0] !== numFields) {
		t0 = () => {
			setNumFields(numFields + 1);
		};
		$[0] = numFields;
		$[1] = t0;
	} else t0 = $[1];
	const addField = t0;
	let t1;
	let t2;
	if ($[2] !== previousValues) {
		t1 = () => {
			if (previousValues) {
				const numPrevValues = Object.keys(previousValues).length;
				setNumFields(numPrevValues);
			}
		};
		t2 = [previousValues];
		$[2] = previousValues;
		$[3] = t1;
		$[4] = t2;
	} else {
		t1 = $[3];
		t2 = $[4];
	}
	useEffect(t1, t2);
	let t3;
	if ($[5] !== numFields) {
		t3 = Array.from({ length: numFields });
		$[5] = numFields;
		$[6] = t3;
	} else t3 = $[6];
	let t4;
	if ($[7] !== fieldName || $[8] !== previousValues || $[9] !== t3) {
		t4 = t3.map((_, index) => /* @__PURE__ */ React.createElement("div", {
			key: index,
			style: {
				display: "flex",
				gap: 5
			}
		}, /* @__PURE__ */ React.createElement(Field, {
			component: TextField,
			id: `${fieldName}Key${index + 1}`,
			name: `${fieldName}Key${index + 1}`,
			label: `Parameter Name ${index + 1}`,
			variant: "filled",
			size: "small",
			required: false,
			fullWidth: true,
			initialValue: previousValues && Object.keys(previousValues)[index]
		}), /* @__PURE__ */ React.createElement(Field, {
			component: TextField,
			id: `${fieldName}Value${index + 1}`,
			name: `${fieldName}Value${index + 1}`,
			label: `Value ${index + 1}`,
			variant: "filled",
			size: "small",
			required: false,
			fullWidth: true,
			initialValue: previousValues && Object.values(previousValues)[index]
		})));
		$[7] = fieldName;
		$[8] = previousValues;
		$[9] = t3;
		$[10] = t4;
	} else t4 = $[10];
	let t5;
	if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
		t5 = {
			display: "flex",
			justifyContent: "right"
		};
		$[11] = t5;
	} else t5 = $[11];
	let t6;
	if ($[12] !== addField) {
		t6 = /* @__PURE__ */ React.createElement("div", { style: t5 }, /* @__PURE__ */ React.createElement(IconButtonWithTooltip, {
			icon: AddIcon,
			onClick: addField,
			title: "Add field"
		}));
		$[12] = addField;
		$[13] = t6;
	} else t6 = $[13];
	let t7;
	if ($[14] !== t4 || $[15] !== t6) {
		t7 = /* @__PURE__ */ React.createElement("div", null, t4, t6);
		$[14] = t4;
		$[15] = t6;
		$[16] = t7;
	} else t7 = $[16];
	return t7;
};
//#endregion
export { KeyValueTextField };

//# sourceMappingURL=KeyValueTextField.mjs.map