/**
 * 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 isFunction = require('lodash/isFunction');
var camelCase = require('lodash/camelCase');
var kebabCase = require('lodash/kebabCase');
var hooks_renderLnode = require('./render-lnode.js');
require('lodash/isString');
require('lodash/isObject');

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

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

function handleSlots(slots, name, params) {
  var _slots$camelCase, _slots$kebabCase;

  var node = (_slots$camelCase = slots[camelCase__default["default"](name)]) === null || _slots$camelCase === void 0 ? void 0 : _slots$camelCase.call(slots, params);
  if (node) return node;
  node = (_slots$kebabCase = slots[kebabCase__default["default"](name)]) === null || _slots$kebabCase === void 0 ? void 0 : _slots$kebabCase.call(slots, params);
  if (node) return node;
  return null;
}

var useLNodeJSX = function useLNodeJSX() {
  var instance = VueCompositionAPI.getCurrentInstance();
  return function (name, options) {
    var params = hooks_renderLnode.getParams(options);
    var defaultNode = hooks_renderLnode.getDefaultNode(options);
    var slots = instance.setupContext.slots;
    var propsNode;

    if (Object.keys(instance.props).includes(name)) {
      propsNode = instance.props[name];
    }

    if (propsNode === false) return;

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

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

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

    return propsNode;
  };
};
var useLNodeDefault = function useLNodeDefault() {
  var renderTNodeJSX = useLNodeJSX();
  return function (name, options) {
    var defaultNode = hooks_renderLnode.getDefaultNode(options);
    return renderTNodeJSX(name, options) || defaultNode;
  };
};
var useContent = function useContent() {
  var renderLNodeJSX = useLNodeJSX();
  return function (name1, name2, options) {
    var params = hooks_renderLnode.getParams(options);
    var defaultNode = hooks_renderLnode.getDefaultNode(options);
    var toParams = params ? {
      params: params
    } : void 0;
    var node1 = renderLNodeJSX(name1, toParams);
    var node2 = renderLNodeJSX(name2, toParams);
    var res = isEmpty__default["default"](node1) ? node2 : node1;
    return isEmpty__default["default"](res) ? defaultNode : res;
  };
};

exports.useContent = useContent;
exports.useLNodeDefault = useLNodeDefault;
exports.useLNodeJSX = useLNodeJSX;
//# sourceMappingURL=lnode.js.map
