"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 _upload = _interopRequireDefault(require("@alifd/next/lib/upload"));

var _configProvider = _interopRequireDefault(require("../config-provider"));

var _propTypes = _interopRequireDefault(require("prop-types"));

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

var _classnames = _interopRequireDefault(require("classnames"));

var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));

var _index = require("../index");

var _getTheme = require("../utils/getTheme");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

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

// CardUpload
// 图片预览功能，只有图片列表在全部完成上传状态时才有
// const showImg = url => {
//   Dialog.show({
//     title: 'img preview',
//     content: <img src={url} style={{ width: 400, height: 400 }} />,
//     footer: false,
//   });
// };
var CardUpload = /*#__PURE__*/function (_Component) {
  _inherits(CardUpload, _Component);

  var _super = _createSuper(CardUpload);

  function CardUpload() {
    _classCallCheck(this, CardUpload);

    return _super.apply(this, arguments);
  }

  _createClass(CardUpload, [{
    key: "render",
    value: function render() {
      var _cls;

      var _this$props = this.props,
          _this$props$prefix = _this$props.prefix,
          prefix = _this$props$prefix === void 0 ? 'next-' : _this$props$prefix,
          className = _this$props.className;
      var theme = (0, _getTheme.getTheme)(this.context, this.props); // card预览功能
      // const itemRender = file => {
      //   return (
      //     <div >
      //       <img src={file.url} style={{ maxWidth: '100%', maxHeight: '100%' }} />
      //       <div className={`${prefix}card-preview`}
      //         style={{
      //           position: 'absolute',
      //           top: 0,
      //           right: 0,
      //           bottom: 0,
      //           left: 0,
      //           background: 'rgba(0,0,0,.5)',
      //           color: '#ddd',
      //           display: 'flex',
      //           flexDirection: 'row',
      //           justifyContent: 'center',
      //           alignItems: 'center',
      //         }}
      //       >
      //         <Button
      //           // text
      //           onClick={e => {
      //             e.preventDefault();
      //             showImg(file.url);
      //           }}
      //           size="small"
      //           style={{ background: 'transparent', borderColor: 'transparent', boxShadow: 'none', padding: 0 }}
      //         >
      //           <Icon type="eye" style={{ marginRight: 12, cursor: 'pointer', color: '#fff' }} />
      //         </Button>
      //         <Button size="small" component="a" href={file.url} target="_blank" style={{ background: 'transparent', borderColor: 'transparent', boxShadow: 'none', padding: 0 }}>
      //           <Icon type="download" style={{ cursor: 'pointer', color: '#fff' }} />
      //         </Button>
      //       </div>
      //     </div>
      //   );
      // };

      return /*#__PURE__*/_react["default"].createElement(_upload["default"].Card, _extends({}, this.props, {
        // @ts-ignore
        // itemRender={disabled ? undefined : itemRender}
        className: (0, _classnames["default"])(className, (_cls = {}, _defineProperty(_cls, "".concat(prefix, "white"), theme === 'white'), _defineProperty(_cls, "".concat(prefix, "grey"), theme === 'grey'), _cls))
      }));
    }
  }]);

  return CardUpload;
}(_react.Component); // DraggerUpload


_defineProperty(CardUpload, "contextTypes", {
  theme: _propTypes["default"].string
});

var DraggerUpload = /*#__PURE__*/function (_Component2) {
  _inherits(DraggerUpload, _Component2);

  var _super2 = _createSuper(DraggerUpload);

  function DraggerUpload(props) {
    var _this;

    _classCallCheck(this, DraggerUpload);

    _this = _super2.call(this, props);

    _defineProperty(_assertThisInitialized(_this), "handleProgress", function () {
      _this.setState({
        progress: true
      });
    });

    _defineProperty(_assertThisInitialized(_this), "handleChange", function () {
      _this.setState({
        progress: false
      });
    });

    _this.state = {
      progress: false
    };
    return _this;
  }

  _createClass(DraggerUpload, [{
    key: "render",
    value: function render() {
      var _cls2;

      var _this$props2 = this.props,
          _this$props2$prefix = _this$props2.prefix,
          prefix = _this$props2$prefix === void 0 ? 'next-' : _this$props2$prefix,
          _this$props2$listType = _this$props2.listType,
          listType = _this$props2$listType === void 0 ? 'text' : _this$props2$listType,
          className = _this$props2.className,
          children = _this$props2.children,
          onProgress = _this$props2.onProgress,
          size = _this$props2.size;
      var theme = (0, _getTheme.getTheme)(this.context, this.props);
      return /*#__PURE__*/_react["default"].createElement(_upload["default"], _extends({}, this.props, {
        listType: listType,
        dragable: true,
        onProgress: onProgress ? onProgress : this.handleProgress,
        onChange: this.handleChange,
        className: (0, _classnames["default"])(className, (_cls2 = {}, _defineProperty(_cls2, "".concat(prefix, "white"), theme === 'white'), _defineProperty(_cls2, "".concat(prefix, "grey"), theme === 'grey'), _defineProperty(_cls2, "".concat(prefix, "on-progress"), this.state.progress === true), _defineProperty(_cls2, "".concat(prefix, "all-finish"), this.state.progress === false), _defineProperty(_cls2, "".concat(prefix, "small"), size === 'small'), _defineProperty(_cls2, "".concat(prefix, "medium"), size === 'medium'), _defineProperty(_cls2, "".concat(prefix, "large"), size === 'large'), _defineProperty(_cls2, "".concat(prefix, "text-list"), listType === 'text'), _defineProperty(_cls2, "".concat(prefix, "img-list"), listType === 'image'), _cls2))
      }), /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefix, "upload-drag")
      }, /*#__PURE__*/_react["default"].createElement("p", {
        className: "".concat(prefix, "upload-drag-icon")
      }, /*#__PURE__*/_react["default"].createElement(_index.Icon, {
        type: "upload"
      })), /*#__PURE__*/_react["default"].createElement("p", {
        className: "".concat(prefix, "upload-drag-text")
      }, "\u62D6\u62FD\u81F3\u6B64\uFF0C\u6216 ", ' ', " ", /*#__PURE__*/_react["default"].createElement("a", {
        className: "".concat(prefix, "upload-drag-a")
      }, "\u70B9\u51FB\u4E0A\u4F20"))), children);
    }
  }]);

  return DraggerUpload;
}(_react.Component); // Upload


