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

import { h } from '@vue/composition-api';
import isEmpty from 'lodash/isEmpty';
import isString from 'lodash/isString';
import isFunction from 'lodash/isFunction';
import isObject from 'lodash/isObject';
import camelCase from 'lodash/camelCase';
import kebabCase from 'lodash/kebabCase';

var isVNode = function isVNode(obj) {
  var vNode = h("span", "");
  var VNode2 = vNode.constructor;
  return obj instanceof VNode2;
};
function getDefaultNode(options) {
  var defaultNode;

  if (isObject(options) && "defaultNode" in options) {
    defaultNode = options.defaultNode;
  } else if (isVNode(options) || isString(options)) {
    defaultNode = options;
  }

  return defaultNode;
}
function getParams(options) {
  return isObject(options) && "params" in options ? options.params : null;
}
function handleSlots(instance, params, name) {
  var _instance$$slots$came, _instance$$slots, _instance$$slots$keba, _instance$$slots2;

  var node = (_instance$$slots$came = (_instance$$slots = instance.$slots)[camelCase(name)]) === null || _instance$$slots$came === void 0 ? void 0 : _instance$$slots$came.call(_instance$$slots, params);
  if (node) return node;
  node = (_instance$$slots$keba = (_instance$$slots2 = instance.$slots)[kebabCase(name)]) === null || _instance$$slots$keba === void 0 ? void 0 : _instance$$slots$keba.call(_instance$$slots2, params);
  if (node) return node;
  return null;
}
var renderTNodeJSX = function renderTNodeJSX(instance, name, options) {
  var params = getParams(options);
  var defaultNode = getDefaultNode(options);
  var propsNode;

  if (name in instance) {
    propsNode = instance[name];
  }

  if (propsNode === false) return;

  if (propsNode === true && defaultNode) {
    return handleSlots(instance, params, name) || defaultNode;
  }

  if (isFunction(propsNode)) return propsNode(h, params);
  var isPropsEmpty = [void 0, params, ""].includes(propsNode);

  if (isPropsEmpty && (instance.$slots[camelCase(name)] || instance.$slots[kebabCase(name)])) {
    return handleSlots(instance, params, name);
  }

  return propsNode;
};
var renderTNodeJSXDefault = function renderTNodeJSXDefault(vm, name, options) {
  var defaultNode = getDefaultNode(options);
  return renderTNodeJSX(vm, name, options) || defaultNode;
};
var renderContent = function renderContent(vm, name1, name2, options) {
  var params = getParams(options);
  var defaultNode = getDefaultNode(options);
  var toParams = params ? {
    params: params
  } : void 0;
  var node1 = renderTNodeJSX(vm, name1, toParams);
  var node2 = renderTNodeJSX(vm, name2, toParams);
  var res = isEmpty(node1) ? node2 : node1;
  return isEmpty(res) ? defaultNode : res;
};

export { getDefaultNode, getParams, handleSlots, isVNode, renderContent, renderTNodeJSX, renderTNodeJSXDefault };
//# sourceMappingURL=render-tnode.js.map
