import { Form } from "../../utilities/form/Form.mjs";
import { SubmitButton } from "../../utilities/form/SubmitButton.mjs";
import { FormButtons } from "../../utilities/form/FormButtons.mjs";
import { useVirtualActions } from "../../hooks/virtualActions.mjs";
import { c } from "react-compiler-runtime";
import React, { useState } from "react";
import { Typography, makeStyles } from "@material-ui/core";
import PropTypes from "prop-types";
//#region src/UI/forms/VirtualForm.jsx
const useStyles = makeStyles((theme) => ({
	actions: {
		marginTop: theme.spacing(2),
		marginBottom: theme.spacing(2),
		display: "flex",
		flexDirection: "row"
	},
	title: { flexGrow: 1 },
	subject: {
		marginLeft: theme.spacing(1),
		display: "flex",
		flexDirection: "row",
		flexGrow: 1
	},
	switchRoot: { marginLeft: theme.spacing(1) },
	input: {
		height: 34,
		padding: 0
	},
	formTextInput: { fontSize: 13 },
	labelRoot: { fontSize: 13 }
}));
const VirtualForm = (props) => {
	const $ = c(19);
	const { tableDescription, rowValue, closeSideSheet, onCreate, onUpdate } = props;
	const { renderInputByFieldType } = useVirtualActions();
	let t0;
	if ($[0] !== rowValue) {
		t0 = rowValue || {};
		$[0] = rowValue;
		$[1] = t0;
	} else t0 = $[1];
	const [virtualTableFormData] = useState(t0);
	const classes = useStyles();
	let t1;
	if ($[2] !== closeSideSheet || $[3] !== onCreate || $[4] !== onUpdate || $[5] !== rowValue || $[6] !== virtualTableFormData) {
		t1 = async (values) => {
			const newTableData = {
				...virtualTableFormData,
				...values
			};
			if (!rowValue) onCreate && await onCreate(newTableData);
			else onUpdate && await onUpdate(newTableData);
			closeSideSheet && closeSideSheet();
		};
		$[2] = closeSideSheet;
		$[3] = onCreate;
		$[4] = onUpdate;
		$[5] = rowValue;
		$[6] = virtualTableFormData;
		$[7] = t1;
	} else t1 = $[7];
	const handleSubmit = t1;
	let t2;
	if ($[8] !== classes || $[9] !== renderInputByFieldType || $[10] !== tableDescription || $[11] !== virtualTableFormData) {
		t2 = tableDescription?.map((formField, index) => /* @__PURE__ */ React.createElement(React.Fragment, { key: `${formField.name}-${index}` }, /* @__PURE__ */ React.createElement(Typography, {
			variant: "subtitle2",
			style: { marginTop: 8 }
		}, formField.friendlyName), renderInputByFieldType(formField, index, virtualTableFormData, classes)));
		$[8] = classes;
		$[9] = renderInputByFieldType;
		$[10] = tableDescription;
		$[11] = virtualTableFormData;
		$[12] = t2;
	} else t2 = $[12];
	let t3;
	if ($[13] !== t2) {
		t3 = /* @__PURE__ */ React.createElement("div", null, t2);
		$[13] = t2;
		$[14] = t3;
	} else t3 = $[14];
	let t4;
	if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
		t4 = /* @__PURE__ */ React.createElement(FormButtons, null, /* @__PURE__ */ React.createElement(SubmitButton, {
			variant: "contained",
			color: "secondary",
			disablePristine: false,
			disabled: false,
			style: { marginTop: 15 }
		}, "Save"));
		$[15] = t4;
	} else t4 = $[15];
	let t5;
	if ($[16] !== handleSubmit || $[17] !== t3) {
		t5 = /* @__PURE__ */ React.createElement(Form, { onSubmit: handleSubmit }, t3, t4);
		$[16] = handleSubmit;
		$[17] = t3;
		$[18] = t5;
	} else t5 = $[18];
	return t5;
};
VirtualForm.propTypes = {
	closeSideSheet: PropTypes.func,
	onCreate: PropTypes.func,
	onUpdate: PropTypes.func
};
//#endregion
export { VirtualForm };

//# sourceMappingURL=VirtualForm.mjs.map