import { Form } from "../../utilities/form/Form.mjs";
import { Field } from "../../utilities/form/Field.mjs";
import { ConfigService } from "../../configService/index.mjs";
import { VisibilityTypeEnums } from "../../enums/unitySystemEnums.mjs";
import { useHandleAxiosSnackbar } from "../../utilities/apiHelpers.mjs";
import { apiMutate } from "../../utilities/useAxiosMutate.mjs";
import { AmbientTextField } from "../inputs/textField/AmbientTextField.mjs";
import { FluentDialog } from "../feedback/FluentDialog.mjs";
import { getGridState } from "../../utilities/aggrid/GridFunctions.mjs";
import { c } from "react-compiler-runtime";
import React, { useRef } from "react";
import { Box, Divider, FormControlLabel, Switch, Typography, makeStyles } from "@material-ui/core";
import PropTypes from "prop-types";
import { useTranslation } from "react-i18next";
//#region src/UI/utilityDisplay/SaveViewFormDialog.jsx
const useStyles = makeStyles((theme) => ({
	root: {},
	saveForm: {
		minWidth: 450,
		paddingLeft: theme.spacing(2),
		paddingRight: theme.spacing(2)
	},
	column: {
		flex: 1,
		paddingLeft: theme.spacing(2),
		paddingRight: theme.spacing(2)
	},
	divider: {
		backgroundColor: "grey",
		color: "grey",
		width: 2,
		height: "100%"
	},
	infoHeader: { color: "grey" }
}));
/**
* @param {PropTypes.InferProps<typeof SaveViewFormDialog.propTypes>} props
*/
const SaveViewFormDialog = (props) => {
	const $ = c(84);
	const { handleErrorSnackbar, handleSuccessSnackbar } = useHandleAxiosSnackbar();
	const { open, handleClose, tenant, application, user, refetchViews, gApi, gcApi, gridId, domain, apiCatalogId } = props;
	const { t } = useTranslation();
	const classes = useStyles(props);
	const saveViewFormRef = useRef(null);
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = () => {
			saveViewFormRef.current.handleSubmit();
		};
		$[0] = t0;
	} else t0 = $[0];
	const triggerSaveView = t0;
	let t1;
	if ($[1] !== apiCatalogId || $[2] !== domain || $[3] !== gApi || $[4] !== gcApi || $[5] !== gridId || $[6] !== handleClose || $[7] !== handleErrorSnackbar || $[8] !== handleSuccessSnackbar || $[9] !== refetchViews || $[10] !== t || $[11] !== user?.currentTenantId || $[12] !== user?.id) {
		t1 = async (values) => {
			const data = {
				data: {
					gridView: {
						Name: values.name,
						GridViewVisibilityTypeId: values.private ? VisibilityTypeEnums.Private : VisibilityTypeEnums.Public,
						isDefault: 0,
						tenantId: user?.currentTenantId,
						userId: user?.id,
						gridId,
						domain,
						apiCatalogId
					},
					gridConfigurations: getGridState(gApi, gcApi, gridId)
				},
				method: "POST"
			};
			handleClose();
			await apiMutate(ConfigService.tenantV2ApiUrl, "GridView/createGridView", data).then((response) => {
				handleSuccessSnackbar(t("View Saved"));
				refetchViews();
			}).catch((error) => {
				console.log(error);
				handleErrorSnackbar(error, t("Failed to Save View"));
			});
		};
		$[1] = apiCatalogId;
		$[2] = domain;
		$[3] = gApi;
		$[4] = gcApi;
		$[5] = gridId;
		$[6] = handleClose;
		$[7] = handleErrorSnackbar;
		$[8] = handleSuccessSnackbar;
		$[9] = refetchViews;
		$[10] = t;
		$[11] = user?.currentTenantId;
		$[12] = user?.id;
		$[13] = t1;
	} else t1 = $[13];
	const saveView = t1;
	let t2;
	if ($[14] !== t) {
		t2 = t("Save New View");
		$[14] = t;
		$[15] = t2;
	} else t2 = $[15];
	let t3;
	if ($[16] !== t) {
		t3 = t("Save View");
		$[16] = t;
		$[17] = t3;
	} else t3 = $[17];
	let t4;
	if ($[18] !== t) {
		t4 = t("Cancel");
		$[18] = t;
		$[19] = t4;
	} else t4 = $[19];
	const t5 = classes.column;
	const t6 = classes.infoHeader;
	let t7;
	if ($[20] !== t) {
		t7 = t("Tenant");
		$[20] = t;
		$[21] = t7;
	} else t7 = $[21];
	let t8;
	if ($[22] !== classes.infoHeader || $[23] !== t7) {
		t8 = /* @__PURE__ */ React.createElement(Typography, {
			className: t6,
			align: "left"
		}, t7);
		$[22] = classes.infoHeader;
		$[23] = t7;
		$[24] = t8;
	} else t8 = $[24];
	const t9 = tenant ?? "--";
	let t10;
	if ($[25] !== t9) {
		t10 = /* @__PURE__ */ React.createElement(Typography, {
			variant: "subtitle2",
			align: "left"
		}, t9);
		$[25] = t9;
		$[26] = t10;
	} else t10 = $[26];
	let t11;
	if ($[27] !== classes.column || $[28] !== t10 || $[29] !== t8) {
		t11 = /* @__PURE__ */ React.createElement("div", { className: t5 }, t8, t10);
		$[27] = classes.column;
		$[28] = t10;
		$[29] = t8;
		$[30] = t11;
	} else t11 = $[30];
	let t12;
	if ($[31] === Symbol.for("react.memo_cache_sentinel")) {
		t12 = /* @__PURE__ */ React.createElement(Divider, {
			flexItem: true,
			orientation: "vertical"
		});
		$[31] = t12;
	} else t12 = $[31];
	const t13 = classes.column;
	const t14 = classes.infoHeader;
	let t15;
	if ($[32] !== t) {
		t15 = t("Application");
		$[32] = t;
		$[33] = t15;
	} else t15 = $[33];
	let t16;
	if ($[34] !== classes.infoHeader || $[35] !== t15) {
		t16 = /* @__PURE__ */ React.createElement(Typography, {
			className: t14,
			align: "left"
		}, t15);
		$[34] = classes.infoHeader;
		$[35] = t15;
		$[36] = t16;
	} else t16 = $[36];
	const t17 = application ?? "--";
	let t18;
	if ($[37] !== t17) {
		t18 = /* @__PURE__ */ React.createElement(Typography, {
			variant: "subtitle2",
			align: "left"
		}, t17);
		$[37] = t17;
		$[38] = t18;
	} else t18 = $[38];
	let t19;
	if ($[39] !== classes.column || $[40] !== t16 || $[41] !== t18) {
		t19 = /* @__PURE__ */ React.createElement("div", { className: t13 }, t16, t18);
		$[39] = classes.column;
		$[40] = t16;
		$[41] = t18;
		$[42] = t19;
	} else t19 = $[42];
	let t20;
	if ($[43] === Symbol.for("react.memo_cache_sentinel")) {
		t20 = /* @__PURE__ */ React.createElement(Divider, {
			flexItem: true,
			orientation: "vertical"
		});
		$[43] = t20;
	} else t20 = $[43];
	const t21 = classes.column;
	const t22 = classes.infoHeader;
	let t23;
	if ($[44] !== t) {
		t23 = t("Entity");
		$[44] = t;
		$[45] = t23;
	} else t23 = $[45];
	let t24;
	if ($[46] !== classes.infoHeader || $[47] !== t23) {
		t24 = /* @__PURE__ */ React.createElement(Typography, {
			className: t22,
			align: "left"
		}, t23);
		$[46] = classes.infoHeader;
		$[47] = t23;
		$[48] = t24;
	} else t24 = $[48];
	const t25 = domain ?? "--";
	let t26;
	if ($[49] !== t25) {
		t26 = /* @__PURE__ */ React.createElement(Typography, {
			variant: "subtitle2",
			align: "left"
		}, t25);
		$[49] = t25;
		$[50] = t26;
	} else t26 = $[50];
	let t27;
	if ($[51] !== classes.column || $[52] !== t24 || $[53] !== t26) {
		t27 = /* @__PURE__ */ React.createElement("div", { className: t21 }, t24, t26);
		$[51] = classes.column;
		$[52] = t24;
		$[53] = t26;
		$[54] = t27;
	} else t27 = $[54];
	let t28;
	if ($[55] !== t11 || $[56] !== t19 || $[57] !== t27) {
		t28 = /* @__PURE__ */ React.createElement(Box, { display: "flex" }, t11, t12, t19, t20, t27);
		$[55] = t11;
		$[56] = t19;
		$[57] = t27;
		$[58] = t28;
	} else t28 = $[58];
	const t29 = classes.saveForm;
	let t30;
	if ($[59] !== t) {
		t30 = t("Name");
		$[59] = t;
		$[60] = t30;
	} else t30 = $[60];
	let t31;
	if ($[61] === Symbol.for("react.memo_cache_sentinel")) {
		t31 = {
			marginBottom: 20,
			marginTop: 10
		};
		$[61] = t31;
	} else t31 = $[61];
	let t32;
	if ($[62] !== t30) {
		t32 = /* @__PURE__ */ React.createElement(Field, {
			type: "text",
			component: AmbientTextField,
			name: "name",
			id: "name",
			label: t30,
			fullWidth: true,
			required: true,
			style: t31
		});
		$[62] = t30;
		$[63] = t32;
	} else t32 = $[63];
	let t33;
	if ($[64] === Symbol.for("react.memo_cache_sentinel")) {
		t33 = /* @__PURE__ */ React.createElement(Field, {
			component: Switch,
			name: "private",
			id: "private",
			defaultValue: false,
			type: "checkbox"
		});
		$[64] = t33;
	} else t33 = $[64];
	let t34;
	if ($[65] !== t) {
		t34 = t("Private");
		$[65] = t;
		$[66] = t34;
	} else t34 = $[66];
	let t35;
	if ($[67] !== t34) {
		t35 = /* @__PURE__ */ React.createElement(FormControlLabel, {
			control: t33,
			label: t34,
			labelPlacement: "end"
		});
		$[67] = t34;
		$[68] = t35;
	} else t35 = $[68];
	let t36;
	if ($[69] !== saveView || $[70] !== t32 || $[71] !== t35) {
		t36 = /* @__PURE__ */ React.createElement(Form, {
			onSubmit: saveView,
			ref: saveViewFormRef
		}, t32, t35);
		$[69] = saveView;
		$[70] = t32;
		$[71] = t35;
		$[72] = t36;
	} else t36 = $[72];
	let t37;
	if ($[73] !== classes.saveForm || $[74] !== t36) {
		t37 = /* @__PURE__ */ React.createElement("div", { className: t29 }, t36);
		$[73] = classes.saveForm;
		$[74] = t36;
		$[75] = t37;
	} else t37 = $[75];
	let t38;
	if ($[76] !== handleClose || $[77] !== open || $[78] !== t2 || $[79] !== t28 || $[80] !== t3 || $[81] !== t37 || $[82] !== t4) {
		t38 = /* @__PURE__ */ React.createElement(FluentDialog, {
			title: t2,
			open,
			handleClose,
			labelOne: t3,
			labelTwo: t4,
			actionOne: triggerSaveView,
			actionTwo: handleClose
		}, t28, t37);
		$[76] = handleClose;
		$[77] = open;
		$[78] = t2;
		$[79] = t28;
		$[80] = t3;
		$[81] = t37;
		$[82] = t4;
		$[83] = t38;
	} else t38 = $[83];
	return t38;
};
SaveViewFormDialog.propTypes = {
	open: PropTypes.bool.isRequired,
	handleClose: PropTypes.func.isRequired,
	tenant: PropTypes.string,
	application: PropTypes.string,
	entity: PropTypes.string,
	user: PropTypes.object,
	columnDefsValues: PropTypes.array,
	refetchViews: PropTypes.func,
	gApi: PropTypes.object,
	gcApi: PropTypes.object,
	setSelectedView: PropTypes.func
};
//#endregion
export { SaveViewFormDialog };

//# sourceMappingURL=SaveViewFormDialog.mjs.map