/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 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/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../../../config.js';
import '../../loading/loading.js';
import '../../../utils/dom.js';
import 'raf';
import '../../../_chunks/dep-eaa95999.js';
import '../../../_chunks/dep-102361be.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 'lodash/merge';
import '../../../_chunks/dep-b4fd1955.js';
import '../../../utils/mixins.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../../_chunks/dep-aacc31a3.js';
import '../../../_chunks/dep-c68dc4b6.js';
import '../../../_chunks/dep-1a6bca30.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() {
    if (typeof props.asyncLoading !== "string") return;
    props.onAsyncLoadingClick?.({
      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
