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

import { h, getCurrentInstance } from 'vue';
import { i as isFunction_1 } from '../_chunks/dep-5717e263.mjs';
import { c as camelCase_1 } from '../_chunks/dep-406cd044.mjs';
import { k as kebabCase_1 } from '../_chunks/dep-9a85dac1.mjs';
import { getParams, getDefaultNode } from '../utils/render-tnode.mjs';
import '../_chunks/dep-eba0ea6e.mjs';
import '../_chunks/dep-469b4ae0.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../_chunks/dep-a8bcacea.mjs';
import '../_chunks/dep-42cc3015.mjs';
import '../_chunks/dep-b57180d0.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-2bc37d52.mjs';
import '../_chunks/dep-3da99438.mjs';
import '../_chunks/dep-327559e8.mjs';
import '../_chunks/dep-b2235f26.mjs';
import '../_chunks/dep-8b989474.mjs';
import '../_chunks/dep-1372b2d3.mjs';
import '../_chunks/dep-888e80c4.mjs';
import '../_chunks/dep-334a4f6b.mjs';
import '../_chunks/dep-e5eb9f23.mjs';
import '../_chunks/dep-9fe2ef12.mjs';
import '../_chunks/dep-672e7d1a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-2e7f59b1.mjs';
import '../_chunks/dep-1434aa15.mjs';
import '../_chunks/dep-9262ee2f.mjs';
import '../_chunks/dep-876fb3ec.mjs';

function handleSlots(instance, name, params) {
  var _instance$slots$camel, _instance$slots, _instance$slots$kebab, _instance$slots2;
  var finalParams = new Function("return ".concat(h.toString()))();
  if (params) Object.assign(finalParams, params);
  var node = (_instance$slots$camel = (_instance$slots = instance.slots)[camelCase_1(name)]) === null || _instance$slots$camel === void 0 ? void 0 : _instance$slots$camel.call(_instance$slots, finalParams);
  if (node) return node;
  node = (_instance$slots$kebab = (_instance$slots2 = instance.slots)[kebabCase_1(name)]) === null || _instance$slots$kebab === void 0 ? void 0 : _instance$slots$kebab.call(_instance$slots2, finalParams);
  if (node) return node;
  return null;
}
function isEmptyNode(node) {
  if ([void 0, null, ""].includes(node)) return true;
  var innerNodes = Array.isArray(node) ? node : [node];
  var r = innerNodes.filter(function (node2) {
    var _node2$type;
    return (node2 === null || node2 === void 0 ? void 0 : (_node2$type = node2.type) === null || _node2$type === void 0 ? void 0 : _node2$type.toString()) !== "Symbol(Comment)";
  });
  return !r.length;
}
var useTNodeJSX = function useTNodeJSX() {
  var instance = getCurrentInstance();
  return function (name, options) {
    var params = getParams(options);
    var defaultNode = getDefaultNode(options);
    var propsNode;
    if (Object.keys(instance.props).includes(name)) propsNode = instance.props[name];
    if (propsNode === false) return;
    if (propsNode === true) return handleSlots(instance, name, params) || defaultNode;
    if (isFunction_1(propsNode)) return propsNode(h, params);
    var isPropsEmpty = [void 0, params, ""].includes(propsNode);
    if (isPropsEmpty && (instance.slots[camelCase_1(name)] || instance.slots[kebabCase_1(name)])) return handleSlots(instance, 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 = isEmptyNode(node1) ? node2 : node1;
    return isEmptyNode(res) ? defaultNode : res;
  };
};

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