/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

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

const isVNode = obj => {
  const vNode = h("span", "");
  const VNode = vNode.constructor;
  return obj instanceof VNode;
};
function getDefaultNode(options) {
  let 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) {
  let node = instance.$slots[camelCase(name)]?.(params);
  if (node) return node;
  node = instance.$slots[kebabCase(name)]?.(params);
  if (node) return node;
  return null;
}
const renderLNodeJSX = (instance, name, options) => {
  const params = getParams(options);
  const defaultNode = getDefaultNode(options);
  let 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);
  const isPropsEmpty = [void 0, params, ""].includes(propsNode);
  const hasSlots = instance.$slots[camelCase(name)] || instance.$slots[kebabCase(name)];
  if (isPropsEmpty && hasSlots) return handleSlots(instance, params, name);
  return propsNode;
};
const renderLNodeJSXDefault = (vm, name, options) => {
  const defaultNode = getDefaultNode(options);
  return renderLNodeJSX(vm, name, options) || defaultNode;
};
const renderContent = (vm, name1, name2, options) => {
  const params = getParams(options);
  const defaultNode = getDefaultNode(options);
  const toParams = params ? {
    params
  } : void 0;
  const node1 = renderLNodeJSX(vm, name1, toParams);
  const node2 = renderLNodeJSX(vm, name2, toParams);
  const res = isEmpty(node1) ? node2 : node1;
  return isEmpty(res) ? defaultNode : res;
};

export { getDefaultNode, getParams, handleSlots, isVNode, renderContent, renderLNodeJSX, renderLNodeJSXDefault };
//# sourceMappingURL=render-lnode.js.map
