import { useUdpExport } from "../../../udp/export/useUdpExport.mjs";
import { ExportSidesheet } from "../../../udp/export/ExportSidesheet.mjs";
import { c } from "react-compiler-runtime";
import React, { forwardRef, useImperativeHandle, useRef, useState } from "react";
import { ApiMethodInstanceGrid } from "udp-react-stencil-component-library";
//#region src/UI/templates/newGrid/BackwardsCompatibleGrid.jsx
const BackwardsCompatibleGrid = forwardRef((props, ref) => {
	const $ = c(59);
	const { gridBarTitle, queryId, gridId, primaryActionOnClick, primaryActionLabel, primaryActionIcon, defaultSearchObject, renderConfigs, disableGridPersistance, enableCheckboxOnColumns, gridHeight } = props;
	const [exportSidesheetOpen, setExportSidesheetOpen] = useState(false);
	const gridApiRef = useRef(null);
	let t0;
	if ($[0] !== defaultSearchObject) {
		t0 = {
			filterElements: defaultSearchObject,
			logicalSearchOperator: 1
		};
		$[0] = defaultSearchObject;
		$[1] = t0;
	} else t0 = $[1];
	const fullDefaultSearchObject = t0;
	const initialColumns = renderConfigs;
	let t1;
	if ($[2] !== initialColumns) {
		t1 = initialColumns.map(_temp);
		$[2] = initialColumns;
		$[3] = t1;
	} else t1 = $[3];
	const columnOverrides = t1;
	let t2;
	bb0: {
		if (primaryActionIcon === "add32") {
			t2 = "add";
			break bb0;
		}
		t2 = void 0;
	}
	const sizedIcon = t2;
	const { updateExportParameters, createExport, entity, searchObject, fileFormat, numRowsToExport, validSearch, errorList, activeExportJob, exportLoading, handleFileDownload, clearParameters } = useUdpExport();
	let t3;
	if ($[4] !== updateExportParameters) {
		t3 = (searchObject_0, entityName) => {
			if (searchObject_0 && entityName) {
				updateExportParameters(entityName, searchObject_0);
				setExportSidesheetOpen(true);
			} else console.error("Failed to retrieve searchObject or entityName from grid");
		};
		$[4] = updateExportParameters;
		$[5] = t3;
	} else t3 = $[5];
	const exportFromGrid = t3;
	let t4;
	if ($[6] !== clearParameters) {
		t4 = () => {
			setExportSidesheetOpen(false);
			clearParameters();
		};
		$[6] = clearParameters;
		$[7] = t4;
	} else t4 = $[7];
	const handleCloseExportSidesheet = t4;
	let t5;
	if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
		t5 = () => ({
			refreshOnNoResults: () => gridApiRef.current?.refreshServerSide(),
			getSelectedRows: () => gridApiRef.current?.getSelectedRows()
		});
		$[8] = t5;
	} else t5 = $[8];
	useImperativeHandle(ref, t5);
	let t6;
	if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
		t6 = (api) => {
			gridApiRef.current = api;
		};
		$[9] = t6;
	} else t6 = $[9];
	const handleGridApiCallback = t6;
	let t7;
	if ($[10] !== activeExportJob || $[11] !== createExport || $[12] !== entity || $[13] !== errorList || $[14] !== exportLoading || $[15] !== exportSidesheetOpen || $[16] !== fileFormat || $[17] !== handleCloseExportSidesheet || $[18] !== handleFileDownload || $[19] !== numRowsToExport || $[20] !== searchObject || $[21] !== validSearch) {
		t7 = /* @__PURE__ */ React.createElement(ExportSidesheet, {
			entity,
			searchObject,
			fileFormat,
			numRowsToExport,
			errorList,
			activeExportJob,
			handleFileDownload,
			exportSidesheetOpen,
			handleCloseExportSidesheet,
			createExport,
			exportLoading,
			validSearch
		});
		$[10] = activeExportJob;
		$[11] = createExport;
		$[12] = entity;
		$[13] = errorList;
		$[14] = exportLoading;
		$[15] = exportSidesheetOpen;
		$[16] = fileFormat;
		$[17] = handleCloseExportSidesheet;
		$[18] = handleFileDownload;
		$[19] = numRowsToExport;
		$[20] = searchObject;
		$[21] = validSearch;
		$[22] = t7;
	} else t7 = $[22];
	let t8;
	if ($[23] !== enableCheckboxOnColumns) {
		t8 = enableCheckboxOnColumns && {
			mode: "multiRow",
			enableClickSelection: true,
			headerCheckbox: false
		};
		$[23] = enableCheckboxOnColumns;
		$[24] = t8;
	} else t8 = $[24];
	let t9;
	if ($[25] !== t8) {
		t9 = {
			pagination: true,
			rowSelection: t8
		};
		$[25] = t8;
		$[26] = t9;
	} else t9 = $[26];
	let t10;
	if ($[27] !== primaryActionLabel || $[28] !== primaryActionOnClick || $[29] !== sizedIcon) {
		t10 = {
			label: primaryActionLabel,
			iconName: sizedIcon,
			onClick: primaryActionOnClick
		};
		$[27] = primaryActionLabel;
		$[28] = primaryActionOnClick;
		$[29] = sizedIcon;
		$[30] = t10;
	} else t10 = $[30];
	let t11;
	if ($[31] !== gridBarTitle || $[32] !== t10) {
		t11 = {
			title: gridBarTitle,
			primaryActionButton: t10
		};
		$[31] = gridBarTitle;
		$[32] = t10;
		$[33] = t11;
	} else t11 = $[33];
	let t12;
	let t13;
	let t14;
	let t15;
	if ($[34] === Symbol.for("react.memo_cache_sentinel")) {
		t12 = { name: "agGridExport" };
		t13 = { name: "openSavedViews" };
		t14 = { name: "agGridSizeColumnsToFit" };
		t15 = { name: "agGridAutoSizeColumns" };
		$[34] = t12;
		$[35] = t13;
		$[36] = t14;
		$[37] = t15;
	} else {
		t12 = $[34];
		t13 = $[35];
		t14 = $[36];
		t15 = $[37];
	}
	let t16;
	if ($[38] !== disableGridPersistance) {
		t16 = !disableGridPersistance && { name: "restoreGridState" };
		$[38] = disableGridPersistance;
		$[39] = t16;
	} else t16 = $[39];
	let t17;
	let t18;
	if ($[40] === Symbol.for("react.memo_cache_sentinel")) {
		t17 = { name: "agGridHideShowColumns" };
		t18 = { name: "agGridResetColumns" };
		$[40] = t17;
		$[41] = t18;
	} else {
		t17 = $[40];
		t18 = $[41];
	}
	let t19;
	if ($[42] !== exportFromGrid) {
		t19 = {
			name: "udpExport",
			params: { callback: (searchObject_1, entityName_0) => exportFromGrid(searchObject_1, entityName_0) }
		};
		$[42] = exportFromGrid;
		$[43] = t19;
	} else t19 = $[43];
	let t20;
	if ($[44] !== t16 || $[45] !== t19) {
		t20 = [
			t12,
			t13,
			t14,
			t15,
			t16,
			t17,
			t18,
			t19
		];
		$[44] = t16;
		$[45] = t19;
		$[46] = t20;
	} else t20 = $[46];
	let t21;
	if ($[47] !== columnOverrides || $[48] !== fullDefaultSearchObject || $[49] !== gridHeight || $[50] !== gridId || $[51] !== queryId || $[52] !== t11 || $[53] !== t20 || $[54] !== t9) {
		t21 = /* @__PURE__ */ React.createElement(ApiMethodInstanceGrid, {
			apiMethodInstanceId: queryId,
			gridId,
			defaultSearchObject: fullDefaultSearchObject,
			columnDefOverrides: columnOverrides,
			gridHeight,
			gridOptions: t9,
			gridHeaderConfig: t11,
			gridFunctions: t20,
			gridApiCallback: handleGridApiCallback
		});
		$[47] = columnOverrides;
		$[48] = fullDefaultSearchObject;
		$[49] = gridHeight;
		$[50] = gridId;
		$[51] = queryId;
		$[52] = t11;
		$[53] = t20;
		$[54] = t9;
		$[55] = t21;
	} else t21 = $[55];
	let t22;
	if ($[56] !== t21 || $[57] !== t7) {
		t22 = /* @__PURE__ */ React.createElement("div", null, t7, t21);
		$[56] = t21;
		$[57] = t7;
		$[58] = t22;
	} else t22 = $[58];
	return t22;
});
BackwardsCompatibleGrid.displayName = "BackwardsCompatibleGrid";
function _temp(col) {
	const { rendererName, ...rest } = col;
	return {
		...rest,
		...rendererName && { cellRenderer: rendererName }
	};
}
//#endregion
export { BackwardsCompatibleGrid };

//# sourceMappingURL=BackwardsCompatibleGrid.mjs.map