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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import isString from 'lodash/isString';
import { computed } from '@vue/composition-api';
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/isEmpty';
import 'lodash/isFunction';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../hooks/render-tnode.js';
import 'lodash/isObject';
import '../../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../../loading/directive.js';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../../loading/plugin.js';
import '../../config.js';
import '../../utils/dom.js';
import 'raf';
import '../../utils/easing.js';
import '../../loading/loading.js';
import '../../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import '../../utils/transfer-dom.js';
import '../../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../../config-provider/context.js';
import 'lodash/merge';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '../../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../../_chunks/dep-67ff4010.js';
import '../../config-provider/type.js';
import '../../utils/mixins.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 '@babel/runtime/helpers/slicedToArray';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import '../../loading/style/css.js';
import '../../loading/type.js';

function useAsyncLoading(props, context) {
  var renderTNode = useTNodeJSX();
  var _useConfig = useConfig("table"),
    global = _useConfig.global;
  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
    });
    context.emit("async-loading-click", {
      status: props.asyncLoading
    });
  }
  function renderAsyncLoading(h) {
    var asyncLoadingNode = renderTNode("asyncLoading");
    if (isString(asyncLoadingNode)) {
      var asyncLoading = props.asyncLoading;
      var loadingText = {
        "load-more": global.value.loadingMoreText,
        "loading": global.value.loadingText
      }[String(asyncLoading)];
      return h("div", {
        "class": classes.value,
        "on": {
          "click": onLoadClick
        }
      }, [h(Loading, {
        "attrs": {
          "indicator": asyncLoading === "loading",
          "loading": !!asyncLoading,
          "size": "small",
          "text": loadingText
        }
      })]);
    }
    if (![null, false, void 0].includes(asyncLoadingNode)) {
      return h("div", {
        "class": classes.value,
        "on": {
          "click": onLoadClick
        }
      }, [asyncLoadingNode]);
    }
    return null;
  }
  return {
    renderAsyncLoading: renderAsyncLoading
  };
}

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