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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var helper = require('../_chunks/dep-33ee4bce.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var table_baseTableProps = require('./base-table-props.js');
var table_primaryTableProps = require('./primary-table-props.js');
var table_baseTable = require('./base-table.js');
var hooks_tnode = require('../hooks/tnode.js');
var table_hooks_useColumnController = require('./hooks/useColumnController.js');
var table_hooks_useRowExpand = require('./hooks/useRowExpand.js');
var table_hooks_useTableHeader = require('./hooks/useTableHeader.js');
var table_hooks_useRowSelect = require('./hooks/useRowSelect.js');
var table_hooks_useSorter = require('./hooks/useSorter.js');
var table_hooks_useFilter = require('./hooks/useFilter.js');
var table_hooks_useAsyncLoading = require('./hooks/useAsyncLoading.js');
require('lodash/pick');
require('./hooks/useFixed.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/get');
require('../_common/js/log/log.js');
require('../_common/js/utils/getScrollbarWidth.js');
require('../utils/dom.js');
require('vue');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('./hooks/usePagination.js');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../pagination/index.js');
require('../pagination/pagination.js');
require('@babel/runtime/helpers/typeof');
require('tdesign-icons-vue');
require('../config.js');
require('../utils/mixins.js');
require('../config-provider/config-receiver.js');
require('../input-number/index.js');
require('../input-number/input-number.js');
require('@babel/runtime/helpers/asyncToGenerator');
require('@babel/runtime/regenerator');
require('../button/index.js');
require('../button/button.js');
require('../utils/classnames.js');
require('../loading/index.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../utils/render-tnode.js');
require('lodash/isObject');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../loading/plugin.js');
require('../button/props.js');
require('../utils/ripple.js');
require('../input/index.js');
require('../input/addon.js');
require('../input/input.js');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/helper.js');
require('../utils/event.js');
require('../input/props.js');
require('../input/input-group.js');
require('../utils/map-props.js');
require('../input-number/props.js');
require('../select/index.js');
require('../select/select.js');
require('lodash/isFunction');
require('lodash/debounce');
require('lodash/set');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../popup/props.js');
require('../popup/container.js');
require('../tag/index.js');
require('../tag/tag.js');
require('../tag/props.js');
require('../tag/check-tag.js');
require('../tag/check-tag-props.js');
require('../common-components/fake-arrow.js');
require('../select/option.js');
require('../select/option-props.js');
require('../checkbox/index.js');
require('../checkbox/group.js');
require('lodash/intersection');
require('../checkbox/checkbox.js');
require('../checkbox/props.js');
require('../checkbox/checkbox-group-props.js');
require('../select/props.js');
require('../select/optionGroup.js');
require('../select/option-group-props.js');
require('../pagination/props.js');
require('../hooks/useVirtualScroll.js');
require('./tbody.js');
require('./tr.js');
require('lodash/upperFirst');
require('./utils.js');
require('./hooks/useClassName.js');
require('./ellipsis.js');
require('./hooks/useStyle.js');
require('../hooks/useCommonClassName.js');
require('../affix/index.js');
require('../affix/affix.js');
require('../affix/props.js');
require('./thead.js');
require('./tfoot.js');
require('./hooks/useMultiHeader.js');
require('lodash/isEmpty');
require('../hooks/render-tnode.js');
require('../dialog/plugin.js');
require('../dialog/dialog.js');
require('lodash/throttle');
require('../dialog/actions.js');
require('../dialog/props.js');
require('../hooks/useDestroyOnClose.js');
require('../hooks/useDefaultValue.js');
require('../radio/index.js');
require('../radio/radio.js');
require('../radio/props.js');
require('../radio/group.js');
require('lodash/isNumber');
require('../radio/radio-group-props.js');
require('../radio/radio-button.js');
require('./sorter-button.js');
require('../tooltip/index.js');
require('../tooltip/tooltip.js');
require('../tooltip/props.js');
require('./filter-controller.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

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__default["default"](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 = VueCompositionAPI.defineComponent({
  name: "TPrimaryTable",
  props: _objectSpread(_objectSpread({}, table_baseTableProps["default"]), table_primaryTableProps["default"]),
  setup: function setup(props, context) {
    var renderTNode = hooks_tnode.useTNodeJSX();

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

    var _useColumnController = table_hooks_useColumnController["default"](props, context),
        displayColumnKeys = _useColumnController.displayColumnKeys,
        renderColumnController = _useColumnController.renderColumnController;

    var _useRowExpand = table_hooks_useRowExpand["default"](props, context),
        showExpandedRow = _useRowExpand.showExpandedRow,
        showExpandIconColumn = _useRowExpand.showExpandIconColumn,
        getExpandColumn = _useRowExpand.getExpandColumn,
        renderExpandedRow = _useRowExpand.renderExpandedRow,
        onInnerExpandRowClick = _useRowExpand.onInnerExpandRowClick;

    var _useSorter = table_hooks_useSorter["default"](props, context),
        renderSortIcon = _useSorter.renderSortIcon;

    var _useRowSelect = table_hooks_useRowSelect["default"](props),
        formatToRowSelectColumn = _useRowSelect.formatToRowSelectColumn,
        tRowClassNames = _useRowSelect.tRowClassNames;

    var _useFilter = table_hooks_useFilter["default"](props, context),
        hasEmptyCondition = _useFilter.hasEmptyCondition,
        primaryTableRef = _useFilter.primaryTableRef,
        renderFilterIcon = _useFilter.renderFilterIcon,
        renderFirstFilterRow = _useFilter.renderFirstFilterRow;

    var _useTableHeader = table_hooks_useTableHeader["default"](props),
        renderTitleWidthIcon = _useTableHeader.renderTitleWidthIcon;

    var _useAsyncLoading = table_hooks_useAsyncLoading["default"](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 = table_hooks_useTableHeader.renderTitle(VueCompositionAPI.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);

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

      return arr;
    };

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

      if (showExpandIconColumn.value) {
        cols.unshift(getExpandColumn(VueCompositionAPI.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 = {};
      table_baseTable.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(table_baseTable["default"], helper.helper([{
      "ref": "primaryTableRef",
      "scopedSlots": this.$scopedSlots
    }, {
      "props": props
    }, {}, {
      "on": on
    }, {}, this.$attrs]));
  }
});

exports.BASE_TABLE_ALL_EVENTS = table_baseTable.BASE_TABLE_ALL_EVENTS;
exports["default"] = _PrimaryTable;
//# sourceMappingURL=primary-table.js.map
