import { toLowerFirstChar, toTitleCase } from "../utilities/input/StringUtilities.mjs";
//#region src/dataBrowser/DataBrowserColumnDefs.js
const defaultGridColumn = {
	headerName: "",
	field: "",
	minWidth: 80,
	autoHeight: false,
	sortable: false
};
const DataBrowserColumnDefs = (entityAttributes, actionList, isServerSide, queryColumnsData, columnName = "Actions", crudTableActionRenderName = "actionsRenderer", panelDirection = "right") => {
	const childEntityAttributes = entityAttributes?.reduce((defs, element) => {
		if (element?.extendedProperties?.childEntity) defs.push(element);
		return defs;
	}, []);
	let shownColumns = [];
	let hiddenColumns = [];
	entityAttributes?.forEach((element) => {
		if (!element?.extendedProperties?.childEntity) {
			let matchingColumn = null;
			const matchingColumnIndex = queryColumnsData.findIndex((column) => column.name === element?.name);
			if (matchingColumnIndex >= 0) matchingColumn = queryColumnsData[matchingColumnIndex];
			const childEntity = childEntityAttributes.find((ea) => Object.keys(ea?.extendedProperties?.childEntityAssoc || {}).length && !ea?.extendedProperties?.childEntityAssoc?.UdpType && ea?.name === element?.name && ea?.extendedProperties?.childEntityAssoc.Keys.find((k) => toLowerFirstChar(k).includes(element?.name)));
			let columnHeaderName = toTitleCase(childEntity ? childEntity?.reference : element?.name);
			if (matchingColumn) columnHeaderName = toTitleCase(childEntity ? childEntity?.reference : matchingColumn?.alias || matchingColumn?.name);
			let def = {
				...defaultGridColumn,
				headerName: columnHeaderName,
				field: element?.name.charAt(0).toLowerCase() + element?.name.slice(1),
				hide: !matchingColumn
			};
			if (element?.extendedProperties?.searchable && isServerSide) def = {
				...def,
				filter: "agTextColumnFilter",
				filterParams: {
					suppressAndOrCondition: true,
					filterOptions: [
						"equals",
						"contains",
						"notEqual",
						"greaterThan",
						"lessThan",
						"greaterThanOrEqual",
						"lessThanOrEqual"
					]
				},
				enableRowGroup: true
			};
			if (element?.extendedProperties?.orderable || !isServerSide) def = {
				...def,
				sortable: true
			};
			if (matchingColumn) shownColumns[matchingColumnIndex] = def;
			else hiddenColumns.push(def);
		}
	});
	let columnDefs = shownColumns.concat(hiddenColumns);
	columnDefs.push({
		headerName: crudTableActionRenderName === "actionsRenderer" ? "Actions" : columnName,
		filter: false,
		pinned: panelDirection,
		width: 150,
		maxWidth: 180,
		cellRenderer: crudTableActionRenderName,
		cellRendererParams: { actionList },
		valueGetter: (params) => params.data,
		suppressMenu: true,
		sortable: false,
		cellStyle: {
			display: "flex",
			alignItems: "center"
		}
	});
	return columnDefs;
};
//#endregion
export { DataBrowserColumnDefs };

//# sourceMappingURL=DataBrowserColumnDefs.mjs.map