import { Form } from "../../../../utilities/form/Form.mjs";
import { SubmitButton } from "../../../../utilities/form/SubmitButton.mjs";
import { FormButtons } from "../../../../utilities/form/FormButtons.mjs";
import { useUser } from "../../../../utilities/auth/useUser.mjs";
import { UserFormFields } from "./UserFormFields.mjs";
import { c } from "react-compiler-runtime";
import React, { useState } from "react";
import { Divider, makeStyles } from "@material-ui/core";
//#region src/shell/ui/user/form/UserForm.jsx
const useStyles = makeStyles((theme) => ({
	divider: {
		marginTop: theme.spacing(2),
		marginBottom: theme.spacing(2)
	},
	loadingBar: {
		bottom: theme.spacing(-2),
		marginLeft: theme.spacing(-2),
		marginRight: theme.spacing(-2)
	}
}));
const UserForm = (props) => {
	const $ = c(23);
	const { editedUser, rolesData, showRolesField: t0, submitUser, updateCreatedUser, formLoading, altFieldMapping } = props;
	const showRolesField = t0 === void 0 ? true : t0;
	const classes = useStyles();
	const user = useUser();
	const [passwordType, setPasswordType] = useState("autoGeneratePassword");
	const [creationMethod, setCreationMethod] = useState("standard");
	let t1;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t1 = (event) => {
			setPasswordType(event.target.value);
		};
		$[0] = t1;
	} else t1 = $[0];
	const handlePasswordTypeChange = t1;
	let t2;
	if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
		t2 = (event_0) => {
			setCreationMethod(event_0.target.value);
		};
		$[1] = t2;
	} else t2 = $[1];
	const handleCreationMethodChange = t2;
	let t3;
	if ($[2] !== editedUser || $[3] !== passwordType || $[4] !== submitUser || $[5] !== updateCreatedUser) {
		t3 = (values) => {
			if (submitUser) {
				if (passwordType === "autoGeneratePassword") values.passwordProfile = null;
				updateCreatedUser && editedUser ? updateCreatedUser(values) : submitUser(values);
			}
		};
		$[2] = editedUser;
		$[3] = passwordType;
		$[4] = submitUser;
		$[5] = updateCreatedUser;
		$[6] = t3;
	} else t3 = $[6];
	const handleSubmitUser = t3;
	let t4;
	if ($[7] !== altFieldMapping || $[8] !== creationMethod || $[9] !== editedUser || $[10] !== passwordType || $[11] !== rolesData || $[12] !== showRolesField) {
		t4 = /* @__PURE__ */ React.createElement(UserFormFields, {
			rolesData,
			editedUser,
			showRolesField,
			handlePasswordTypeChange,
			passwordType,
			handleCreationMethodChange,
			creationMethod,
			altFieldMapping
		});
		$[7] = altFieldMapping;
		$[8] = creationMethod;
		$[9] = editedUser;
		$[10] = passwordType;
		$[11] = rolesData;
		$[12] = showRolesField;
		$[13] = t4;
	} else t4 = $[13];
	let t5;
	if ($[14] !== classes || $[15] !== editedUser || $[16] !== formLoading || $[17] !== user.can.CAN_MANAGE_USERS) {
		t5 = user.can.CAN_MANAGE_USERS && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: classes.divider }, /* @__PURE__ */ React.createElement(Divider, null)), /* @__PURE__ */ React.createElement(FormButtons, null, /* @__PURE__ */ React.createElement(SubmitButton, {
			variant: "contained",
			color: "primary",
			disablePristine: false,
			disabled: formLoading
		}, editedUser ? "Update" : "Create")));
		$[14] = classes;
		$[15] = editedUser;
		$[16] = formLoading;
		$[17] = user.can.CAN_MANAGE_USERS;
		$[18] = t5;
	} else t5 = $[18];
	let t6;
	if ($[19] !== handleSubmitUser || $[20] !== t4 || $[21] !== t5) {
		t6 = /* @__PURE__ */ React.createElement(Form, { onSubmit: handleSubmitUser }, t4, t5);
		$[19] = handleSubmitUser;
		$[20] = t4;
		$[21] = t5;
		$[22] = t6;
	} else t6 = $[22];
	return t6;
};
//#endregion
export { UserForm };

//# sourceMappingURL=UserForm.mjs.map