/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var table_primaryTableProps = require('../../primary-table-props.js');
var table_baseTable_tableRow = require('../../base-table/table-row.js');
var loading_index = require('../../../loading/index.js');
var config = require('../../../config.js');
var utils_classnames = require('../../../utils/classnames.js');
var utils_event = require('../../../utils/event.js');
require('../../../_chunks/dep-44e6bdf6.js');
require('lodash/get');
require('../../base-table-props.js');
require('../../base-table/table-cell.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../../../popup/index.js');
require('../../../popup/popup.js');
require('@babel/runtime/helpers/typeof');
require('@popperjs/core');
require('../../../_chunks/dep-939cdc39.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../utils/easing.js');
require('../../../popup/props.js');
require('../../../utils/render-tnode.js');
require('../../../utils/set-style.js');
require('../../../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../../../utils/withInstall.js');
require('lodash/capitalize');
require('../../util/common.js');
require('lodash/isFunction');
require('../../../loading/loading.js');
require('../../../loading/icon/gradient.js');
require('../../../utils/transfer-dom.js');
require('../../../loading/props.js');
require('../../../loading/plugin.js');
require('../../../utils/helper.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');

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

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

var ASYNC_LOADING_ROW = "async-loading-row";
var asyncLoadingMixin = Vue__default["default"].extend({
  name: "".concat(config.prefix, "-primary-table-async-loading"),
  props: {
    columns: table_primaryTableProps["default"].columns,
    asyncLoading: table_primaryTableProps["default"].asyncLoading
  },
  data: function data() {
    return {
      pullDownLoading: false
    };
  },
  computed: {
    classes: function classes() {
      var _ref;

      return ["".concat(config.prefix, "-table__async-loading"), (_ref = {}, _defineProperty__default["default"](_ref, utils_classnames.STATUS_CLASSNAMES.loading, this.asyncLoading === "loading"), _defineProperty__default["default"](_ref, utils_classnames.STATUS_CLASSNAMES.loadMore, this.asyncLoading === "load-more"), _ref)];
    }
  },
  methods: {
    asyncLoadingHandler: function asyncLoadingHandler(data) {
      if (this.asyncLoading || typeof this.$scopedSlots.asyncLoading === "function") {
        return data.concat({
          colKey: ASYNC_LOADING_ROW
        });
      }

      return data;
    },
    onLoadClick: function onLoadClick() {
      if (typeof this.asyncLoading !== "string") return;
      utils_event.emitEvent(this, "async-loading-click", {
        status: this.asyncLoading
      });
    },
    renderAsyncLoadingRow: function renderAsyncLoadingRow() {
      var _this = this;

      var h = this.$createElement;
      var asyncLoading = this.asyncLoading;
      var columns = [{
        colKey: ASYNC_LOADING_ROW,
        attrs: {
          colSpan: this.columns.length
        },
        render: function render(h) {
          if (typeof asyncLoading === "function") {
            return asyncLoading(h);
          }

          if (typeof _this.$scopedSlots.asyncLoading === "function") {
            return _this.$scopedSlots.asyncLoading(h);
          }

          var loadingText = {
            "load-more": "\u70B9\u51FB\u52A0\u8F7D\u66F4\u591A",
            loading: "\u6B63\u5728\u52A0\u8F7D\u4E2D\uFF0C\u8BF7\u7A0D\u540E"
          }[String(asyncLoading)];

          if (!loadingText) {
            return "";
          }

          return h("div", {
            "class": _this.classes,
            "on": {
              "click": _this.onLoadClick
            }
          }, [h(loading_index.Loading, {
            "attrs": {
              "loading": asyncLoading === "loading",
              "text": loadingText
            }
          })]);
        }
      }];
      return h(table_baseTable_tableRow["default"], {
        "attrs": {
          "rowKey": ASYNC_LOADING_ROW,
          "columns": columns
        }
      });
    }
  }
});

exports.ASYNC_LOADING_ROW = ASYNC_LOADING_ROW;
exports["default"] = asyncLoadingMixin;
//# sourceMappingURL=async-loading.js.map
