/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _typeof from '@babel/runtime/helpers/typeof';
import Vue from 'vue';

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 || {});

var getValueRenderWay = function getValueRenderWay(value) {
  if (["string", "number", "boolean"].includes(_typeof(value))) return "text"
  /* Text */
  ;

  if (_typeof(value) === "object") {
    if (!(value instanceof Array) && value && value.context instanceof Vue) {
      return "vnode"
      /* VNode */
      ;
    }

    return "jsonstring"
    /* JsonString */
    ;
  }

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

var RenderTNodeTemplate = Vue.extend({
  name: "render-tnode-template",
  functional: true,
  props: {
    render: RenderJsTypes,
    params: null
  },
  render: function render(h, ctx) {
    var _renderMap;

    var _ctx$props = ctx.props,
        render = _ctx$props.render,
        params = _ctx$props.params;
    var renderResult = typeof render === "function" ? render(h, 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) : h();
  }
});
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 vm.$scopedSlots[name] ? vm.$scopedSlots[name](params) : defaultNode;
  }

  if (typeof propsNode === "function") return propsNode(vm.$createElement, params);
  var isPropsEmpty = [void 0, params, ""].includes(propsNode);
  if (isPropsEmpty && vm.$scopedSlots[name]) return vm.$scopedSlots[name](params);
  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, renderContent, renderTNodeJSX, renderTNodeJSXDefault };
//# sourceMappingURL=render-tnode.js.map
