"use strict";

var _react = _interopRequireDefault(require("react"));

var _reactDom = _interopRequireDefault(require("react-dom"));

var _ = _interopRequireDefault(require(".."));

var _2 = require("../..");

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

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var requestOpts = {
  action: 'https://www.easy-mock.com/mock/5b713974309d0d7d107a74a3/alifd/upload',
  data: {
    osstoken: 1234
  },
  headers: {
    'X-Requested-With': 12345
  }
};

function beforeUpload(file, options) {
  console.log('beforeUpload callback : ', file, options);
  return requestOpts;
}

function asyncBeforeUpload(_x, _x2) {
  return _asyncBeforeUpload.apply(this, arguments);
}

function _asyncBeforeUpload() {
  _asyncBeforeUpload = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(file, options) {
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            console.log('beforeUpload callback : ', file, options);
            _context.next = 3;
            return new Promise(function (resolve) {
              setTimeout(function () {
                resolve(requestOpts);
              }, 1e3);
            });

          case 3:
            return _context.abrupt("return", _context.sent);

          case 4:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _asyncBeforeUpload.apply(this, arguments);
}

function onChange(file) {
  console.log('onChange callback : ', file);
}

_reactDom["default"].render([/*#__PURE__*/_react["default"].createElement(_["default"], {
  listType: "text",
  action: "https://www.easy-mock.com/mock/5b713974309d0d7d107a74a3/alifd/upload",
  accept: "image/png, image/jpg, image/jpeg, image/gif, image/bmp",
  beforeUpload: beforeUpload,
  onChange: onChange,
  key: "1"
}, /*#__PURE__*/_react["default"].createElement(_2.Button, {
  type: "primary",
  style: {
    margin: '0 0 10px'
  }
}, "Upload File")), /*#__PURE__*/_react["default"].createElement(_["default"], {
  listType: "text",
  action: "https://www.easy-mock.com/mock/5b713974309d0d7d107a74a3/alifd/upload",
  accept: "image/png, image/jpg, image/jpeg, image/gif, image/bmp",
  beforeUpload: asyncBeforeUpload,
  onChange: onChange,
  key: "2"
}, /*#__PURE__*/_react["default"].createElement(_2.Button, {
  type: "secondary",
  style: {
    margin: '0 0 10px'
  }
}, "Async Call before Upload File")), /*#__PURE__*/_react["default"].createElement(_["default"], {
  listType: "text",
  action: "https://www.easy-mock.com/mock/5b713974309d0d7d107a74a3/alifd/upload",
  accept: "image/png, image/jpg, image/jpeg, image/gif, image/bmp",
  beforeUpload: function beforeUpload() {
    return false;
  },
  onChange: onChange,
  key: "3"
}, /*#__PURE__*/_react["default"].createElement(_2.Button, {
  type: "normal",
  style: {
    margin: '0 0 10px'
  }
}, "Prevent Upload")), /*#__PURE__*/_react["default"].createElement(_["default"], {
  listType: "text",
  action: "https://www.easy-mock.com/mock/5b713974309d0d7d107a74a3/alifd/upload",
  accept: "image/png, image/jpg, image/jpeg, image/gif, image/bmp",
  beforeUpload: function beforeUpload() {
    return new Promise(function (resovle, reject) {
      return setTimeout(function () {
        return reject(new Error('error'));
      });
    });
  },
  onChange: onChange,
  key: "4"
}, /*#__PURE__*/_react["default"].createElement(_2.Button, {
  type: "primary",
  style: {
    margin: '0 0 10px'
  }
}, "Async Prevent Upload"))], document.getElementById('upload-demo-13'));