"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 }; }

var beforeUpload = function beforeUpload(file) {
  return new Promise(function (resolve, reject) {
    var reader = new FileReader();

    reader.onload = function (e) {
      if (e.total > 2 * 1024 * 1024) {
        _2.Dialog.alert({
          content: 'File size must be < 2M',
          // @ts-ignore
          closable: false,
          title: 'Warning'
        });

        reject(new Error('error'));
        return;
      }

      var img = new Image();

      img.onload = function () {
        if (img.width <= 1200) {
          resolve(undefined);
        } else {
          _2.Dialog.alert({
            content: "Image width ".concat(img.width, "px, Exceed limits\uFF01"),
            // @ts-ignore
            closable: false,
            title: 'Warning'
          });

          reject(new Error('error'));
        }
      };

      img.src = reader.result;
    };

    reader.readAsDataURL(file);
  });
};

_reactDom["default"].render( /*#__PURE__*/_react["default"].createElement(_["default"], {
  action: "https://www.easy-mock.com/mock/5b713974309d0d7d107a74a3/alifd/upload",
  limit: 3,
  multiple: true,
  beforeUpload: beforeUpload,
  listType: "text",
  defaultValue: [{
    name: 'IMG.png',
    state: 'done',
    size: 1024,
    downloadURL: 'https://img.alicdn.com/tps/TB19O79MVXXXXcZXVXXXXXXXXXX-1024-1024.jpg',
    fileURL: 'https://img.alicdn.com/tps/TB19O79MVXXXXcZXVXXXXXXXXXX-1024-1024.jpg',
    imgURL: 'https://img.alicdn.com/tps/TB19O79MVXXXXcZXVXXXXXXXXXX-1024-1024.jpg'
  }]
}, /*#__PURE__*/_react["default"].createElement(_2.Button, {
  type: "primary",
  style: {
    margin: '0 0 10px'
  }
}, "Upload file")), document.getElementById('upload-demo-11'));