/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-1ec74b8b.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, h, computed } from '@vue/composition-api';
import baseTableProps from './base-table-props.js';
import primaryTableProps from './primary-table-props.js';
import _BaseTable, { BASE_TABLE_ALL_EVENTS } from './base-table.js';
export { BASE_TABLE_ALL_EVENTS } from './base-table.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import useColumnController from './hooks/useColumnController.js';
import useRowExpand from './hooks/useRowExpand.js';
import useTableHeader, { renderTitle } from './hooks/useTableHeader.js';
import useRowSelect from './hooks/useRowSelect.js';
import useSorter from './hooks/useSorter.js';
import useFilter from './hooks/useFilter.js';
import useAsyncLoading from './hooks/useAsyncLoading.js';
import 'lodash/pick';
import './hooks/useFixed.js';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/get';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../_common/js/utils/getScrollbarWidth.js';
import '../utils/dom.js';
import 'vue';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import './hooks/usePagination.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../pagination/index.js';
import '../pagination/pagination.js';
import '@babel/runtime/helpers/typeof';
import 'tdesign-icons-vue';
import '../config.js';
import '../utils/mixins.js';
import '../config-provider/config-receiver.js';
import '../config-provider/type.js';
import '../input-number/index.js';
import '../input-number/input-number.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import '../button/index.js';
import '../button/button.js';
import '../utils/classnames.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../utils/render-tnode.js';
import 'lodash/isObject';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../loading/type.js';
import '../loading/plugin.js';
import '../button/props.js';
import '../utils/ripple.js';
import '../button/type.js';
import '../input/index.js';
import '../input/addon.js';
import '../input/input.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/helper.js';
import '../utils/event.js';
import '../input/props.js';
import '../input/input-group.js';
import '../utils/map-props.js';
import '../input/type.js';
import '../input-number/props.js';
import '../input-number/type.js';
import '../select/index.js';
import '../select/select.js';
import 'lodash/isFunction';
import 'lodash/debounce';
import 'lodash/set';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../popup/props.js';
import '../popup/container.js';
import '../popup/type.js';
import '../tag/index.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../tag/type.js';
import '../common-components/fake-arrow.js';
import '../select/option.js';
import '../select/option-props.js';
import '../checkbox/index.js';
import '../checkbox/group.js';
import 'lodash/intersection';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/checkbox-group-props.js';
import '../checkbox/type.js';
import '../select/props.js';
import '../select/optionGroup.js';
import '../select/option-group-props.js';
import '../select/type.js';
import '../pagination/props.js';
import '../pagination/type.js';
import '../hooks/useVirtualScroll.js';
import './tbody.js';
import './tr.js';
import 'lodash/upperFirst';
import './utils.js';
import './hooks/useClassName.js';
import './ellipsis.js';
import './hooks/useStyle.js';
import '../hooks/useCommonClassName.js';
import '../affix/index.js';
import '../affix/affix.js';
import '../affix/props.js';
import '../affix/type.js';
import './thead.js';
import './tfoot.js';
import './hooks/useMultiHeader.js';
import 'lodash/isEmpty';
import '../hooks/render-tnode.js';
import '../dialog/plugin.js';
import '../dialog/dialog.js';
import 'lodash/throttle';
import '../dialog/actions.js';
import '../dialog/props.js';
import '../hooks/useDestroyOnClose.js';
import '../hooks/useDefaultValue.js';
import '../radio/index.js';
import '../radio/radio.js';
import '../radio/props.js';
import '../radio/group.js';
import 'lodash/isNumber';
import '../radio/radio-group-props.js';
import '../radio/radio-button.js';
import '../radio/type.js';
import './sorter-button.js';
import '../tooltip/index.js';
import '../tooltip/tooltip.js';
import '../tooltip/props.js';
import '../tooltip/type.js';
import './filter-controller.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var _PrimaryTable = defineComponent({
  name: "TPrimaryTable",
  props: _objectSpread(_objectSpread({}, baseTableProps), primaryTableProps),
  setup: function setup(props, context) {
    var renderTNode = useTNodeJSX();

    var _toRefs = toRefs(props),
        columns = _toRefs.columns;

    var _useColumnController = useColumnController(props, context),
        displayColumnKeys = _useColumnController.displayColumnKeys,
        renderColumnController = _useColumnController.renderColumnController;

    var _useRowExpand = useRowExpand(props, context),
        showExpandedRow = _useRowExpand.showExpandedRow,
        showExpandIconColumn = _useRowExpand.showExpandIconColumn,
        getExpandColumn = _useRowExpand.getExpandColumn,
        renderExpandedRow = _useRowExpand.renderExpandedRow,
        onInnerExpandRowClick = _useRowExpand.onInnerExpandRowClick;

    var _useSorter = useSorter(props, context),
        renderSortIcon = _useSorter.renderSortIcon;

    var _useRowSelect = useRowSelect(props),
        formatToRowSelectColumn = _useRowSelect.formatToRowSelectColumn,
        tRowClassNames = _useRowSelect.tRowClassNames;

    var _useFilter = useFilter(props, context),
        hasEmptyCondition = _useFilter.hasEmptyCondition,
        primaryTableRef = _useFilter.primaryTableRef,
        renderFilterIcon = _useFilter.renderFilterIcon,
        renderFirstFilterRow = _useFilter.renderFirstFilterRow;

    var _useTableHeader = useTableHeader(props),
        renderTitleWidthIcon = _useTableHeader.renderTitleWidthIcon;

    var _useAsyncLoading = useAsyncLoading(props, context),
        renderAsyncLoading = _useAsyncLoading.renderAsyncLoading;

    var getColumns = function getColumns(columns2) {
      var arr = [];

      var _loop = function _loop(i, len) {
        var _item$children, _displayColumnKeys$va, _item$children2, _item$children3;

        var item = _objectSpread({}, columns2[i]);

        var isDisplayColumn = ((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) || ((_displayColumnKeys$va = displayColumnKeys.value) === null || _displayColumnKeys$va === void 0 ? void 0 : _displayColumnKeys$va.includes(item.colKey));
        if (!isDisplayColumn && props.columnController) return "continue";
        item = formatToRowSelectColumn(item);

        if (item.sorter || item.filter) {
          var titleContent = renderTitle(h, context.slots, item, i);

          item.title = function (h2, p) {
            var sortIcon = item.sorter ? renderSortIcon(h2, p) : null;
            var filterIcon = item.filter ? renderFilterIcon(h2, p) : null;
            return renderTitleWidthIcon(h2, [titleContent, sortIcon, filterIcon]);
          };
        }

        if ((_item$children2 = item.children) !== null && _item$children2 !== void 0 && _item$children2.length) {
          item.children = getColumns(item.children);
        }

        if (!item.children || (_item$children3 = item.children) !== null && _item$children3 !== void 0 && _item$children3.length) {
          arr.push(item);
        }
      };

      for (var i = 0, len = columns2.length; i < len; i++) {
        var _ret = _loop(i, len);

        if (_ret === "continue") continue;
      }

      return arr;
    };

    var tColumns = computed(function () {
      var cols = getColumns(columns.value);

      if (showExpandIconColumn.value) {
        cols.unshift(getExpandColumn(h));
      }

      return cols;
    });

    var onInnerPageChange = function onInnerPageChange(pageInfo, newData) {
      var _props$onPageChange, _props$onChange;

      (_props$onPageChange = props.onPageChange) === null || _props$onPageChange === void 0 ? void 0 : _props$onPageChange.call(props, pageInfo, newData);
      context.emit("page-change", pageInfo, newData);
      var changeParams = [{
        pagination: pageInfo
      }, {
        trigger: "pagination",
        currentData: newData
      }];
      (_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call.apply(_props$onChange, [props].concat(changeParams));
      context.emit.apply(context, ["change"].concat(changeParams));
    };

    return {
      tColumns: tColumns,
      showExpandedRow: showExpandedRow,
      tRowClassNames: tRowClassNames,
      hasEmptyCondition: hasEmptyCondition,
      primaryTableRef: primaryTableRef,
      renderTNode: renderTNode,
      renderColumnController: renderColumnController,
      renderExpandedRow: renderExpandedRow,
      onInnerExpandRowClick: onInnerExpandRowClick,
      renderFirstFilterRow: renderFirstFilterRow,
      renderAsyncLoading: renderAsyncLoading,
      onInnerPageChange: onInnerPageChange
    };
  },
  methods: {
    getListener: function getListener() {
      var _this = this;

      var listener = {};
      BASE_TABLE_ALL_EVENTS.forEach(function (key) {
        listener[key] = function () {
          for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
          }

          _this.$emit.apply(_this, [key].concat(args));
        };
      });
      return listener;
    },
    formatNode: function formatNode(api, renderInnerNode, condition) {
      var h = this.$createElement;
      if (!condition) return this[api];
      var innerNode = renderInnerNode(h);
      var propsNode = this.renderTNode(api);
      if (innerNode && !propsNode) return function () {
        return innerNode;
      };
      if (propsNode && !innerNode) return function () {
        return propsNode;
      };

      if (innerNode && propsNode) {
        return function () {
          return h("div", [propsNode, innerNode]);
        };
      }

      return null;
    }
  },
  render: function render() {
    var h = arguments[0];
    var topContent = this.formatNode("topContent", this.renderColumnController, !!this.columnController);
    var firstFullRow = this.formatNode("firstFullRow", this.renderFirstFilterRow, !this.hasEmptyCondition);
    var lastFullRow = this.formatNode("lastFullRow", this.renderAsyncLoading, !!this.asyncLoading);

    var props = _objectSpread(_objectSpread({}, this.$props), {}, {
      rowClassName: this.tRowClassNames,
      columns: this.tColumns,
      renderExpandedRow: this.showExpandedRow ? this.renderExpandedRow : void 0,
      topContent: topContent,
      firstFullRow: firstFullRow,
      lastFullRow: lastFullRow
    });

    var on = _objectSpread(_objectSpread({}, this.getListener()), {}, {
      "page-change": this.onInnerPageChange
    });

    if (this.expandOnRowClick) {
      on["row-click"] = this.onInnerExpandRowClick;
    }

    return h(_BaseTable, helper([{
      "ref": "primaryTableRef",
      "scopedSlots": this.$scopedSlots
    }, {
      "props": props
    }, {}, {
      "on": on
    }, {}, this.$attrs]));
  }
});

export { _PrimaryTable as default };
//# sourceMappingURL=primary-table.js.map
