"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _i18n = require("../../../../../Framework/i18n");
var _reactFileDrop = _interopRequireDefault(require("react-file-drop"));
var _styles = require("@material-ui/core/styles");
var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
var _FormControlLabel = _interopRequireDefault(require("@material-ui/core/FormControlLabel"));
var _Image = _interopRequireDefault(require("@material-ui/icons/Image"));
var _CheckCircle = _interopRequireDefault(require("@material-ui/icons/CheckCircle"));
var _Error = _interopRequireDefault(require("@material-ui/icons/Error"));
var _Loop = _interopRequireDefault(require("@material-ui/icons/Loop"));
var _Checkbox = _interopRequireDefault(require("@material-ui/core/Checkbox"));
var _FormGroup = _interopRequireDefault(require("@material-ui/core/FormGroup"));
var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
var _MainButton = _interopRequireDefault(require("../../../../../Shared/Components/MainButton"));
var _ServiceLocator = require("../../../../ServiceLocator");
var _withWidth = _interopRequireWildcard(require("@material-ui/core/withWidth"));
var _configuration = require("../../../../configuration");
var _DesignDataService = require("../../../../Services/DesignDataService");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _regeneratorRuntime() { "use strict"; var r = _regenerator(), e = r.m(_regeneratorRuntime), t = (Object.getPrototypeOf ? Object.getPrototypeOf(e) : e.__proto__).constructor; function n(r) { var e = "function" == typeof r && r.constructor; return !!e && (e === t || "GeneratorFunction" === (e.displayName || e.name)); } var o = { "throw": 1, "return": 2, "break": 3, "continue": 3 }; function a(r) { var e, t; return function (n) { e || (e = { stop: function stop() { return t(n.a, 2); }, "catch": function _catch() { return n.v; }, abrupt: function abrupt(r, e) { return t(n.a, o[r], e); }, delegateYield: function delegateYield(r, o, a) { return e.resultName = o, t(n.d, _regeneratorValues(r), a); }, finish: function finish(r) { return t(n.f, r); } }, t = function t(r, _t, o) { n.p = e.prev, n.n = e.next; try { return r(_t, o); } finally { e.next = n.n; } }), e.resultName && (e[e.resultName] = n.v, e.resultName = void 0), e.sent = n.v, e.next = n.n; try { return r.call(this, e); } finally { n.p = e.prev, n.n = e.next; } }; } return (_regeneratorRuntime = function _regeneratorRuntime() { return { wrap: function wrap(e, t, n, o) { return r.w(a(e), t, n, o && o.reverse()); }, isGeneratorFunction: n, mark: r.m, awrap: function awrap(r, e) { return new _OverloadYield(r, e); }, AsyncIterator: _regeneratorAsyncIterator, async: function async(r, e, t, o, u) { return (n(e) ? _regeneratorAsyncGen : _regeneratorAsync)(a(r), e, t, o, u); }, keys: _regeneratorKeys, values: _regeneratorValues }; })(); }
function _regeneratorValues(e) { if (null != e) { var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"], r = 0; if (t) return t.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) return { next: function next() { return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e }; } }; } throw new TypeError(_typeof(e) + " is not iterable"); }
function _regeneratorKeys(e) { var n = Object(e), r = []; for (var t in n) r.unshift(t); return function e() { for (; r.length;) if ((t = r.pop()) in n) return e.value = t, e.done = !1, e; return e.done = !0, e; }; }
function _regeneratorAsync(n, e, r, t, o) { var a = _regeneratorAsyncGen(n, e, r, t, o); return a.next().then(function (n) { return n.done ? n.value : a.next(); }); }
function _regeneratorAsyncGen(r, e, t, o, n) { return new _regeneratorAsyncIterator(_regenerator().w(r, e, t, o), n || Promise); }
function _regeneratorAsyncIterator(t, e) { function n(r, o, i, f) { try { var c = t[r](o), u = c.value; return u instanceof _OverloadYield ? e.resolve(u.v).then(function (t) { n("next", t, i, f); }, function (t) { n("throw", t, i, f); }) : e.resolve(u).then(function (t) { c.value = t, i(c); }, function (t) { return n("throw", t, i, f); }); } catch (t) { f(t); } } var r; this.next || (_regeneratorDefine2(_regeneratorAsyncIterator.prototype), _regeneratorDefine2(_regeneratorAsyncIterator.prototype, "function" == typeof Symbol && Symbol.asyncIterator || "@asyncIterator", function () { return this; })), _regeneratorDefine2(this, "_invoke", function (t, o, i) { function f() { return new e(function (e, r) { n(t, i, e, r); }); } return r = r ? r.then(f, f) : f(); }, !0); }
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
function _OverloadYield(e, d) { this.v = e, this.k = d; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var styles = function styles(theme) {
  var _imagePreview, _imageUploadDropZone, _imageUploadContainer, _imageUploadButton, _imageUploadTextSucce;
  return {
    imagePreview: (_imagePreview = {
      maxWidth: 400,
      maxHeight: 200
    }, _defineProperty(_imagePreview, theme.breakpoints.down('sm'), {
      maxWidth: 300,
      maxHeight: 160
    }), _defineProperty(_imagePreview, "resizeMode", 'contain'), _defineProperty(_imagePreview, "boxShadow", theme.shadows[4]), _imagePreview),
    imageUploadDropZone: (_imageUploadDropZone = {
      background: 'white',
      height: 335,
      width: 450,
      border: '1px dashed #ccc',
      borderRadius: 4,
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center'
    }, _defineProperty(_imageUploadDropZone, theme.breakpoints.down('sm'), {
      width: 'auto'
    }), _defineProperty(_imageUploadDropZone, theme.breakpoints.down('xs'), {
      height: 300
    }), _imageUploadDropZone),
    imageUploadContainer: (_imageUploadContainer = {
      background: 'white',
      width: '100%',
      margin: 30,
      borderRadius: 4
    }, _defineProperty(_imageUploadContainer, theme.breakpoints.down('xs'), {
      margin: 16
    }), _defineProperty(_imageUploadContainer, "display", 'flex'), _defineProperty(_imageUploadContainer, "flexDirection", 'column'), _defineProperty(_imageUploadContainer, "alignItems", 'center'), _imageUploadContainer),
    imageUploadIcon: {
      fontSize: 30,
      marginRight: 5,
      color: theme.palette.primary.darkText
    },
    imageUploadIconError: {
      fontSize: 50,
      marginBottom: 5,
      color: 'red'
    },
    imageUploadIconSuccess: {
      color: '#4FC36D'
    },
    imageUploadButton: (_imageUploadButton = {
      fontSize: 15
    }, _defineProperty(_imageUploadButton, theme.breakpoints.down('xs'), {
      padding: '0 24px',
      height: 56
    }), _defineProperty(_imageUploadButton, '& input', {
      position: 'absolute',
      top: 0,
      left: 0,
      bottom: 0,
      right: 0,
      opacity: 0,
      '&:hover': {
        cursor: 'pointer'
      }
    }), _imageUploadButton),
    imageUploadOwnership: _defineProperty({
      padding: '20px 0px 20px 12px',
      maxWidth: 450,
      minHeight: 65,
      '& span': {
        fontSize: 15
      }
    }, theme.breakpoints.down('sm'), {
      width: 'auto'
    }),
    imageUploadOwnershipCheckbox: {
      marginBottom: 'auto',
      padding: '0 12px'
    },
    colorChecked: {
      '& svg': {
        color: theme.palette.primary.main
      }
    },
    imageUploadChangeImageButton: {
      textTransform: 'none',
      fontWeight: 'bold'
    },
    imageUploadText: _defineProperty({
      margin: '0 100px',
      marginBottom: 10,
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      textAlign: 'center',
      width: '100%'
    }, theme.breakpoints.down('sm'), {
      marginLeft: 0,
      marginRight: 0
    }),
    imageUploadTextError: {
      color: 'red',
      margin: '0 45px 20px'
    },
    imageUploadTextSuccess: (_imageUploadTextSucce = {
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      textAlign: 'left'
    }, _defineProperty(_imageUploadTextSucce, theme.breakpoints.down('sm'), {
      marginLeft: 0,
      marginRight: 0
    }), _defineProperty(_imageUploadTextSucce, "color", '#4FC36D'), _defineProperty(_imageUploadTextSucce, "fontWeight", 'bold'), _imageUploadTextSucce),
    termsAndConditionsLink: {
      color: 'black'
    },
    ownershipError: {
      color: '#f00',
      paddingLeft: 36,
      textAlign: 'initial'
    },
    uploadTextIconContainer: {
      flexDirection: 'row',
      display: 'flex',
      justifyContent: 'center',
      alignItems: 'center',
      marginTop: 10,
      marginBottom: 10,
      width: '100%',
      alignSelf: 'center'
    },
    checkerBackground: {
      backgroundImage: 'linear-gradient(45deg, #F0F0F0 25%, transparent 25%), ' + 'linear-gradient(-45deg, #F0F0F0 25%, transparent 25%), ' + 'linear-gradient(45deg, transparent 75%, #F0F0F0 75%), ' + 'linear-gradient(-45deg, transparent 75%, #F0F0F0 75%)',
      backgroundSize: '20px 20px',
      backgroundPosition: '0 0, 0 10px, 10px -10px, -10px 0px'
    }
  };
};
var ImageEditDialog = /*#__PURE__*/function (_React$Component) {
  _inherits(ImageEditDialog, _React$Component);
  var _super = _createSuper(ImageEditDialog);
  function ImageEditDialog(props) {
    var _this;
    _classCallCheck(this, ImageEditDialog);
    _this = _super.call(this, props);
    _defineProperty(_assertThisInitialized(_this), "handleInputChange", function (evt) {
      return _this.updateFile(evt.target.files[0]);
    });
    _defineProperty(_assertThisInitialized(_this), "handleDrop", function (files) {
      return _this.updateFile(files[0]);
    });
    _defineProperty(_assertThisInitialized(_this), "handleUpload", /*#__PURE__*/function () {
      var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(image) {
        return _regeneratorRuntime().wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              _context.next = 2;
              return (0, _DesignDataService.calculateImageBrightness)(image);
            case 2:
              return _context.abrupt("return", _context.sent);
            case 3:
            case "end":
              return _context.stop();
          }
        }, _callee);
      }));
      return function (_x) {
        return _ref.apply(this, arguments);
      };
    }());
    _defineProperty(_assertThisInitialized(_this), "updateFile", function (file) {
      if (!file) {
        return;
      }
      var _this$props = _this.props,
        uploadSize = _this$props.uploadSize,
        onValidate = _this$props.onValidate;
      var error = null;
      if (file.size > uploadSize) {
        var maxUploadSize = parseFloat((uploadSize / Math.pow(1024, Math.floor(Math.log(uploadSize) / Math.log(1024)))).toFixed(2));
        error = (0, _i18n.t)('fileUpload.uploadSizeError', {
          uploadSize: maxUploadSize
        });
      }
      var extension = file.name.toLowerCase().match(/\.([0-9a-z]+)$/i)[1];
      var allowedFormats = (0, _configuration.getConf)('designer.allowedImageUploadFormats').split(',');
      if (allowedFormats.indexOf(extension) === -1) {
        error = (0, _i18n.t)('fileUpload.uploadFormatError', {
          formats: allowedFormats.join(', ').toUpperCase()
        });
      }
      onValidate && onValidate({
        isValid: !error,
        error: error
      });
      _this.setState({
        ownershipErrorVisible: false,
        selectedFile: file,
        error: error,
        imageData: null
      });
      var renderableFormats = ['jpg', 'jpeg', 'svg', 'png', 'bmp', 'gif'];
      var isRenderable = renderableFormats.indexOf(extension) !== -1;
      if (isRenderable && file.type && file.type.match('image.*')) {
        var reader = new FileReader();
        reader.onload = /*#__PURE__*/function () {
          var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(e) {
            var image;
            return _regeneratorRuntime().wrap(function _callee3$(_context3) {
              while (1) switch (_context3.prev = _context3.next) {
                case 0:
                  image = new Image();
                  image.onload = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
                    return _regeneratorRuntime().wrap(function _callee2$(_context2) {
                      while (1) switch (_context2.prev = _context2.next) {
                        case 0:
                          _context2.next = 2;
                          return _this.handleUpload(image);
                        case 2:
                          image = _context2.sent;
                          _this.setState({
                            imageData: image
                          });
                        case 4:
                        case "end":
                          return _context2.stop();
                      }
                    }, _callee2);
                  }));
                  image.src = e.target.result;
                case 3:
                case "end":
                  return _context3.stop();
              }
            }, _callee3);
          }));
          return function (_x2) {
            return _ref2.apply(this, arguments);
          };
        }();
        reader.readAsDataURL(file);
      }
    });
    _defineProperty(_assertThisInitialized(_this), "handleImageOwnershipChange", function (event, checked) {
      _this.setState({
        ownershipErrorVisible: false,
        ownershipChecked: checked
      });
    });
    _defineProperty(_assertThisInitialized(_this), "uploadFile", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
      var _this$state, ownershipChecked, selectedFile, checkOwnership, onUploadFinished;
      return _regeneratorRuntime().wrap(function _callee4$(_context4) {
        while (1) switch (_context4.prev = _context4.next) {
          case 0:
            _this$state = _this.state, ownershipChecked = _this$state.ownershipChecked, selectedFile = _this$state.selectedFile;
            checkOwnership = _this.props.checkOwnership;
            if (selectedFile) {
              _context4.next = 4;
              break;
            }
            return _context4.abrupt("return");
          case 4:
            if (!(checkOwnership && !ownershipChecked)) {
              _context4.next = 8;
              break;
            }
            _this.setState({
              ownershipErrorVisible: true
            });
            if (_this.ownershipGroup && _this.ownershipGroup.current && typeof _this.ownershipGroup.current.scrollIntoView === 'function') {
              _this.ownershipGroup.current.scrollIntoView();
            }
            return _context4.abrupt("return");
          case 8:
            // reset the error before the next upload
            _this.setState({
              error: null
            });
            _context4.prev = 9;
            _context4.next = 12;
            return _ServiceLocator.Services.designer.uploadFile(selectedFile);
          case 12:
            if (_this.dropZone.current && _this.dropZone.current && typeof _this.dropZone.current.scrollIntoView === 'function') {
              _this.dropZone.current.scrollIntoView();
            }
            onUploadFinished = _this.props.onUploadFinished;
            onUploadFinished && onUploadFinished();
            _context4.next = 21;
            break;
          case 17:
            _context4.prev = 17;
            _context4.t0 = _context4["catch"](9);
            // eslint-disable-next-line no-console
            console.error(_context4.t0);
            _this.setState({
              error: (0, _i18n.t)('fileUpload.processingFailed')
            });
          case 21:
          case "end":
            return _context4.stop();
        }
      }, _callee4, null, [[9, 17]]);
    })));
    _defineProperty(_assertThisInitialized(_this), "getAllowedImageFormats", function () {
      var formats = (0, _configuration.getConf)('designer.allowedImageUploadFormats').split(',');
      return formats ? formats.map(function (format) {
        return ".".concat(format);
      }) : 'image/*';
    });
    _this.state = {
      selectedFile: null,
      ownershipChecked: false,
      ownershipErrorVisible: false,
      error: null,
      imageData: null,
      uploadDelayed: false
    };
    _this.ownershipGroup = /*#__PURE__*/_react["default"].createRef();
    _this.dropZone = /*#__PURE__*/_react["default"].createRef();
    return _this;
  }
  _createClass(ImageEditDialog, [{
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
        classes = _this$props2.classes,
        width = _this$props2.width,
        checkOwnership = _this$props2.checkOwnership,
        imageIcon = _this$props2.imageIcon,
        checkIcon = _this$props2.checkIcon,
        errorIcon = _this$props2.errorIcon,
        loopIcon = _this$props2.loopIcon;
      var _this$state2 = this.state,
        ownershipChecked = _this$state2.ownershipChecked,
        ownershipErrorVisible = _this$state2.ownershipErrorVisible,
        selectedFile = _this$state2.selectedFile,
        error = _this$state2.error,
        imageData = _this$state2.imageData;
      return /*#__PURE__*/_react["default"].createElement(_reactFileDrop["default"], {
        onDrop: this.handleDrop,
        draggingOverTargetClassName: 'draggingOverDropZone',
        accept: "image/jpeg,image/jpg,image/tiff,image/gif",
        multiple: false
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: classes.imageUploadDropZone,
        ref: this.dropZone
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: classes.imageUploadContainer
      }, selectedFile === null && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, imageIcon !== null && imageIcon !== void 0 ? imageIcon : /*#__PURE__*/_react["default"].createElement(_Image["default"], {
        className: classes.imageUploadIcon
      }), /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        className: classes.imageUploadText,
        variant: "body2"
      }, (0, _i18n.t)((0, _withWidth.isWidthDown)('sm', width) ? 'fileUpload.uploadFiles' : 'fileUpload.dragDropFiles')), /*#__PURE__*/_react["default"].createElement(_MainButton["default"], {
        onClick: function onClick() {},
        variant: "contained",
        className: classes.imageUploadButton
      }, (0, _i18n.t)('fileUpload.chooseImage'), /*#__PURE__*/_react["default"].createElement("input", {
        type: "file",
        accept: this.getAllowedImageFormats(),
        onChange: this.handleInputChange
      }))), selectedFile !== null && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, imageData && /*#__PURE__*/_react["default"].createElement("img", {
        className: "".concat(classes.imagePreview, " ").concat(imageData.isBright ? classes.checkerBackground : ''),
        alt: selectedFile.name,
        src: imageData.src
      }), error === null ? /*#__PURE__*/_react["default"].createElement("div", {
        className: classes.uploadTextIconContainer
      }, checkIcon !== null && checkIcon !== void 0 ? checkIcon : /*#__PURE__*/_react["default"].createElement(_CheckCircle["default"], {
        className: "\n                                                ".concat(classes.imageUploadIcon, "\n                                                ").concat(classes.imageUploadIconSuccess, "\n                                            ")
      }), /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        variant: "body2",
        className: classes.imageUploadTextSuccess
      }, selectedFile.name)) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, errorIcon !== null && errorIcon !== void 0 ? errorIcon : /*#__PURE__*/_react["default"].createElement(_Error["default"], {
        className: classes.imageUploadIconError
      }), /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        variant: "body2",
        className: "\n                                                        ".concat(classes.imageUploadText, "\n                                                        ").concat(classes.imageUploadTextError, "\n                                             ")
      }, error)), /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        variant: "body2",
        className: classes.imageUploadText
      }, (0, _i18n.t)((0, _withWidth.isWidthDown)('sm', width) ? 'fileUpload.changeFiles' : 'fileUpload.dragDropFiles')), /*#__PURE__*/_react["default"].createElement(_Button["default"], {
        onClick: function onClick() {},
        variant: "text",
        className: "".concat(classes.imageUploadButton, " ").concat(classes.imageUploadChangeImageButton)
      }, loopIcon !== null && loopIcon !== void 0 ? loopIcon : /*#__PURE__*/_react["default"].createElement(_Loop["default"], null), " ", (0, _i18n.t)('fileUpload.changeImage'), /*#__PURE__*/_react["default"].createElement("input", {
        type: "file",
        accept: this.getAllowedImageFormats(),
        onChange: this.handleInputChange
      }))))), checkOwnership && /*#__PURE__*/_react["default"].createElement(_FormGroup["default"], {
        classes: {
          root: classes.imageUploadOwnership
        },
        ref: this.ownershipGroup
      }, /*#__PURE__*/_react["default"].createElement(_FormControlLabel["default"], {
        control: /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
          classes: {
            root: classes.imageUploadOwnershipCheckbox,
            checked: classes.colorChecked
          },
          checked: ownershipChecked,
          onChange: this.handleImageOwnershipChange,
          disabled: false
        }),
        label: /*#__PURE__*/_react["default"].createElement("span", {
          dangerouslySetInnerHTML: {
            __html: (0, _i18n.t)('fileUpload.confirmImageOwnership')
          }
        })
      }), ownershipErrorVisible && /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        variant: "body2",
        className: classes.ownershipError
      }, (0, _i18n.t)('fileUpload.imageOwnershipError'))));
    }
  }]);
  return ImageEditDialog;
}(_react["default"].Component);
_defineProperty(ImageEditDialog, "defaultProps", {
  checkOwnership: true
});
var _default = exports["default"] = (0, _withWidth["default"])({
  initialWidth: 'lg'
})((0, _styles.withStyles)(styles, {
  name: 'ImageEditDialog'
})(ImageEditDialog));