_defineProperty(DraggerUpload, "contextTypes", {
  theme: _propTypes["default"].string
});

var Upload = /*#__PURE__*/function (_Component3) {
  _inherits(Upload, _Component3);

  var _super3 = _createSuper(Upload);

  function Upload(props) {
    var _this2;

    _classCallCheck(this, Upload);

    _this2 = _super3.call(this, props);

    _defineProperty(_assertThisInitialized(_this2), "handleProgress", function () {
      _this2.setState({
        progress: true
      });
    });

    _defineProperty(_assertThisInitialized(_this2), "handleChange", function () {
      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }

      _this2.setState({
        value: args[0],
        progress: false
      });

      var onChange = _this2.props.onChange;
      onChange && onChange.apply(null, [].concat(args));
    });

    _defineProperty(_assertThisInitialized(_this2), "showImg", function (url) {
      _index.Dialog.show({
        title: 'img preview',
        content: /*#__PURE__*/_react["default"].createElement("img", {
          src: url,
          style: {
            width: 400,
            height: 400
          }
        }),
        footer: false
      });
    });

    _defineProperty(_assertThisInitialized(_this2), "actionRender", function (file) {
      return /*#__PURE__*/_react["default"].createElement("span", {
        className: "extra-icons",
        style: {
          position: 'absolute',
          right: 50,
          top: '50%'
        }
      }, /*#__PURE__*/_react["default"].createElement(_index.Button // text
      , {
        onClick: function onClick(e) {
          e.preventDefault();

          _this2.showImg(file.url);
        },
        size: "medium",
        style: {
          background: 'transparent',
          borderColor: 'transparent',
          boxShadow: 'none',
          padding: 0
        }
      }, /*#__PURE__*/_react["default"].createElement(_index.Icon, {
        type: "eye",
        style: {
          color: '#737373',
          marginRight: 12,
          cursor: 'pointer'
        }
      })), /*#__PURE__*/_react["default"].createElement(_index.Button, {
        size: "medium",
        component: "a",
        href: file.url,
        target: "_blank",
        style: {
          background: 'transparent',
          borderColor: 'transparent',
          boxShadow: 'none',
          padding: 0
        }
      }, /*#__PURE__*/_react["default"].createElement(_index.Icon, {
        type: "download",
        style: {
          color: '#737373',
          cursor: 'pointer'
        }
      })));
    });

    _this2.state = {
      progress: false,
      value: props.value || props.defaultValue
    };
    return _this2;
  }

  _createClass(Upload, [{
    key: "render",
    value: function render() {
      var _cls3;

      var theme = (0, _getTheme.getTheme)(this.context, this.props);
      var _this$props3 = this.props,
          _this$props3$prefix = _this$props3.prefix,
          prefix = _this$props3$prefix === void 0 ? 'next-' : _this$props3$prefix,
          className = _this$props3.className,
          onProgress = _this$props3.onProgress,
          _this$props3$size = _this$props3.size,
          size = _this$props3$size === void 0 ? 'small' : _this$props3$size,
          listType = _this$props3.listType,
          actionRender = _this$props3.actionRender;
      return /*#__PURE__*/_react["default"].createElement(_upload["default"], _extends({}, this.props, {
        className: (0, _classnames["default"])(className, (_cls3 = {}, _defineProperty(_cls3, "".concat(prefix, "white"), theme === 'white'), _defineProperty(_cls3, "".concat(prefix, "grey"), theme === 'grey'), _defineProperty(_cls3, "".concat(prefix, "on-progress"), this.state.progress === true), _defineProperty(_cls3, "".concat(prefix, "all-finish"), this.state.progress === false), _defineProperty(_cls3, "".concat(prefix, "small"), size === 'small'), _defineProperty(_cls3, "".concat(prefix, "medium"), size === 'medium'), _defineProperty(_cls3, "".concat(prefix, "large"), size === 'large'), _defineProperty(_cls3, "".concat(prefix, "text-list"), listType === 'text'), _defineProperty(_cls3, "".concat(prefix, "img-list"), listType === 'image'), _cls3)),
        value: this.state.value,
        onProgress: onProgress ? onProgress : this.handleProgress,
        actionRender: actionRender ? actionRender : this.state.progress === false ? listType === 'image' ? this.actionRender : undefined : undefined,
        onChange: this.handleChange
      }));
    }
  }]);

  return Upload;
}(_react.Component);

_defineProperty(Upload, "contextTypes", void 0);

_defineProperty(Upload, "Card", void 0);

_defineProperty(Upload, "Dragger", void 0);

_defineProperty(Upload, "Uploader", void 0);

_defineProperty(Upload, "Selecter", void 0);

(0, _hoistNonReactStatics["default"])(Upload, _upload["default"]);
Upload.contextTypes = {
  theme: _propTypes["default"].string
};
Upload.Card = _configProvider["default"].config(CardUpload);
Upload.Dragger = _configProvider["default"].config(DraggerUpload);

var _default = _configProvider["default"].config(Upload);

exports["default"] = _default;