/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var isEmpty = require('lodash/isEmpty');
var isString = require('lodash/isString');
var isFunction = require('lodash/isFunction');
var isObject = require('lodash/isObject');
var camelCase = require('lodash/camelCase');
var kebabCase = require('lodash/kebabCase');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
var camelCase__default = /*#__PURE__*/_interopDefaultLegacy(camelCase);
var kebabCase__default = /*#__PURE__*/_interopDefaultLegacy(kebabCase);

var isVNode = function isVNode(obj) {
  var vNode = VueCompositionAPI.h("span", "");
  var VNode2 = vNode.constructor;
  return obj instanceof VNode2;
};
function getDefaultNode(options) {
  var defaultNode;

  if (isObject__default["default"](options) && "defaultNode" in options) {
    defaultNode = options.defaultNode;
  } else if (isVNode(options) || isString__default["default"](options)) {
    defaultNode = options;
  }

  return defaultNode;
}
function getParams(options) {
  return isObject__default["default"](options) && "params" in options ? options.params : null;
}
function handleSlots(instance, params, name) {
  var _instance$$slots$came, _instance$$slots, _instance$$slots$keba, _instance$$slots2;

  var node = (_instance$$slots$came = (_instance$$slots = instance.$slots)[camelCase__default["default"](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)[kebabCase__default["default"](name)]) === null || _instance$$slots$keba === void 0 ? void 0 : _instance$$slots$keba.call(_instance$$slots2, params);
  if (node) return node;
  return null;
}
var renderLNodeJSX = function renderLNodeJSX(instance, name, options) {
  var params = getParams(options);
  var defaultNode = getDefaultNode(options);
  var propsNode;

  if (name in instance) {
    propsNode = instance[name];
  }

  if (propsNode === false) return;

  if (propsNode === true && defaultNode) {
    return handleSlots(instance, params, name) || defaultNode;
  }

  if (isFunction__default["default"](propsNode)) return propsNode(VueCompositionAPI.h, params);
  var isPropsEmpty = [void 0, params, ""].includes(propsNode);

  if (isPropsEmpty && (instance.$slots[camelCase__default["default"](name)] || instance.$slots[kebabCase__default["default"](name)])) {
    return handleSlots(instance, params, name);
  }

  return propsNode;
};
var renderLNodeJSXDefault = function renderLNodeJSXDefault(vm, name, options) {
  var defaultNode = getDefaultNode(options);
  return renderLNodeJSX(vm, name, options) || defaultNode;
};
var renderContent = function renderContent(vm, name1, name2, options) {
  var params = getParams(options);
  var defaultNode = getDefaultNode(options);
  var toParams = params ? {
    params: params
  } : void 0;
  var node1 = renderLNodeJSX(vm, name1, toParams);
  var node2 = renderLNodeJSX(vm, name2, toParams);
  var res = isEmpty__default["default"](node1) ? node2 : node1;
  return isEmpty__default["default"](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
