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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { computed, createVNode } from 'vue';
import isString from 'lodash/isString';
import { useTNodeJSX } from '../../hooks/tnode.js';
import { Loading } from '../../loading/index.js';
import { useConfig } from '../../config-provider/useConfig.js';
import useClassName from './useClassName.js';
import 'lodash/isFunction';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import '../../utils/withInstall.js';
import '../../loading/directive.js';
import '../../loading/plugin.js';
import '../../utils/dom.js';
import '../../_chunks/dep-c9c789a8.js';
import 'lodash/isArray';
import '../../utils/easing.js';
import '../../hooks/useConfig.js';
import 'lodash/cloneDeep';
import '../../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import 'dayjs';
import '../../loading/loading.js';
import '@babel/runtime/helpers/slicedToArray';
import '../../hooks/useTeleport.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../_common/js/loading/circle-adapter.js';
import '../../_common/js/utils/set-style.js';
import '../../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';

function useAsyncLoading(props) {
  var renderTNode = useTNodeJSX();
  var _useConfig = useConfig("table"),
    globalConfig = _useConfig.globalConfig;
  var _useClassName = useClassName(),
    isLoadingClass = _useClassName.isLoadingClass,
    isLoadMoreClass = _useClassName.isLoadMoreClass,
    asyncLoadingClass = _useClassName.asyncLoadingClass;
  var classes = computed(function () {
    var _ref;
    return [asyncLoadingClass, (_ref = {}, _defineProperty(_ref, isLoadingClass, props.asyncLoading === "loading"), _defineProperty(_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(asyncLoadingNode)) {
      var asyncLoading = props.asyncLoading;
      var loadingText = {
        "load-more": globalConfig.value.loadingMoreText,
        "loading": globalConfig.value.loadingText
      }[String(asyncLoading)];
      return createVNode("div", {
        "class": classes.value,
        "onClick": onLoadClick
      }, [createVNode(Loading, {
        "loading": asyncLoading === "loading",
        "size": "small",
        "text": loadingText
      }, null)]);
    }
    if (![null, false, void 0].includes(asyncLoadingNode)) {
      return createVNode("div", {
        "class": classes.value,
        "onClick": onLoadClick
      }, [asyncLoadingNode]);
    }
    return null;
  }
  return {
    renderAsyncLoading: renderAsyncLoading
  };
}

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