/**
 * 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 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');

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;
  let 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;
}
const useLNodeJSX = () => {
  const instance = VueCompositionAPI.getCurrentInstance();
  return function (name, options) {
    const params = hooks_renderLnode.getParams(options);
    const defaultNode = hooks_renderLnode.getDefaultNode(options);
    const {
      slots
    } = instance.setupContext;
    let 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);
    const 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;
  };
};
const useLNodeDefault = () => {
  const renderTNodeJSX = useLNodeJSX();
  return function (name, options) {
    const defaultNode = hooks_renderLnode.getDefaultNode(options);
    return renderTNodeJSX(name, options) || defaultNode;
  };
};
const useContent = () => {
  const renderLNodeJSX = useLNodeJSX();
  return function (name1, name2, options) {
    const params = hooks_renderLnode.getParams(options);
    const defaultNode = hooks_renderLnode.getDefaultNode(options);
    const toParams = params ? {
      params
    } : void 0;
    const node1 = renderLNodeJSX(name1, toParams);
    const node2 = renderLNodeJSX(name2, toParams);
    const 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
