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

import Vue from 'vue';
import { camelCase, kebabCase } from 'lodash';

const RenderJsTypes = [Function, String, Number, Boolean, Object, Array];
var RenderWay = /* @__PURE__ */(RenderWay2 => {
  RenderWay2["Text"] = "text";
  RenderWay2["JsonString"] = "jsonstring";
  RenderWay2["VNode"] = "vnode";
  RenderWay2["Unknown"] = "unknown";
  return RenderWay2;
})(RenderWay || {});
function handleSlots(vm, params, name) {
  var _vm$$scopedSlots$came, _vm$$scopedSlots, _vm$$scopedSlots$keba, _vm$$scopedSlots2;
  let node = (_vm$$scopedSlots$came = (_vm$$scopedSlots = vm.$scopedSlots)[camelCase(name)]) === null || _vm$$scopedSlots$came === void 0 ? void 0 : _vm$$scopedSlots$came.call(_vm$$scopedSlots, params);
  if (node) return node;
  node = (_vm$$scopedSlots$keba = (_vm$$scopedSlots2 = vm.$scopedSlots)[kebabCase(name)]) === null || _vm$$scopedSlots$keba === void 0 ? void 0 : _vm$$scopedSlots$keba.call(_vm$$scopedSlots2, 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) return "vnode" /* VNode */;
    return "jsonstring" /* JsonString */;
  }

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

const RenderLNodeTemplate = Vue.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[camelCase(name)] || vm.$scopedSlots[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;
};

export { RenderLNodeTemplate, handleSlots, renderContent, renderLNodeJSX, renderLNodeJSXDefault };
//# sourceMappingURL=render-node.js.map
