"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "PropTypes", {
  enumerable: true,
  get: function get() {
    return _vueTypes.default;
  }
});
Object.defineProperty(exports, "isImg", {
  enumerable: true,
  get: function get() {
    return _isImg.default;
  }
});
Object.defineProperty(exports, "isUrl", {
  enumerable: true,
  get: function get() {
    return _isUrl.default;
  }
});
Object.defineProperty(exports, "isNil", {
  enumerable: true,
  get: function get() {
    return _isNil.default;
  }
});
exports.getRenderComponent = exports.withFCInstall = exports.withInstall = exports.PropRenderType = void 0;

var _vue = require("vue");

var _vueTypes = _interopRequireDefault(require("ant-design-vue/es/_util/vue-types"));

var _isImg = _interopRequireDefault(require("./isImg"));

var _isUrl = _interopRequireDefault(require("./isUrl"));

var _isNil = _interopRequireDefault(require("./isNil"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

/**
 * 从属性或插槽获取组件，没有时返回默认组件
 * @param name 属性或插槽名称
 * @param props 属性
 * @param slots 插槽
 * @param def 默认值
 * @param args 渲染函数和插槽的参数
 */
var getRenderComponent = function getRenderComponent(name, props, slots, def, args) {
  var prop = props[name];
  var slot = slots[name];

  if ((0, _vue.isVNode)(prop)) {
    return prop;
  } else if (prop && typeof prop === 'function') {
    return prop.apply(void 0, _toConsumableArray(args === null || args === void 0 ? void 0 : args.propsArgs));
  } else if (prop === true) {
    return def;
  } else if (prop === false) {
    return false;
  } else if (prop) {
    return prop;
  } else if (slot) {
    return slot(args === null || args === void 0 ? void 0 : args.slotArg);
  }

  return def;
};

exports.getRenderComponent = getRenderComponent;
var PropRenderType = {
  type: [Function, Boolean, String, Object],
  default: function _default() {
    return undefined;
  }
};
exports.PropRenderType = PropRenderType;

var withInstall = function withInstall(comp) {
  var c = comp;

  if (!c.install) {
    c.install = function (app) {
      app.component(c.displayName || c.name, comp);
    };
  }

  return c;
};

exports.withInstall = withInstall;

var withFCInstall = function withFCInstall(comp) {
  if (!comp.install) {
    comp.install = function (app) {
      app.component(comp.displayName || comp.name, comp);
    };
  }

  return comp;
};

exports.withFCInstall = withFCInstall;