import { h, defineComponent } from 'vue';
import { Table } from '@hwork/ant-design-vue';

function patchColumns(cols) {
  if (!Array.isArray(cols)) return cols;
  return cols.map((col) => {
    if (!col) return col;
    const next = { ...col };
    if (next.ellipsis === undefined) next.ellipsis = true;
    if (Array.isArray(next.children)) next.children = patchColumns(next.children);
    return next;
  });
}

export default defineComponent({
  name: 'ATable',
  inheritAttrs: false,
  setup(_, { attrs, slots }) {
    // 每次渲染时基于最新的 columns 重新打补丁，确保列显示/隐藏等变更能够生效
    return () => {
      const patchedColumns = patchColumns(attrs.columns);
      return h(Table, { ...attrs, columns: patchedColumns }, slots);
    };
  },
});
