/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var isString = require('lodash/isString');
var VueCompositionAPI = require('@vue/composition-api');
var hooks_tnode = require('../../hooks/tnode.js');
var loading_index = require('../../loading/index.js');
var table_hooks_useClassName = require('./useClassName.js');
var configProvider_useConfig = require('../../config-provider/useConfig.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../hooks/render-tnode.js');
require('lodash/isObject');
require('../../loading/loading.js');
require('../../loading/icon/gradient.js');
require('../../_common/js/loading/circle-adapter.js');
require('../../_common/js/utils/set-style.js');
require('../../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../../config-provider/config-receiver.js');
require('vue');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('../../utils/mixins.js');
require('../../utils/dom.js');
require('raf');
require('../../utils/easing.js');
require('../../utils/render-tnode.js');
require('@babel/runtime/helpers/typeof');
require('../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../utils/withInstall.js');
require('lodash/capitalize');
require('../../loading/plugin.js');
require('../../config.js');

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

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

function useAsyncLoading(props, context) {
  var renderTNode = hooks_tnode.useTNodeJSX();

  var _useConfig = configProvider_useConfig.useConfig("table"),
      global = _useConfig.global;

  var _useClassName = table_hooks_useClassName["default"](),
      isLoadingClass = _useClassName.isLoadingClass,
      isLoadMoreClass = _useClassName.isLoadMoreClass,
      asyncLoadingClass = _useClassName.asyncLoadingClass;

  var classes = VueCompositionAPI.computed(function () {
    var _ref;

    return [asyncLoadingClass, (_ref = {}, _defineProperty__default["default"](_ref, isLoadingClass, props.asyncLoading === "loading"), _defineProperty__default["default"](_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__default["default"](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_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: renderAsyncLoading
  };
}

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