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

import { h, getCurrentInstance } from 'vue';
import { i as isFunction_1 } from '../_chunks/dep-6b22dd27.mjs';
import { c as camelCase_1 } from '../_chunks/dep-f6649a46.mjs';
import { k as kebabCase_1 } from '../_chunks/dep-c4e1a112.mjs';
import { getParams, getDefaultNode } from '../utils/render-tnode.mjs';
import '../_chunks/dep-a0b4a044.mjs';
import '../_chunks/dep-c959a6fb.mjs';
import '../_chunks/dep-b4041200.mjs';
import '../_chunks/dep-0f0c89ff.mjs';
import '../_chunks/dep-37ba476d.mjs';
import '../_chunks/dep-e3b14d70.mjs';
import '../_chunks/dep-66d6733b.mjs';
import '../_chunks/dep-be27d184.mjs';
import '../_chunks/dep-c31e1d9e.mjs';
import '../_chunks/dep-1fe0ad42.mjs';
import '../_chunks/dep-d54f2690.mjs';
import '../_chunks/dep-59c8420d.mjs';
import '../_chunks/dep-74848b92.mjs';
import '../_chunks/dep-bd03960e.mjs';
import '../_chunks/dep-44f056cd.mjs';
import '../_chunks/dep-a9c8a5d5.mjs';
import '../_chunks/dep-10085c61.mjs';
import '../_chunks/dep-1b058de3.mjs';
import '../_chunks/dep-39cc276d.mjs';
import '../_chunks/dep-8f777748.mjs';
import '../_chunks/dep-05fa17c9.mjs';
import '../_chunks/dep-92e7085e.mjs';
import '../_chunks/dep-1cf2b129.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
