import { createVNode as _createVNode } from "vue";
import { defineComponent, inject } from "vue";
import { dataTableContextKey } from "./interface";
import { getColumnClassName, renderTitle } from "./utils";
export default defineComponent({
  props: {
    discrete: Boolean
  },

  setup(props) {
    const {
      props: tableProps,
      leftFixedColumsRef,
      rightFixedColumsRef,
      fixedColumnLeftMapRef,
      fixedColumnRightMapRef
    } = inject(dataTableContextKey);
    return () => {
      const {
        prefixCls,
        columns,
        scrollX,
        virtualScroll
      } = tableProps;

      const theadNode = _createVNode("thead", {
        "class": `${prefixCls}_thead`
      }, [_createVNode("tr", {
        "class": `${prefixCls}_tr`
      }, [columns.map((col, colIndex) => {
        const fixLast = col === leftFixedColumsRef.value[leftFixedColumsRef.value.length - 1],
              rightFirst = col === rightFixedColumsRef.value[0];
        const cls = [`${prefixCls}_th`, getColumnClassName(col, colIndex), col.fixed && `${prefixCls}_th-fix-${col.fixed}`, fixLast && `${prefixCls}_td-fix-left-last`, rightFirst && `${prefixCls}_td-fix-right-first`, col.align && `${prefixCls}_th-align-${col.align}`];
        const style = {
          width: col.width + 'px',
          left: fixedColumnLeftMapRef.value[col.key] + 'px',
          right: fixedColumnRightMapRef.value[col.key] + 'px'
        };
        return _createVNode("th", {
          "class": cls,
          "style": style
        }, [renderTitle(col)]);
      })])]);

      if (!props.discrete) {
        return theadNode;
      }

      const style = [];
      if (virtualScroll) style.push({
        overflowY: 'hidden'
      });
      return _createVNode("div", {
        "class": `${prefixCls}_header`,
        "style": style
      }, [_createVNode("table", {
        "class": `${prefixCls}_table`,
        "style": `width:${scrollX}px`
      }, [theadNode])]);
    };
  }

});