/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _typeof from '@babel/runtime/helpers/typeof';
import Vue from 'vue';
import { h } from '@vue/composition-api';
import camelCase from 'lodash/camelCase';
import kebabCase from 'lodash/kebabCase';

var RenderJsTypes = [Function, String, Number, Boolean, Object, Array];
var RenderWay = /* @__PURE__ */function (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;
  var finaleParams = h;
  if (params) Object.assign(finaleParams, params);
  var node = (_vm$$scopedSlots$came = (_vm$$scopedSlots = vm.$scopedSlots)[camelCase(name)]) === null || _vm$$scopedSlots$came === void 0 ? void 0 : _vm$$scopedSlots$came.call(_vm$$scopedSlots, finaleParams);
  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, finaleParams);
  if (node) return node;
  return null;
}
var getValueRenderWay = function 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 */;
};

var RenderTNodeTemplate = Vue.extend({
  name: "RenderTnodeTemplate",
  functional: true,
  props: {
    render: RenderJsTypes,
    params: null
  },
  render: function render(h2, ctx) {
    var _renderMap;
    var _ctx$props = ctx.props,
      render = _ctx$props.render,
      params = _ctx$props.params;
    var renderResult = typeof render === "function" ? render(h2, params) : render;
    var renderWay = getValueRenderWay(renderResult);
    var renderText = function renderText(c) {
      return ctx.__proto__._v(c);
    };
    var renderMap = (_renderMap = {}, _defineProperty(_renderMap, "text" /* Text */, function text(c) {
      return renderText(c);
    }), _defineProperty(_renderMap, "jsonstring" /* JsonString */, function jsonstring(c) {
      return renderText(JSON.stringify(c, null, 2));
    }), _defineProperty(_renderMap, "vnode" /* VNode */, function vnode(c) {
      return c;
    }), _renderMap);
    return renderMap[renderWay] ? renderMap[renderWay](renderResult) : h2();
  }
});
var renderTNodeJSX = function renderTNodeJSX(vm, name, options) {
  var params = _typeof(options) === "object" && "params" in options ? options.params : null;
  var defaultNode = _typeof(options) === "object" && "defaultNode" in options ? options.defaultNode : options;
  var 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);
  var isPropsEmpty = [void 0, params, ""].includes(propsNode);
  if (isPropsEmpty && (vm.$scopedSlots[camelCase(name)] || vm.$scopedSlots[kebabCase(name)])) return handleSlots(vm, params, name);
  return propsNode;
};
var renderTNodeJSXDefault = function renderTNodeJSXDefault(vm, name, options) {
  var defaultNode = _typeof(options) === "object" && "defaultNode" in options ? options.defaultNode : options;
  return renderTNodeJSX(vm, name, options) || defaultNode;
};
var renderContent = function renderContent(vm, name1, name2, options) {
  var params = _typeof(options) === "object" && "params" in options ? options.params : null;
  var defaultNode = _typeof(options) === "object" && "defaultNode" in options && options.defaultNode;
  defaultNode = _typeof(options) === "object" && "context" in options && options;
  var toParams = params ? {
    params: params
  } : void 0;
  var node1 = renderTNodeJSX(vm, name1, toParams);
  var node2 = renderTNodeJSX(vm, name2, toParams);
  var r = [void 0, null, ""].includes(node1) ? node2 : node1;
  return [void 0, null, ""].includes(r) ? defaultNode : r;
};

export { RenderTNodeTemplate, handleSlots, renderContent, renderTNodeJSX, renderTNodeJSXDefault };
//# sourceMappingURL=render-tnode.js.map
