<script lang="ts">
import { defineComponent, PropType, renderList, createCommentVNode, createVNode, resolveComponent } from 'vue-demi'
import { ElTableColumnCtx } from '@/types/table'

export default defineComponent({
  name: 'TableColumns',
  props: {
    columns: {
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      type: Array as PropType<Array<ElTableColumnCtx<any>>>,
      default: () => []
    }
  },
  setup (props, { attrs }) {
    return () => createVNode(resolveComponent('el-table'), {
      ...attrs
    }, {
      default: () => renderList(props.columns, item => {
        if (item?.show === false) {
          return createCommentVNode('v-if', true)
        }
        return createVNode(resolveComponent('el-table-column'), { ...item })
      })
    })
  }
})
</script>
