/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { Loading } from '../loading/index.js';
import { renderLNodeJSX } from '../../utils/render-node.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import { LOADING, LOAD_MORE } from './const.js';
import { ListProps } from './props.js';
import '../../utils/with-install.js';
import 'vue';
import 'lodash';
import '../../config.js';
import '../loading/loading.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../chunks/index.js';
import '../../chunks/log.js';
import '../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../utils/easing.js';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../../chunks/defineProperty-838e4192.js';
import '../../chunks/set-style.js';
import '../../chunks/helper2.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '../loading/style/css.js';
import '../loading/type.js';
import '../loading/plugin.js';

const classPrefixMixins = getClassPrefixMixins("list");
var _List = mixins(classPrefixMixins).extend({
  name: "LList",
  props: {
    ...ListProps
  },
  computed: {
    listClass() {
      return [`${this.componentName}`, this.commonSizeClassName[this.size], {
        [`${this.componentName}--split`]: this.split,
        [`${this.componentName}--stripe`]: this.stripe,
        [`${this.componentName}--vertical-action`]: this.layout === "vertical"
      }];
    },
    loadingClass() {
      if (this.asyncLoading === "loading") return this.commonStatusClassName.loading;
      if (this.asyncLoading === "load-more") return this.commonStatusClassName.loadMore;
      return "";
    }
  },
  components: {
    LLoading: Loading
  },
  methods: {
    renderLoading() {
      const h = this.$createElement;
      if (this.asyncLoading && typeof this.asyncLoading === "string") {
        const text = {
          [LOADING]: "\u6B63\u5728\u52A0\u8F7D\u4E2D\uFF0C\u8BF7\u7A0D\u540E",
          [LOAD_MORE]: "\u70B9\u51FB\u52A0\u8F7D\u66F4\u591A"
        }[this.asyncLoading];
        const loading = this.asyncLoading === LOADING;
        return h("l-loading", {
          "class": this.loadingClass,
          "attrs": {
            "loading": loading,
            "text": text
          }
        });
      }
      return renderLNodeJSX(this, "asyncLoading");
    },
    handleScroll(e) {
      const listElement = this.$el;
      const {
        scrollTop,
        scrollHeight,
        clientHeight
      } = listElement;
      this.$emit("scroll", {
        $event: e,
        scrollTop,
        scrollBottom: scrollHeight - clientHeight - scrollTop
      });
      if (this.onScroll) {
        this.onScroll({
          e,
          scrollTop,
          scrollBottom: scrollHeight - clientHeight - scrollTop
        });
      }
    },
    handleLoadMore(e) {
      if (typeof this.asyncLoading === "string" && this.asyncLoading !== LOAD_MORE) return;
      this.$emit("load-more", {
        e
      });
      if (this.onLoadMore) {
        this.onLoadMore({
          e
        });
      }
    },
    renderContent() {
      const h = this.$createElement;
      const propsHeaderContent = renderLNodeJSX(this, "header");
      const propsFooterContent = renderLNodeJSX(this, "footer");
      return [propsHeaderContent && h("div", {
        "class": `${this.componentName}__header`
      }, [propsHeaderContent]), h("ul", {
        "class": `${this.componentName}__inner`
      }, [renderLNodeJSX(this, "default")]), propsFooterContent && h("div", {
        "class": `${this.componentName}__footer`
      }, [propsFooterContent])];
    }
  },
  render() {
    const h = arguments[0];
    let listContent = this.renderContent();
    listContent = [listContent, h("div", {
      "class": `${this.componentName}__load`,
      "on": {
        "click": this.handleLoadMore
      }
    }, [this.renderLoading()])];
    return h("div", {
      "class": this.listClass,
      "on": {
        "scroll": this.handleScroll
      }
    }, [listContent]);
  }
});

export { _List as default };
//# sourceMappingURL=list.js.map
