/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var VueCompositionAPI = require('@vue/composition-api');
var lodash = require('lodash');

const isVNode = obj => {
  const vNode = VueCompositionAPI.h("span", "");
  const VNode = vNode.constructor;
  return obj instanceof VNode;
};
function getDefaultNode(options) {
  let defaultNode;
  if (lodash.isObject(options) && "defaultNode" in options) defaultNode = options.defaultNode;else if (isVNode(options) || lodash.isString(options)) defaultNode = options;
  return defaultNode;
}
function getParams(options) {
  return lodash.isObject(options) && "params" in options ? options.params : null;
}
function handleSlots(instance, params, name) {
  var _instance$$slots$came, _instance$$slots, _instance$$slots$keba, _instance$$slots2;
  let node = (_instance$$slots$came = (_instance$$slots = instance.$slots)[lodash.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)[lodash.kebabCase(name)]) === null || _instance$$slots$keba === void 0 ? void 0 : _instance$$slots$keba.call(_instance$$slots2, 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 (lodash.isFunction(propsNode)) return propsNode(VueCompositionAPI.h, params);
  const isPropsEmpty = [void 0, params, ""].includes(propsNode);
  const hasSlots = instance.$slots[lodash.camelCase(name)] || instance.$slots[lodash.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 = lodash.isEmpty(node1) ? node2 : node1;
  return lodash.isEmpty(res) ? defaultNode : res;
};

exports.getDefaultNode = getDefaultNode;
exports.getParams = getParams;
exports.handleSlots = handleSlots;
exports.isVNode = isVNode;
exports.renderContent = renderContent;
exports.renderLNodeJSX = renderLNodeJSX;
exports.renderLNodeJSXDefault = renderLNodeJSXDefault;
//# sourceMappingURL=render-lnode.js.map
