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

import { getCurrentInstance, h } from '@vue/composition-api';
import isEmpty from 'lodash/isEmpty';
import isFunction from 'lodash/isFunction';
import camelCase from 'lodash/camelCase';
import kebabCase from 'lodash/kebabCase';
import { getParams, getDefaultNode } from './render-lnode.js';
import 'lodash';

function handleSlots(slots, name, params) {
  var _slots$camelCase, _slots$kebabCase;
  let node = (_slots$camelCase = slots[camelCase(name)]) === null || _slots$camelCase === void 0 ? void 0 : _slots$camelCase.call(slots, params);
  if (node) return node;
  node = (_slots$kebabCase = slots[kebabCase(name)]) === null || _slots$kebabCase === void 0 ? void 0 : _slots$kebabCase.call(slots, params);
  if (node) return node;
  return null;
}
const useLNodeJSX = () => {
  const instance = getCurrentInstance();
  return function (name, options) {
    const params = getParams(options);
    const defaultNode = 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(propsNode)) return propsNode(h, params);
    const isPropsEmpty = [void 0, params, ""].includes(propsNode);
    if (isPropsEmpty && (slots[camelCase(name)] || slots[kebabCase(name)])) return handleSlots(slots, name, params);
    return propsNode;
  };
};
const useLNodeDefault = () => {
  const renderTNodeJSX = useLNodeJSX();
  return function (name, options) {
    const defaultNode = getDefaultNode(options);
    return renderTNodeJSX(name, options) || defaultNode;
  };
};
const useContent = () => {
  const renderLNodeJSX = useLNodeJSX();
  return function (name1, name2, options) {
    const params = getParams(options);
    const defaultNode = getDefaultNode(options);
    const toParams = params ? {
      params
    } : void 0;
    const node1 = renderLNodeJSX(name1, toParams);
    const node2 = renderLNodeJSX(name2, toParams);
    const res = isEmpty(node1) ? node2 : node1;
    return isEmpty(res) ? defaultNode : res;
  };
};

export { useContent, useLNodeDefault, useLNodeJSX };
//# sourceMappingURL=lnode.js.map
