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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var isString = require('lodash/isString');
var VueCompositionAPI = require('@vue/composition-api');
var hooks_lnode = require('../../../hooks/lnode.js');
var components_loading_index = require('../../loading/index.js');
var components_configProvider_useConfig = require('../../config-provider/useConfig.js');
var components_table_hooks_useClassName = require('./useClassName.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../../hooks/render-lnode.js');
require('lodash');
require('../../../utils/with-install.js');
require('vue');
require('../../../config.js');
require('../../loading/loading.js');
require('../../../utils/dom.js');
require('raf');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../../utils/easing.js');
require('../../../utils/render-node.js');
require('../../../utils/transfer-dom.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');
require('../../../utils/mixins.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../../chunks/defineProperty-838e4192.js');
require('../../../chunks/set-style.js');
require('../../../chunks/helper2.js');
require('../../loading/plugin.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);

function useAsyncLoading(props, context) {
  const renderTNode = hooks_lnode.useLNodeJSX();
  const {
    global
  } = components_configProvider_useConfig.useConfig("table");
  const {
    isLoadingClass,
    isLoadMoreClass,
    asyncLoadingClass
  } = components_table_hooks_useClassName["default"]();
  const classes = VueCompositionAPI.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__default["default"](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(components_loading_index.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
  };
}

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