"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _vue = _interopRequireWildcard(require("vue"));

var _vueTypes = _interopRequireDefault(require("../../_util/vue-types"));

var _propsUtil = require("../../_util/props-util");

var _BaseMixin = _interopRequireDefault(require("../../_util/BaseMixin"));

var _AjaxUploader = _interopRequireDefault(require("./AjaxUploader"));

var _IframeUploader = _interopRequireDefault(require("./IframeUploader"));

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function empty() {}

var uploadProps = {
  componentTag: _vueTypes.default.string,
  prefixCls: _vueTypes.default.string,
  action: _vueTypes.default.oneOfType([_vueTypes.default.string, _vueTypes.default.func]),
  name: _vueTypes.default.string,
  multipart: _vueTypes.default.bool,
  directory: _vueTypes.default.bool,
  onError: _vueTypes.default.func,
  onSuccess: _vueTypes.default.func,
  onProgress: _vueTypes.default.func,
  onStart: _vueTypes.default.func,
  data: _vueTypes.default.oneOfType([_vueTypes.default.object, _vueTypes.default.func]),
  headers: _vueTypes.default.object,
  accept: _vueTypes.default.string,
  multiple: _vueTypes.default.bool,
  disabled: _vueTypes.default.bool,
  beforeUpload: _vueTypes.default.func,
  customRequest: _vueTypes.default.func,
  onReady: _vueTypes.default.func,
  withCredentials: _vueTypes.default.bool,
  supportServerRender: _vueTypes.default.bool,
  openFileDialogOnClick: _vueTypes.default.bool
};
var _default2 = {
  name: 'Upload',
  mixins: [_BaseMixin.default],
  inheritAttrs: false,
  props: (0, _propsUtil.initDefaultProps)(uploadProps, {
    componentTag: 'span',
    prefixCls: 'rc-upload',
    data: {},
    headers: {},
    name: 'file',
    multipart: false,
    onReady: empty,
    onStart: empty,
    onError: empty,
    onSuccess: empty,
    supportServerRender: false,
    multiple: false,
    beforeUpload: empty,
    withCredentials: false,
    openFileDialogOnClick: true
  }),
  data: function data() {
    this.Component = null;
    return {// Component: null, // 组件作为响应式数据，性能比较低，采用强制刷新
    };
  },
  mounted: function mounted() {
    var _this = this;

    this.$nextTick(function () {
      if (_this.supportServerRender) {
        _this.Component = _this.getComponent();

        _this.$forceUpdate();

        (0, _vue.nextTick)(function () {
          _this.__emit('ready');
        });
      }
    });
  },
  methods: {
    getComponent: function getComponent() {
      return typeof File !== 'undefined' ? _AjaxUploader.default : _IframeUploader.default;
    },
    abort: function abort(file) {
      this.$refs.uploaderRef.abort(file);
    }
  },
  render: function render() {
    var _this2 = this;

    var componentProps = _objectSpread(_objectSpread({}, this.$props), {}, {
      ref: 'uploaderRef'
    }, this.$attrs);

    if (this.supportServerRender) {
      var _ComponentUploader = this.Component;

      if (_ComponentUploader) {
        return _vue.createVNode(_ComponentUploader, componentProps, {
          default: function _default() {
            return [(0, _propsUtil.getSlot)(_this2)];
          }
        });
      }

      return null;
    }

    var ComponentUploader = this.getComponent();
    return _vue.createVNode(ComponentUploader, componentProps, {
      default: function _default() {
        return [(0, _propsUtil.getSlot)(_this2)];
      }
    });
  }
};
exports.default = _default2;