import { getSanitizedName } from "../../utilities/entities/entityUtilities.mjs";
import { Typography as Typography$1 } from "../../UI/dataDisplay/typography/Typography.mjs";
import { SideSheet } from "../../UI/surfaces/SideSheet.mjs";
import { StatusChip } from "../../UI/dataDisplay/status/StatusChip.mjs";
import { AmbientCard } from "../../UI/surfaces/cards/AmbientCard/AmbientCard.mjs";
import { LinearProgress as LinearProgress$1 } from "../../UI/loading/LinearProgress.mjs";
import { AmbientAlert } from "../../UI/feedback/AmbientAlert.mjs";
import { EmptyStateDisplay } from "../../UI/dataDisplay/EmptyStateDisplay.mjs";
import { FluentListItem } from "../../UI/dataDisplay/FluentListItem.mjs";
import { VisualSearchObject } from "./VisualSearchObject.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect, useState } from "react";
import { Slide } from "@material-ui/core";
import { useHistory } from "react-router-dom";
import { StatusCircleCheckmarkIcon } from "@fluentui/react-icons";
import { Skeleton } from "@material-ui/lab";
//#region src/udp/export/ExportSidesheet.jsx
const ExportSidesheet = (props) => {
	const $ = c(74);
	const { entity, numRowsToExport, fileFormat, searchObject, errorList, activeExportJob, handleFileDownload, exportSidesheetOpen, handleCloseExportSidesheet, createExport, exportLoading, validSearch } = props;
	const history = useHistory();
	const [page, setPage] = useState("exportSummary");
	let t0;
	if ($[0] !== activeExportJob?.id) {
		t0 = () => {
			if (activeExportJob?.id) setPage("transition");
		};
		$[0] = activeExportJob?.id;
		$[1] = t0;
	} else t0 = $[1];
	const t1 = activeExportJob?.id;
	let t2;
	if ($[2] !== t1) {
		t2 = [t1];
		$[2] = t1;
		$[3] = t2;
	} else t2 = $[3];
	useEffect(t0, t2);
	let t3;
	if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
		t3 = () => {
			setPage("exportProgress");
		};
		$[4] = t3;
	} else t3 = $[4];
	const handleSummaryExited = t3;
	const getJobStatus = _temp;
	let t4;
	if ($[5] !== handleCloseExportSidesheet) {
		t4 = () => {
			setPage("exportSummary");
			handleCloseExportSidesheet();
		};
		$[5] = handleCloseExportSidesheet;
		$[6] = t4;
	} else t4 = $[6];
	const onCloseSidesheet = t4;
	let t5;
	if ($[7] !== history) {
		t5 = () => history.push("/myexports");
		$[7] = history;
		$[8] = t5;
	} else t5 = $[8];
	const t6 = !validSearch || activeExportJob;
	let t7;
	if ($[9] !== errorList) {
		t7 = errorList?.map(_temp2);
		$[9] = errorList;
		$[10] = t7;
	} else t7 = $[10];
	const t8 = page === "exportSummary";
	let t9;
	if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
		t9 = {
			display: "flex",
			flexDirection: "column",
			gap: 10
		};
		$[11] = t9;
	} else t9 = $[11];
	let t10;
	let t11;
	if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
		t10 = /* @__PURE__ */ React.createElement(Typography$1, null, "You are about to export all records from this table using your search criteria.");
		t11 = { marginTop: 16 };
		$[12] = t10;
		$[13] = t11;
	} else {
		t10 = $[12];
		t11 = $[13];
	}
	let t12;
	if ($[14] !== entity) {
		t12 = getSanitizedName(entity);
		$[14] = entity;
		$[15] = t12;
	} else t12 = $[15];
	let t13;
	if ($[16] !== t12) {
		t13 = /* @__PURE__ */ React.createElement(FluentListItem, {
			subject: "Table",
			value: t12
		});
		$[16] = t12;
		$[17] = t13;
	} else t13 = $[17];
	let t14;
	if ($[18] !== numRowsToExport) {
		t14 = numRowsToExport ?? /* @__PURE__ */ React.createElement(Skeleton, {
			width: 40,
			height: 26
		});
		$[18] = numRowsToExport;
		$[19] = t14;
	} else t14 = $[19];
	let t15;
	if ($[20] !== t14) {
		t15 = /* @__PURE__ */ React.createElement(FluentListItem, {
			subject: "Number of Rows",
			value: t14
		});
		$[20] = t14;
		$[21] = t15;
	} else t15 = $[21];
	let t16;
	if ($[22] !== t13 || $[23] !== t15) {
		t16 = /* @__PURE__ */ React.createElement(AmbientCard, {
			title: "Export Summary",
			fullWidth: true,
			removeTopLayoutUnit: true
		}, t10, /* @__PURE__ */ React.createElement("div", { style: t11 }, t13, t15));
		$[22] = t13;
		$[23] = t15;
		$[24] = t16;
	} else t16 = $[24];
	let t17;
	if ($[25] !== searchObject) {
		t17 = /* @__PURE__ */ React.createElement(AmbientCard, {
			title: "Applied Filters",
			fullWidth: true
		}, /* @__PURE__ */ React.createElement(VisualSearchObject, { searchObject }));
		$[25] = searchObject;
		$[26] = t17;
	} else t17 = $[26];
	let t18;
	if ($[27] !== fileFormat) {
		t18 = /* @__PURE__ */ React.createElement(AmbientCard, {
			title: "Export Options",
			fullWidth: true
		}, /* @__PURE__ */ React.createElement(FluentListItem, {
			subject: "File Format",
			value: fileFormat
		}));
		$[27] = fileFormat;
		$[28] = t18;
	} else t18 = $[28];
	let t19;
	if ($[29] !== t16 || $[30] !== t17 || $[31] !== t18) {
		t19 = /* @__PURE__ */ React.createElement("div", { style: t9 }, t16, t17, t18);
		$[29] = t16;
		$[30] = t17;
		$[31] = t18;
		$[32] = t19;
	} else t19 = $[32];
	let t20;
	if ($[33] !== t19 || $[34] !== t8) {
		t20 = /* @__PURE__ */ React.createElement(Slide, {
			in: t8,
			onExited: handleSummaryExited,
			direction: "right",
			unmountOnExit: true,
			appear: false
		}, t19);
		$[33] = t19;
		$[34] = t8;
		$[35] = t20;
	} else t20 = $[35];
	const t21 = page === "exportProgress";
	let t22;
	if ($[36] === Symbol.for("react.memo_cache_sentinel")) {
		t22 = {
			display: "flex",
			flexDirection: "column",
			gap: 10
		};
		$[36] = t22;
	} else t22 = $[36];
	let t23;
	if ($[37] === Symbol.for("react.memo_cache_sentinel")) {
		t23 = /* @__PURE__ */ React.createElement("div", { style: { marginBottom: 25 } }, /* @__PURE__ */ React.createElement(Typography$1, null, "Exports are handled in the background. You can safely close this window."));
		$[37] = t23;
	} else t23 = $[37];
	const t24 = activeExportJob?.id;
	let t25;
	if ($[38] !== t24) {
		t25 = /* @__PURE__ */ React.createElement(FluentListItem, {
			subject: "Job Id",
			value: t24
		});
		$[38] = t24;
		$[39] = t25;
	} else t25 = $[39];
	const t26 = getJobStatus(activeExportJob?.statusId)?.status;
	const t27 = getJobStatus(activeExportJob?.statusId)?.label;
	let t28;
	if ($[40] !== t26 || $[41] !== t27) {
		t28 = /* @__PURE__ */ React.createElement(FluentListItem, {
			subject: "Status",
			value: /* @__PURE__ */ React.createElement(StatusChip, {
				status: t26,
				label: t27
			})
		});
		$[40] = t26;
		$[41] = t27;
		$[42] = t28;
	} else t28 = $[42];
	let t29;
	if ($[43] !== t25 || $[44] !== t28) {
		t29 = /* @__PURE__ */ React.createElement(AmbientCard, {
			title: "Job Details",
			fullWidth: true,
			removeTopLayoutUnit: true
		}, t23, t25, t28);
		$[43] = t25;
		$[44] = t28;
		$[45] = t29;
	} else t29 = $[45];
	const t30 = `Export ${getJobStatus(activeExportJob?.statusId)?.label}`;
	let t31;
	if ($[46] !== activeExportJob?.statusId) {
		t31 = (activeExportJob?.statusId === 1 || activeExportJob?.statusId === 2) && /* @__PURE__ */ React.createElement(LinearProgress$1, null);
		$[46] = activeExportJob?.statusId;
		$[47] = t31;
	} else t31 = $[47];
	let t32;
	if ($[48] !== activeExportJob?.statusId || $[49] !== errorList || $[50] !== handleFileDownload) {
		t32 = activeExportJob?.statusId === 3 && (!errorList.some(_temp3) ? /* @__PURE__ */ React.createElement(EmptyStateDisplay, {
			icon: StatusCircleCheckmarkIcon,
			primaryText: "File is ready!",
			actionLabel: "Download",
			action: handleFileDownload && (() => handleFileDownload())
		}) : /* @__PURE__ */ React.createElement(Typography$1, null, "To download the file, please go to the My Exports page."));
		$[48] = activeExportJob?.statusId;
		$[49] = errorList;
		$[50] = handleFileDownload;
		$[51] = t32;
	} else t32 = $[51];
	let t33;
	if ($[52] !== t30 || $[53] !== t31 || $[54] !== t32) {
		t33 = /* @__PURE__ */ React.createElement(AmbientCard, {
			title: t30,
			fullWidth: true,
			removeTopLayoutUnit: true
		}, t31, t32);
		$[52] = t30;
		$[53] = t31;
		$[54] = t32;
		$[55] = t33;
	} else t33 = $[55];
	let t34;
	if ($[56] !== t29 || $[57] !== t33) {
		t34 = /* @__PURE__ */ React.createElement("div", { style: t22 }, t29, t33);
		$[56] = t29;
		$[57] = t33;
		$[58] = t34;
	} else t34 = $[58];
	let t35;
	if ($[59] !== t21 || $[60] !== t34) {
		t35 = /* @__PURE__ */ React.createElement(Slide, {
			in: t21,
			direction: "left",
			mountOnEnter: true
		}, t34);
		$[59] = t21;
		$[60] = t34;
		$[61] = t35;
	} else t35 = $[61];
	let t36;
	if ($[62] !== t20 || $[63] !== t35 || $[64] !== t7) {
		t36 = /* @__PURE__ */ React.createElement("div", null, t7, t20, t35);
		$[62] = t20;
		$[63] = t35;
		$[64] = t7;
		$[65] = t36;
	} else t36 = $[65];
	let t37;
	if ($[66] !== createExport || $[67] !== exportLoading || $[68] !== exportSidesheetOpen || $[69] !== onCloseSidesheet || $[70] !== t36 || $[71] !== t5 || $[72] !== t6) {
		t37 = /* @__PURE__ */ React.createElement(SideSheet, {
			open: exportSidesheetOpen,
			onClose: onCloseSidesheet,
			width: "50%",
			onSubmit: createExport,
			buttonLabel: "Create Export",
			buttonTwoLabel: "My Exports",
			buttonTwoAction: t5,
			progress: exportLoading,
			buttonOneDisabled: t6
		}, t36);
		$[66] = createExport;
		$[67] = exportLoading;
		$[68] = exportSidesheetOpen;
		$[69] = onCloseSidesheet;
		$[70] = t36;
		$[71] = t5;
		$[72] = t6;
		$[73] = t37;
	} else t37 = $[73];
	return t37;
};
function _temp(value) {
	if (value === 1) return {
		status: null,
		label: "Pending"
	};
	else if (value === 2) return {
		status: "info",
		label: "Running"
	};
	else if (value === 3) return {
		status: "success",
		label: "Completed"
	};
	else if (value === 4) return {
		status: "error",
		label: "Failed"
	};
}
function _temp2(error) {
	return /* @__PURE__ */ React.createElement(AmbientAlert, {
		alertMessage: error.message,
		showAlert: true,
		alertSeverity: error.severity
	});
}
function _temp3(err) {
	return err?.id === "fileResultGet";
}
//#endregion
export { ExportSidesheet };

//# sourceMappingURL=ExportSidesheet.mjs.map