/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var isString = require('lodash/isString');
var hooks_tnode = require('../hooks/tnode.js');
var loading_index = require('../loading/index.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var list_props = require('./props.js');
var list_const = require('./const.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('../utils/withInstall.js');
require('../loading/directive.js');
require('../loading/plugin.js');
require('../utils/dom.js');
require('../_chunks/dep-7f0559c3.js');
require('lodash/isArray');
require('../utils/easing.js');
require('../loading/loading.js');
require('@babel/runtime/helpers/slicedToArray');
require('../hooks/useTeleport.js');
require('../loading/props.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('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
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('dayjs');

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

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

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 _List = vue.defineComponent({
  name: "TList",
  props: _objectSpread({}, list_props["default"]),
  setup: function setup(props2) {
    var _useConfig = configProvider_useConfig.useConfig("list"),
      globalConfig = _useConfig.globalConfig;
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("list");
    var _useCommonClassName = hooks_useConfig.useCommonClassName(),
      SIZE = _useCommonClassName.SIZE;
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var listClass = vue.computed(function () {
      var _ref;
      return ["".concat(COMPONENT_NAME.value), SIZE.value[props2.size], (_ref = {}, _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--split"), props2.split), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--stripe"), props2.stripe), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--vertical-action"), props2.layout === "vertical"), _ref)];
    });
    var renderContent = function renderContent() {
      var propsHeaderContent = renderTNodeJSX("header");
      var propsFooterContent = renderTNodeJSX("footer");
      return [propsHeaderContent && vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__header")
      }, [propsHeaderContent]), vue.createVNode("ul", {
        "class": "".concat(COMPONENT_NAME.value, "__inner")
      }, [renderTNodeJSX("default")]), propsFooterContent && vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__footer")
      }, [propsFooterContent])];
    };
    var handleScroll = function handleScroll(e) {
      var _props2$onScroll;
      var listElement = e.target;
      var scrollTop = listElement.scrollTop,
        scrollHeight = listElement.scrollHeight,
        clientHeight = listElement.clientHeight;
      (_props2$onScroll = props2.onScroll) === null || _props2$onScroll === void 0 ? void 0 : _props2$onScroll.call(props2, {
        e: e,
        scrollTop: scrollTop,
        scrollBottom: scrollHeight - clientHeight - scrollTop
      });
    };
    var loadingClass = vue.computed(function () {
      return isString__default["default"](props2.asyncLoading) && ["loading", "load-more"].includes(props2.asyncLoading) ? "".concat(COMPONENT_NAME.value, "__load ").concat(COMPONENT_NAME.value, "__load--").concat(props2.asyncLoading) : "".concat(COMPONENT_NAME.value, "__load");
    });
    var renderLoading = function renderLoading() {
      if (props2.asyncLoading && isString__default["default"](props2.asyncLoading)) {
        if (props2.asyncLoading === list_const.LOADING) {
          return vue.createVNode("div", null, [vue.createVNode(loading_index.Loading, null, null), vue.createVNode("span", null, [globalConfig.value.loadingText])]);
        }
        if (props2.asyncLoading === list_const.LOAD_MORE) return vue.createVNode("span", null, [globalConfig.value.loadingMoreText]);
      }
      return renderTNodeJSX("asyncLoading");
    };
    var handleLoadMore = function handleLoadMore(e) {
      var _props2$onLoadMore;
      if (isString__default["default"](props2.asyncLoading) && props2.asyncLoading !== list_const.LOAD_MORE) return;
      (_props2$onLoadMore = props2.onLoadMore) === null || _props2$onLoadMore === void 0 ? void 0 : _props2$onLoadMore.call(props2, {
        e: e
      });
    };
    return {
      COMPONENT_NAME: COMPONENT_NAME,
      listClass: listClass,
      loadingClass: loadingClass,
      renderLoading: renderLoading,
      renderContent: renderContent,
      handleScroll: handleScroll,
      handleLoadMore: handleLoadMore
    };
  },
  render: function render() {
    var listContent = this.renderContent();
    listContent = [listContent, vue.createVNode("div", {
      "class": this.loadingClass,
      "onClick": this.handleLoadMore
    }, [this.renderLoading()])];
    return vue.createVNode("div", {
      "class": this.listClass,
      "onScroll": this.handleScroll
    }, [listContent]);
  }
});

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