/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var loading_index = require('../loading/index.js');
var list_props = require('./props.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var list_const = require('./const.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../utils/mixins.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/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../utils/dom.js');
require('vue');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../loading/plugin.js');
require('../config.js');
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('@babel/runtime/helpers/typeof');
require('lodash/camelCase');
require('lodash/kebabCase');

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 classPrefixMixins = configProvider_configReceiver.getClassPrefixMixins("list");
var _List = utils_mixins["default"](classPrefixMixins).extend({
  name: "TList",
  props: _objectSpread({}, list_props["default"]),
  computed: {
    listClass: function listClass() {
      var _ref;

      return ["".concat(this.componentName), this.commonSizeClassName[this.size], (_ref = {}, _defineProperty__default["default"](_ref, "".concat(this.componentName, "--split"), this.split), _defineProperty__default["default"](_ref, "".concat(this.componentName, "--stripe"), this.stripe), _defineProperty__default["default"](_ref, "".concat(this.componentName, "--vertical-action"), this.layout === "vertical"), _ref)];
    },
    loadingClass: function loadingClass() {
      if (this.asyncLoading === "loading") return this.commonStatusClassName.loading;
      if (this.asyncLoading === "load-more") return this.commonStatusClassName.loadMore;
      return "";
    }
  },
  components: {
    Loading: loading_index.Loading
  },
  methods: {
    renderLoading: function renderLoading() {
      var h = this.$createElement;

      if (this.asyncLoading && typeof this.asyncLoading === "string") {
        var _LOADING$LOAD_MORE$th;

        var text = (_LOADING$LOAD_MORE$th = {}, _defineProperty__default["default"](_LOADING$LOAD_MORE$th, list_const.LOADING, "\u6B63\u5728\u52A0\u8F7D\u4E2D\uFF0C\u8BF7\u7A0D\u540E"), _defineProperty__default["default"](_LOADING$LOAD_MORE$th, list_const.LOAD_MORE, "\u70B9\u51FB\u52A0\u8F7D\u66F4\u591A"), _LOADING$LOAD_MORE$th)[this.asyncLoading];
        var loading = this.asyncLoading === list_const.LOADING;
        return h(loading_index.Loading, {
          "class": this.loadingClass,
          "attrs": {
            "loading": loading,
            "text": text
          }
        });
      }

      return utils_renderTnode.renderTNodeJSX(this, "asyncLoading");
    },
    handleScroll: function handleScroll(e) {
      var listElement = this.$el;
      var scrollTop = listElement.scrollTop,
          scrollHeight = listElement.scrollHeight,
          clientHeight = listElement.clientHeight;
      this.$emit("scroll", {
        $event: e,
        scrollTop: scrollTop,
        scrollBottom: scrollHeight - clientHeight - scrollTop
      });

      if (this.onScroll) {
        this.onScroll({
          e: e,
          scrollTop: scrollTop,
          scrollBottom: scrollHeight - clientHeight - scrollTop
        });
      }
    },
    handleLoadMore: function handleLoadMore(e) {
      if (typeof this.asyncLoading === "string" && this.asyncLoading !== list_const.LOAD_MORE) return;
      this.$emit("load-more", {
        e: e
      });

      if (this.onLoadMore) {
        this.onLoadMore({
          e: e
        });
      }
    },
    renderContent: function renderContent() {
      var h = this.$createElement;
      var propsHeaderContent = utils_renderTnode.renderTNodeJSX(this, "header");
      var propsFooterContent = utils_renderTnode.renderTNodeJSX(this, "footer");
      return [propsHeaderContent && h("div", {
        "class": "".concat(this.componentName, "__header")
      }, [propsHeaderContent]), h("ul", {
        "class": "".concat(this.componentName, "__inner")
      }, [utils_renderTnode.renderTNodeJSX(this, "default")]), propsFooterContent && h("div", {
        "class": "".concat(this.componentName, "__footer")
      }, [propsFooterContent])];
    }
  },
  render: function render() {
    var h = arguments[0];
    var listContent = this.renderContent();
    listContent = [listContent, h("div", {
      "class": "".concat(this.componentName, "__load"),
      "on": {
        "click": this.handleLoadMore
      }
    }, [this.renderLoading()])];
    return h("div", {
      "class": this.listClass,
      "on": {
        "scroll": this.handleScroll
      }
    }, [listContent]);
  }
});

exports["default"] = _List;
//# sourceMappingURL=list.js.map
