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

import isString from 'lodash/isString';
import { computed } from '@vue/composition-api';
import { useLNodeJSX } from '../../../hooks/lnode.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-lnode.js';
import 'lodash';
import '../../../utils/with-install.js';
import 'vue';
import '../../../config.js';
import '../../loading/loading.js';
import '../../../utils/dom.js';
import 'raf';
import '../../../chunks/index.js';
import '../../../chunks/log.js';
import '../../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../../utils/easing.js';
import '../../../utils/render-node.js';
import '../../../utils/transfer-dom.js';
import '../../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../../config-provider/context.js';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';
import '../../../utils/mixins.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 '../../loading/style';
import '../../loading/type.js';
import '../../loading/plugin.js';

function useAsyncLoading(props, context) {
  const renderTNode = useLNodeJSX();
  const {
    global
  } = useConfig("table");
  const {
    isLoadingClass,
    isLoadMoreClass,
    asyncLoadingClass
  } = useClassName();
  const classes = computed(() => [asyncLoadingClass, {
    [isLoadingClass]: props.asyncLoading === "loading",
    [isLoadMoreClass]: props.asyncLoading === "load-more"
  }]);
  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) {
    const asyncLoadingNode = renderTNode("asyncLoading");
    if (isString(asyncLoadingNode)) {
      const {
        asyncLoading
      } = props;
      const loadingText = {
        "load-more": global.value.loadingMoreText,
        "loading": global.value.loadingText
      }[String(asyncLoading)];
      return h("div", {
        "class": classes.value,
        "on": {
          "click": onLoadClick
        }
      }, [h(Loading, {
        "attrs": {
          "loading": asyncLoading === "loading",
          "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
  };
}

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