/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import { getCurrentInstance, h } from '@vue/composition-api';
import isEmpty from 'lodash/isEmpty';
import isFunction from 'lodash/isFunction';
import camelCase from 'lodash/camelCase';
import kebabCase from 'lodash/kebabCase';
import { getParams, getDefaultNode } from './render-tnode.js';
import 'lodash/isString';
import 'lodash/isObject';

function handleSlots(slots, name, params) {
  var _slots$camelCase, _slots$kebabCase;
  var finaleParams = h;
  if (params) Object.assign(finaleParams, params);
  var node = (_slots$camelCase = slots[camelCase(name)]) === null || _slots$camelCase === void 0 ? void 0 : _slots$camelCase.call(slots, finaleParams);
  if (node) return node;
  node = (_slots$kebabCase = slots[kebabCase(name)]) === null || _slots$kebabCase === void 0 ? void 0 : _slots$kebabCase.call(slots, finaleParams);
  if (node) return node;
  return null;
}
var useTNodeJSX = function useTNodeJSX() {
  var instance = getCurrentInstance();
  return function (name, options) {
    var params = getParams(options);
    var defaultNode = getDefaultNode(options);
    var slots = instance.setupContext.slots;
    var propsNode;
    if (Object.keys(instance.props).includes(name)) propsNode = instance.props[name];
    if (propsNode === false) return;
    if (propsNode === true) return handleSlots(slots, name, params) || defaultNode;
    if (isFunction(propsNode)) return propsNode(h, params);
    var isPropsEmpty = [void 0, params, ""].includes(propsNode);
    if (isPropsEmpty && (slots[camelCase(name)] || slots[kebabCase(name)])) return handleSlots(slots, name, params);
    return propsNode;
  };
};
var useTNodeDefault = function useTNodeDefault() {
  var renderTNodeJSX = useTNodeJSX();
  return function (name, options) {
    var defaultNode = getDefaultNode(options);
    return renderTNodeJSX(name, options) || defaultNode;
  };
};
var useContent = function useContent() {
  var renderTNodeJSX = useTNodeJSX();
  return function (name1, name2, options) {
    var params = getParams(options);
    var defaultNode = getDefaultNode(options);
    var toParams = params ? {
      params: params
    } : void 0;
    var node1 = renderTNodeJSX(name1, toParams);
    var node2 = renderTNodeJSX(name2, toParams);
    var res = isEmpty(node1) ? node2 : node1;
    return isEmpty(res) ? defaultNode : res;
  };
};

export { useContent, useTNodeDefault, useTNodeJSX };
//# sourceMappingURL=tnode.js.map
