import { GridStateTypeEnums } from "../../enums/unitySystemEnums.mjs";
//#region src/utilities/aggrid/GridFunctions.js
const useGridFormat = () => {
	const gridFormat = (gridApi, type) => {
		type === "expand" && gridApi.expandAll();
		type === "collapse" && gridApi.collapseAll();
		type === "resize" && gridApi.sizeColumnsToFit();
	};
	return [gridFormat];
};
const useGridClear = () => {
	const gridClear = (gridApi, gridColumnApi) => {
		gridColumnApi.setRowGroupColumns([]);
		gridApi.setFilterModel(null);
		gridApi.setQuickFilter("");
		gridApi.sizeColumnsToFit();
		gridColumnApi.resetColumnState();
	};
	return [gridClear];
};
const useQuickFilter = () => {
	const quickFilter = (gridApi, event) => {
		gridApi.setQuickFilter(event?.target.value);
	};
	return [quickFilter];
};
const useExport = () => {
	const gridExport = (gridApi, type) => {
		type === "excel" && gridApi.exportDataAsExcel();
		type === "csv" && gridApi.exportDataAsCsv();
	};
	return [gridExport];
};
const saveGridState = async (gridId, gridApi, gridColumnApi, execute) => {
	const columnState = gridColumnApi?.getColumnState();
	const columnGroupState = gridColumnApi?.getColumnGroupState();
	const sortModel = gridApi.getSortModel();
	const filterModel = gridApi.getFilterModel();
	const isPivotMode = gridColumnApi.isPivotMode();
	const gridState = [];
	const columnGridConfiguration = {
		gridStateTypeId: GridStateTypeEnums.Column,
		gridId,
		values: JSON.stringify(columnState)
	};
	const columnGroupGridConfiguration = {
		gridStateTypeId: GridStateTypeEnums.Column_Group,
		gridId,
		values: JSON.stringify(columnGroupState)
	};
	const columnSortGridConfiguration = {
		gridStateTypeId: GridStateTypeEnums.Column_Sort,
		gridId,
		values: JSON.stringify(sortModel)
	};
	const columnFilterGridConfiguration = {
		gridStateTypeId: GridStateTypeEnums.Column_Filter,
		gridId,
		values: JSON.stringify(filterModel)
	};
	const pivotGridConfiguration = {
		gridStateTypeId: GridStateTypeEnums.Pivot_Mode,
		gridId,
		values: JSON.stringify(isPivotMode)
	};
	gridState.push(columnGridConfiguration);
	gridState.push(columnGroupGridConfiguration);
	gridState.push(columnSortGridConfiguration);
	gridState.push(columnFilterGridConfiguration);
	gridState.push(pivotGridConfiguration);
	return await execute({ data: gridState });
};
const getGridState = (gridApi, gridColumnApi, gridId) => {
	const columnState = gridColumnApi?.getColumnState();
	const columnGroupState = gridColumnApi?.getColumnGroupState();
	const sortModel = gridApi.getSortModel();
	const filterModel = gridApi.getFilterModel();
	const isPivotMode = gridColumnApi.isPivotMode();
	const gridState = [];
	const columnGridConfiguration = {
		gridStateTypeId: GridStateTypeEnums.Column,
		gridId,
		values: JSON.stringify(columnState)
	};
	const columnGroupGridConfiguration = {
		gridStateTypeId: GridStateTypeEnums.Column_Group,
		gridId,
		values: JSON.stringify(columnGroupState)
	};
	const columnSortGridConfiguration = {
		gridStateTypeId: GridStateTypeEnums.Column_Sort,
		gridId,
		values: JSON.stringify(sortModel)
	};
	const columnFilterGridConfiguration = {
		gridStateTypeId: GridStateTypeEnums.Column_Filter,
		gridId,
		values: JSON.stringify(filterModel)
	};
	const pivotGridConfiguration = {
		gridStateTypeId: GridStateTypeEnums.Pivot_Mode,
		gridId,
		values: JSON.stringify(isPivotMode)
	};
	gridState.push(columnGridConfiguration);
	gridState.push(columnGroupGridConfiguration);
	gridState.push(columnSortGridConfiguration);
	gridState.push(columnFilterGridConfiguration);
	gridState.push(pivotGridConfiguration);
	return gridState;
};
const deleteGridState = async (gridApi, gridColumnApi, deleteGridState) => {
	clearGridState(gridApi, gridColumnApi);
	return await deleteGridState();
};
const clearGridState = (gridApi, gridColumnApi) => {
	gridColumnApi.resetColumnState();
	gridColumnApi.resetColumnGroupState();
	gridApi.setFilterModel({});
	gridApi.setSortModel([]);
	gridColumnApi.setPivotMode(false);
	gridApi.sizeColumnsToFit();
};
const onFirstDataRendered = (gridApi, gridColumnApi, gridStates) => {
	if (gridStates && gridStates.length) gridStates.forEach((state) => {
		switch (state.gridStateTypeId) {
			case GridStateTypeEnums.Column:
				gridColumnApi.setColumnState(JSON.parse(state.values));
				break;
			case GridStateTypeEnums.Column_Group:
				gridColumnApi.setColumnGroupState(JSON.parse(state.values));
				break;
			case GridStateTypeEnums.Pivot_Mode:
				gridColumnApi.setPivotMode(JSON.parse(state.values));
				break;
			case GridStateTypeEnums.Column_Sort:
				gridApi.setSortModel(JSON.parse(state.values));
				break;
			case GridStateTypeEnums.Column_Filter:
				gridApi.setFilterModel(JSON.parse(state.values));
				break;
			default: break;
		}
	});
};
//#endregion
export { clearGridState, deleteGridState, getGridState, onFirstDataRendered, saveGridState, useExport, useGridClear, useGridFormat, useQuickFilter };

//# sourceMappingURL=GridFunctions.mjs.map