/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

'use strict';

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

var Vue = require('vue');
var lodash = require('lodash');

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

var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

const RenderJsTypes = [Function, String, Number, Boolean, Object, Array];
function handleSlots(vm, params, name) {
  let node = vm.$scopedSlots[lodash.camelCase(name)]?.(params);
  if (node) return node;
  node = vm.$scopedSlots[lodash.kebabCase(name)]?.(params);
  if (node) return node;
  return null;
}
const getValueRenderWay = value => {
  if (["string", "number", "boolean"].includes(typeof value)) return "text" /* Text */;
  if (typeof value === "object") {
    if (!Array.isArray(value) && value && value.context instanceof Vue__default["default"]) return "vnode" /* VNode */;
    return "jsonstring" /* JsonString */;
  }

  return "unknown" /* Unknown */;
};

const RenderLNodeTemplate = Vue__default["default"].extend({
  name: "RenderLnodeTemplate",
  functional: true,
  props: {
    render: RenderJsTypes,
    params: null
  },
  render(h, ctx) {
    const {
      render,
      params
    } = ctx.props;
    const renderResult = typeof render === "function" ? render(h, params) : render;
    const renderWay = getValueRenderWay(renderResult);
    const renderText = c => ctx.__proto__._v(c);
    const renderMap = {
      ["text" /* Text */]: c => renderText(c),
      ["jsonstring" /* JsonString */]: c => renderText(JSON.stringify(c, null, 2)),
      ["vnode" /* VNode */]: c => c
    };
    return renderMap[renderWay] ? renderMap[renderWay](renderResult) : h();
  }
});
const renderLNodeJSX = (vm, name, options) => {
  const params = typeof options === "object" && "params" in options ? options.params : null;
  const defaultNode = typeof options === "object" && "defaultNode" in options ? options.defaultNode : options;
  const propsNode = vm[name];
  if (propsNode === false) return;
  if (propsNode === true && defaultNode) return handleSlots(vm, params, name) || defaultNode;
  if (typeof propsNode === "function") return propsNode(vm.$createElement, params);
  const isPropsEmpty = [void 0, params, ""].includes(propsNode);
  if (isPropsEmpty && (vm.$scopedSlots[lodash.camelCase(name)] || vm.$scopedSlots[lodash.kebabCase(name)])) return handleSlots(vm, params, name);
  return propsNode;
};
const renderLNodeJSXDefault = (vm, name, options) => {
  const defaultNode = typeof options === "object" && "defaultNode" in options ? options.defaultNode : options;
  return renderLNodeJSX(vm, name, options) || defaultNode;
};
const renderContent = (vm, name1, name2, options) => {
  const params = typeof options === "object" && "params" in options ? options.params : null;
  let defaultNode = typeof options === "object" && "defaultNode" in options && options.defaultNode;
  defaultNode = typeof options === "object" && "context" in options && options;
  const toParams = params ? {
    params
  } : void 0;
  const node1 = renderLNodeJSX(vm, name1, toParams);
  const node2 = renderLNodeJSX(vm, name2, toParams);
  const r = [void 0, null, ""].includes(node1) ? node2 : node1;
  return [void 0, null, ""].includes(r) ? defaultNode : r;
};

exports.RenderLNodeTemplate = RenderLNodeTemplate;
exports.handleSlots = handleSlots;
exports.renderContent = renderContent;
exports.renderLNodeJSX = renderLNodeJSX;
exports.renderLNodeJSXDefault = renderLNodeJSXDefault;
//# sourceMappingURL=render-node.js.map
