import { getSanitizedName } from "../../utilities/entities/entityUtilities.mjs";
import { IconRenderer } from "../../UI/templates/ui/renderers/IconRenderer.mjs";
import { AmbientCard } from "../../UI/surfaces/cards/AmbientCard/AmbientCard.mjs";
import { AgTable, useAgGridApi } from "../../utilities/aggrid/AgTable.mjs";
import { formatDateToLocaleString } from "../../utilities/input/DateUtilities.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect, useState } from "react";
import { LinearProgress, Typography } from "@material-ui/core";
import { DateTime } from "luxon";
//#region src/inquiry/dashboard/RecentlyLoadedNodesTable.jsx
const defaultColDef = {
	resizable: true,
	editable: false,
	sortable: true,
	filter: true
};
const RecentlyLoadedNodesTable = (props) => {
	const $ = c(25);
	const { recentlyLoadedNodes, loading, onLoadedNodeClick, tableHeight, tree, columnDefs, hideTitle: t0 } = props;
	const hideTitle = t0 === void 0 ? false : t0;
	const { gridApi, gridColumnApi, onGridReady } = useAgGridApi();
	const [, setSelectedRow] = useState();
	let t1;
	let t2;
	if ($[0] !== gridApi || $[1] !== gridColumnApi) {
		t1 = () => {
			if (!gridColumnApi) return;
			gridApi?.sizeColumnsToFit();
			setSelectedRow(gridApi?.getSelectedRows().length && gridApi.getSelectedRows()[0]);
		};
		t2 = [gridColumnApi, gridApi];
		$[0] = gridApi;
		$[1] = gridColumnApi;
		$[2] = t1;
		$[3] = t2;
	} else {
		t1 = $[2];
		t2 = $[3];
	}
	useEffect(t1, t2);
	let t3;
	if ($[4] !== gridApi || $[5] !== onLoadedNodeClick) {
		t3 = (event) => {
			if (!event.node.selected) return;
			if (!gridApi) return;
			const selectedRowData = gridApi.getSelectedRows().length && gridApi.getSelectedRows()[0];
			if (!selectedRowData) return;
			setSelectedRow(selectedRowData);
			if (selectedRowData?.nodeInfo) onLoadedNodeClick(selectedRowData.nodeInfo);
		};
		$[4] = gridApi;
		$[5] = onLoadedNodeClick;
		$[6] = t3;
	} else t3 = $[6];
	const handleRowSelected = t3;
	const getterRowData = _temp;
	let t4;
	if ($[7] !== columnDefs || $[8] !== tree?.treeStructure) {
		t4 = columnDefs ? columnDefs : [
			tree?.treeStructure && {
				headerName: "",
				cellRenderer: "iconRenderer",
				valueGetter: getterRowData,
				maxWidth: 60,
				resizable: false,
				suppressMenu: true,
				sortable: false,
				cellStyle: {
					display: "flex",
					alignItems: "center",
					justifyContent: "center"
				}
			},
			{
				headerName: "Name",
				field: "name",
				minWidth: 120,
				maxWidth: 300
			},
			{
				headerName: "Type",
				field: "type",
				valueGetter: _temp2,
				minWidth: 80
			},
			{
				headerName: "Date Loaded",
				field: "dateLoaded",
				minWidth: 80
			},
			{
				headerName: "",
				field: "nodeInfo",
				maxWidth: 0,
				cellStyle: { display: "none" }
			}
		];
		$[7] = columnDefs;
		$[8] = tree?.treeStructure;
		$[9] = t4;
	} else t4 = $[9];
	const columnDefinitions = t4;
	let t5;
	if ($[10] !== recentlyLoadedNodes || $[11] !== tree?.treeStructure) {
		t5 = recentlyLoadedNodes?.map((loadedNode) => {
			return {
				iconData: (tree?.treeStructure?.find((node) => node.properties.catalogReturnObject === loadedNode?.nodeDetails?.catalogReturnObject))?.properties?.defaultIcon || { name: "PictureTileIcon" },
				name: loadedNode?.nodeDetails?.nodeLabel,
				type: loadedNode?.nodeDetails?.catalogReturnObject,
				dateLoaded: formatDateToLocaleString(loadedNode?.dateLoaded, DateTime.DATETIME_MED),
				nodeInfo: loadedNode
			};
		});
		$[10] = recentlyLoadedNodes;
		$[11] = tree?.treeStructure;
		$[12] = t5;
	} else t5 = $[12];
	const recentlyLoadedNodesValues = t5;
	const t6 = !hideTitle ? "Recently Loaded" : " ";
	let t7;
	if ($[13] !== columnDefinitions || $[14] !== handleRowSelected || $[15] !== loading || $[16] !== onGridReady || $[17] !== recentlyLoadedNodes?.length || $[18] !== recentlyLoadedNodesValues || $[19] !== tableHeight || $[20] !== tree) {
		t7 = loading || !tree ? /* @__PURE__ */ React.createElement(LinearProgress, null) : recentlyLoadedNodes?.length ? /* @__PURE__ */ React.createElement(AgTable, {
			columnDefs: columnDefinitions,
			defaultColDef,
			rowData: recentlyLoadedNodesValues || [],
			onGridReady,
			getRowNodeId: _temp3,
			onRowSelected: handleRowSelected,
			rowSelection: "single",
			frameworkComponents: { iconRenderer: IconRenderer },
			height: tableHeight
		}) : /* @__PURE__ */ React.createElement(Typography, null, "No Data Recently Loaded.");
		$[13] = columnDefinitions;
		$[14] = handleRowSelected;
		$[15] = loading;
		$[16] = onGridReady;
		$[17] = recentlyLoadedNodes?.length;
		$[18] = recentlyLoadedNodesValues;
		$[19] = tableHeight;
		$[20] = tree;
		$[21] = t7;
	} else t7 = $[21];
	let t8;
	if ($[22] !== t6 || $[23] !== t7) {
		t8 = /* @__PURE__ */ React.createElement(AmbientCard, {
			title: t6,
			fullWidth: true,
			noAdornment: true
		}, t7);
		$[22] = t6;
		$[23] = t7;
		$[24] = t8;
	} else t8 = $[24];
	return t8;
};
function _temp(params) {
	return params.data?.iconData;
}
function _temp2(params_0) {
	return getSanitizedName(params_0.data?.type);
}
function _temp3(row) {
	return row.name;
}
//#endregion
export { RecentlyLoadedNodesTable };

//# sourceMappingURL=RecentlyLoadedNodesTable.mjs.map