/**
 * 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 configProvider_useConfig = require('../../config-provider/useConfig.js');
var table_hooks_useClassName = require('./useClassName.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('../../hooks/useConfig.js');
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');
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');

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 useAsyncLoading(props) {
  var renderTNode = hooks_tnode.useTNodeJSX();
  var _useConfig = configProvider_useConfig.useConfig("table"),
    globalConfig = _useConfig.globalConfig;
  var _useClassName = table_hooks_useClassName["default"](),
    isLoadingClass = _useClassName.isLoadingClass,
    isLoadMoreClass = _useClassName.isLoadMoreClass,
    asyncLoadingClass = _useClassName.asyncLoadingClass;
  var classes = vue.computed(function () {
    var _ref;
    return [asyncLoadingClass, (_ref = {}, _defineProperty__default["default"](_ref, isLoadingClass, props.asyncLoading === "loading"), _defineProperty__default["default"](_ref, isLoadMoreClass, props.asyncLoading === "load-more"), _ref)];
  });
  function onLoadClick() {
    var _props$onAsyncLoading;
    if (typeof props.asyncLoading !== "string") return;
    (_props$onAsyncLoading = props.onAsyncLoadingClick) === null || _props$onAsyncLoading === void 0 ? void 0 : _props$onAsyncLoading.call(props, {
      status: props.asyncLoading
    });
  }
  function renderAsyncLoading() {
    var asyncLoadingNode = renderTNode("asyncLoading");
    if (isString__default["default"](asyncLoadingNode)) {
      var asyncLoading = props.asyncLoading;
      var loadingText = {
        "load-more": globalConfig.value.loadingMoreText,
        "loading": globalConfig.value.loadingText
      }[String(asyncLoading)];
      return vue.createVNode("div", {
        "class": classes.value,
        "onClick": onLoadClick
      }, [vue.createVNode(loading_index.Loading, {
        "loading": asyncLoading === "loading",
        "size": "small",
        "text": loadingText
      }, null)]);
    }
    if (![null, false, void 0].includes(asyncLoadingNode)) {
      return vue.createVNode("div", {
        "class": classes.value,
        "onClick": onLoadClick
      }, [asyncLoadingNode]);
    }
    return null;
  }
  return {
    renderAsyncLoading: renderAsyncLoading
  };
}

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