import type { Ref } from 'vue'; import type { TransformColumns, ColumnTitleProps, ColumnsType } from '../interface'; import { renderColumnTitle } from '../util'; function fillTitle( columns: ColumnsType, columnTitleProps: ColumnTitleProps, ) { return columns.map(column => { const cloneColumn = { ...column }; cloneColumn.title = renderColumnTitle(cloneColumn.title, columnTitleProps); if ('children' in cloneColumn) { cloneColumn.children = fillTitle(cloneColumn.children, columnTitleProps); } return cloneColumn; }); } export default function useTitleColumns( columnTitleProps: Ref>, ): [TransformColumns] { const filledColumns = (columns: ColumnsType) => fillTitle(columns, columnTitleProps.value); return [filledColumns]; }