import { SELECTION_COLUMN } from "./useSelection.js";
import { computed } from "vue";
import { EXPAND_COLUMN } from "@v-c/table";

//#region src/table/hooks/useFilledColumns.ts
function isSpecialColumn(col) {
	return col === SELECTION_COLUMN || col === EXPAND_COLUMN;
}
/**
* Merge a per-column default (typically from ConfigProvider) into every
* non-special column in the tree. Mirrors ant-design 6.4.0 useFilledColumns.
*
* Component-level column props take precedence over the default; defaults only
* fill in missing keys.
*/
function useFilledColumns(columns, column) {
	return computed(() => {
		const defaults = column.value;
		if (!defaults) return columns.value;
		const { children: _ignoredChildren, ...defaultsWithoutChildren } = defaults;
		const fill = (list) => list.map((col) => {
			if (isSpecialColumn(col)) return col;
			if ("children" in col && Array.isArray(col.children)) {
				const group = col;
				return {
					...defaults,
					...group,
					children: fill(group.children)
				};
			}
			return {
				...defaultsWithoutChildren,
				...col
			};
		});
		return fill(columns.value);
	});
}

//#endregion
export { useFilledColumns as default };