"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _find = _interopRequireDefault(require("lodash/find"));
var _values = _interopRequireDefault(require("lodash/values"));
var _get = _interopRequireDefault(require("lodash/get"));
var _uniqBy = _interopRequireDefault(require("lodash/uniqBy"));
var _size = _interopRequireDefault(require("lodash/size"));
var _styles = require("@material-ui/core/styles");
var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
var _TextField = _interopRequireDefault(require("@material-ui/core/TextField"));
var _Grid = _interopRequireDefault(require("@material-ui/core/Grid"));
var _Edit = _interopRequireDefault(require("@material-ui/icons/Edit"));
var _Delete = _interopRequireDefault(require("@material-ui/icons/Delete"));
var _Close = _interopRequireDefault(require("@material-ui/icons/Close"));
var _Dialog = _interopRequireDefault(require("@material-ui/core/Dialog"));
var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
var _FormatPaint = _interopRequireDefault(require("@material-ui/icons/FormatPaint"));
var _MenuItem = _interopRequireDefault(require("@material-ui/core/MenuItem"));
var _withWidth = _interopRequireWildcard(require("@material-ui/core/withWidth"));
var _i18n = require("../../../../../Framework/i18n");
var _Selectors = require("../../../../Reducers/DesignArea/Selectors");
var _AnalyticsWrapper = _interopRequireDefault(require("../../../../Shared/Components/Analytics/AnalyticsWrapper"));
var _MessageBox = _interopRequireDefault(require("../../../../Shared/Components/MessageBox"));
var _getContrastText = _interopRequireDefault(require("../../../../Utils/getContrastText"));
var _ColorPalettes = _interopRequireDefault(require("../ColorPalettes"));
var _Select = _interopRequireDefault(require("../Select"));
var _clsx = _interopRequireDefault(require("clsx"));
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
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) {
  return {
    infoText: {
      fontStyle: 'italic',
      fontSize: 12,
      color: '#666'
    },
    maxColorError: {
      color: '#f00'
    },
    colorsContainer: _defineProperty({
      paddingLeft: 16,
      maxHeight: 144,
      overflowY: 'auto',
      marginTop: 15
    }, theme.breakpoints.down('xs'), {
      width: 'calc(100% - 18px)',
      paddingLeft: 0,
      marginBottom: 0,
      margin: 'auto'
    }),
    slider: {
      padding: '24px 0px'
    },
    gridGrow: {
      maxWidth: 150,
      flex: '1 1 100%'
    },
    colorBox: {
      width: 32,
      height: 32,
      background: 'red',
      borderRadius: '50%',
      borderColor: '#212121',
      boxShadow: '0px 0px 2px'
    },
    editButton: {
      cursor: 'pointer',
      color: theme.palette.primary.darkText,
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'space-around'
    },
    deleteContainer: {
      minWidth: 32
    },
    deleteButton: {
      cursor: 'pointer'
    },
    editButtonDisabled: {
      cursor: 'default'
    },
    colorInput: {
      textAlign: 'center',
      color: theme.palette.primary.darkText,
      textTransform: 'capitalize',
      fontWeight: 'bold',
      textOverflow: 'ellipsis',
      overflow: 'hidden',
      fontSize: 15,
      cursor: 'pointer'
    },
    justifyGrid: _defineProperty({}, theme.breakpoints.down('xs'), {
      justifyContent: 'space-between'
    }),
    buttonContainer: _defineProperty({
      margin: '12px -12px',
      display: 'flex',
      justifyContent: 'space-between',
      '& > *': _defineProperty({
        margin: '0 12px',
        flexGrow: 1,
        flexBasis: 0,
        fontSize: '14px',
        textTransform: 'none',
        fontWeight: 'bold',
        minHeight: '60px',
        maxWidth: '50%',
        '& > div': {
          minHeight: '60px'
        }
      }, theme.breakpoints.down('xs'), {
        margin: 0
      })
    }, theme.breakpoints.down('xs'), {
      display: 'flex',
      margin: '24px 0px',
      '& > *:first-child': {
        maxWidth: '190px'
      },
      '& button': {
        marginLeft: 12
      }
    }),
    resetButtonText: {
      textTransform: 'none',
      fontWeight: 'bold'
    },
    vectorsNotRequired: {
      marginTop: 10,
      textTransform: 'none'
    },
    listItemText: _defineProperty({
      fontSize: '12px',
      lineHeight: '40px'
    }, theme.breakpoints.down('xs'), {
      lineHeight: '56px'
    })
  };
};
var ImageColorize = /*#__PURE__*/function (_React$Component) {
  _inherits(ImageColorize, _React$Component);
  var _super = _createSuper(ImageColorize);
  function ImageColorize() {
    var _this;
    _classCallCheck(this, ImageColorize);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _super.call.apply(_super, [this].concat(args));
    _defineProperty(_assertThisInitialized(_this), "state", {
      selectedColor: null,
      selectedColorPalette: null,
      vectorizeThreshold: 0,
      isThresholdSliderDisabled: false,
      designProductionMethodName: '',
      vectorizeRequested: false
    });
    _defineProperty(_assertThisInitialized(_this), "onVectorizeThresholdChange", function (event) {
      var onVectorizeThresholdChange = _this.props.onVectorizeThresholdChange;
      var thresholdValue = event.target.value;
      _this.setState({
        prevThreshold: thresholdValue,
        vectorizeThreshold: thresholdValue
      });
      onVectorizeThresholdChange && onVectorizeThresholdChange(thresholdValue);
    });
    _defineProperty(_assertThisInitialized(_this), "onColorSelectClick", function (value, identifier, paletteIdentifier, custom) {
      var onColorSelectClick = _this.props.onColorSelectClick;
      var colorKey = _this.state.selectedColor;
      _this.setState({
        selectedColor: null
      });
      var createdColor = (0, _Selectors.createColorData)(identifier, paletteIdentifier, custom, '#' + value);
      onColorSelectClick && onColorSelectClick(colorKey, createdColor);
    });
    _defineProperty(_assertThisInitialized(_this), "onColorPaletteClose", function () {
      _this.setState({
        selectedColor: null
      });
    });
    _defineProperty(_assertThisInitialized(_this), "onEditClick", function (colorKey) {
      _this.setState({
        selectedColor: colorKey
      });
    });
    _defineProperty(_assertThisInitialized(_this), "resetImageState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
      var onColorImageStateReset;
      return _regeneratorRuntime().wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            onColorImageStateReset = _this.props.onColorImageStateReset;
            _context.t0 = onColorImageStateReset;
            if (!_context.t0) {
              _context.next = 5;
              break;
            }
            _context.next = 5;
            return onColorImageStateReset();
          case 5:
          case "end":
            return _context.stop();
        }
      }, _callee);
    })));
    _defineProperty(_assertThisInitialized(_this), "getColorName", function (color) {
      var colorPalettes = _this.props.colorPalettes;
      var data = (0, _Selectors.parseColorData)(color.identifier);
      if (!(0, _Selectors.isValidHex)(color.value)) {
        return data.color + " (".concat((0, _i18n.t)('imageEditDialog.customColor'), ")");
      }
      var colorPalette = (0, _find["default"])(colorPalettes, {
        identifier: data.palette
      });
      if (!colorPalette) {
        return data.color.toUpperCase();
      }
      var paletteColor = (0, _find["default"])(colorPalette.colors, {
        identifier: data.color
      });
      if (!paletteColor) {
        return data.color.toUpperCase();
      }
      return paletteColor.title;
    });
    _defineProperty(_assertThisInitialized(_this), "getColorValue", function (color) {
      var value = color.value;
      return (0, _Selectors.isValidHex)(value) ? value : '#000000';
    });
    _defineProperty(_assertThisInitialized(_this), "onVectorizeToggleChange", function (e, value) {
      var onVectorizeToggleChange = _this.props.onVectorizeToggleChange;
      _this.setState({
        vectorizeRequested: value
      });
      onVectorizeToggleChange && onVectorizeToggleChange(value);
    });
    _defineProperty(_assertThisInitialized(_this), "validateAmount", function () {
      var _this$props = _this.props,
        maxColorAmount = _this$props.maxColorAmount,
        colorAmount = _this$props.colorAmount;
      return !maxColorAmount || colorAmount <= maxColorAmount;
    });
    _defineProperty(_assertThisInitialized(_this), "getSelectedColorPalette", function (color) {
      var colorPalettes = _this.props.colorPalettes;
      var selectedColorPalette = _this.state.selectedColorPalette;
      var colorData = (0, _Selectors.parseColorData)(color.identifier);
      var colorPalette = (0, _find["default"])(colorPalettes, {
        identifier: selectedColorPalette || colorData.palette
      });
      return colorPalette || colorPalettes[0];
    });
    _defineProperty(_assertThisInitialized(_this), "getColorAmountMessage", function () {
      var _this$props2 = _this.props,
        colorAmount = _this$props2.colorAmount,
        maxColorAmount = _this$props2.maxColorAmount;
      if (!maxColorAmount) {
        return (0, _i18n.t)('colorAmountIndicator.unlimitedColors');
      }
      if (colorAmount > maxColorAmount) {
        return (0, _i18n.t)('colorAmountIndicator.warning', {
          colorAmount: colorAmount,
          maxColorAmount: maxColorAmount
        });
      }
      return (0, _i18n.t)('colorAmountIndicator.ok', {
        colorAmount: colorAmount
      });
    });
    _defineProperty(_assertThisInitialized(_this), "getColors", function (vectorizeColorsMap, colorPalettes) {
      var usedColors = _this.props.usedColors;
      try {
        var imageColors = (0, _values["default"])(vectorizeColorsMap);
        var usedImageColors = [];
        imageColors.forEach(function (color) {
          var identifier = (0, _get["default"])(color, 'identifier');
          var parsedColor = JSON.parse(identifier);
          if (!parsedColor.custom) {
            var colorPalette = (0, _find["default"])(colorPalettes, {
              identifier: parsedColor.palette
            }) || {};
            var colors = (0, _find["default"])(colorPalette.colors, {
              identifier: parsedColor.color
            });
            usedImageColors.push(_objectSpread(_objectSpread({}, colors), {}, {
              value: color.value,
              palette: colorPalette.identifier
            }));
          }
        });
        return (0, _uniqBy["default"])([].concat(usedImageColors, usedColors), 'identifier');
      } catch (_unused) {
        // eslint-disable-next-line no-console
        console.error('failed to parse color data');
        return null;
      }
    });
    _defineProperty(_assertThisInitialized(_this), "onColorPaletteChange", function (identifier) {
      _this.setState({
        selectedColorPalette: identifier
      });
    });
    return _this;
  }
  _createClass(ImageColorize, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var vectorizeThreshold = this.props.vectorizeThreshold;
      this.setState({
        vectorizeThreshold: vectorizeThreshold
      });
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate(prevProps) {
      var _this$props3 = this.props,
        vectorizeThreshold = _this$props3.vectorizeThreshold,
        vectorizeColorsMap = _this$props3.vectorizeColorsMap;
      if (vectorizeThreshold !== prevProps.vectorizeThreshold || (0, _size["default"])(vectorizeColorsMap) !== (0, _size["default"])(prevProps.vectorizeColorsMap)) {
        this.setState({
          vectorizeThreshold: vectorizeThreshold
        });
      }
    }
  }, {
    key: "renderColorizeTools",
    value: function renderColorizeTools() {
      var _this2 = this;
      var _this$props4 = this.props,
        classes = _this$props4.classes,
        colorPalettes = _this$props4.colorPalettes,
        vectorizeColorsMap = _this$props4.vectorizeColorsMap,
        disableInputs = _this$props4.disableInputs,
        width = _this$props4.width,
        vectorize = _this$props4.vectorize,
        inputRef = _this$props4.inputRef,
        aggregatedColors = _this$props4.aggregatedColors,
        isLoading = _this$props4.isLoading,
        imageColorsWereEdited = _this$props4.imageColorsWereEdited,
        colorAmountList = _this$props4.colorAmountList,
        customControlElements = _this$props4.customControlElements;
      var _this$state = this.state,
        selectedColor = _this$state.selectedColor,
        vectorizeThreshold = _this$state.vectorizeThreshold,
        vectorizeRequested = _this$state.vectorizeRequested;
      var onColorRemoveClick = this.props.onColorRemoveClick;
      var thresholdValue = colorAmountList.indexOf(vectorizeThreshold) === -1 ? 0 : vectorizeThreshold;
      var amountIsValid = this.validateAmount();
      var aggregatedColorKeys = Object.keys(aggregatedColors);
      return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, customControlElements, /*#__PURE__*/_react["default"].createElement(_MessageBox["default"], {
        ref: inputRef,
        type: amountIsValid ? 'success' : 'error',
        text: this.getColorAmountMessage()
      }), /*#__PURE__*/_react["default"].createElement("div", {
        className: classes.buttonContainer
      }, /*#__PURE__*/_react["default"].createElement(_AnalyticsWrapper["default"], {
        targetId: "image_edit_colorize_found_colors"
      }, /*#__PURE__*/_react["default"].createElement(_Select["default"], {
        bold: true,
        value: thresholdValue,
        onChange: this.onVectorizeThresholdChange,
        readOnly: false,
        iconClass: '',
        disabled: disableInputs,
        error: !isLoading && !thresholdValue
      }, /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
        disabled: true,
        value: 0
      }, ' ', /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        className: classes.listItemText,
        noWrap: true
      }, (0, _i18n.t)('imageEditDialog.changeColorAmount'))), colorAmountList.map(function (colorAmount) {
        return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
          key: colorAmount,
          value: colorAmount
        }, ' ', /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
          className: classes.listItemText,
          noWrap: true
        }, colorAmount === 1 ? (0, _i18n.t)('imageEditDialog.imageColor', {
          amount: colorAmount
        }) : (0, _i18n.t)('imageEditDialog.imageColors', {
          amount: colorAmount
        })));
      }))), (imageColorsWereEdited || vectorizeRequested) && /*#__PURE__*/_react["default"].createElement(_Button["default"], {
        variant: "outlined",
        onClick: this.resetImageState,
        disabled: isLoading,
        startIcon: /*#__PURE__*/_react["default"].createElement(_Delete["default"], null)
      }, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        className: classes.resetButtonText
      }, (0, _i18n.t)('imageEditDialog.resetButton')))), vectorize && /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        container: true,
        spacing: 2,
        className: classes.colorsContainer
      }, aggregatedColorKeys.map(function (colorKey) {
        var background = _this2.getColorValue(vectorizeColorsMap[colorKey]);
        return /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
          item: true,
          key: colorKey,
          sm: 6,
          xs: 12
        }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
          container: true,
          spacing: 1,
          alignItems: "flex-end",
          wrap: "nowrap",
          className: classes.justifyGrid
        }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
          item: true
        }, /*#__PURE__*/_react["default"].createElement(_AnalyticsWrapper["default"], {
          targetId: "image_colorize",
          data: colorKey
        }, /*#__PURE__*/_react["default"].createElement("div", {
          className: (0, _clsx["default"])(classes.colorBox, classes.editButton, disableInputs && classes.editButtonDisabled),
          style: {
            background: background
          },
          onClick: function onClick() {
            return !disableInputs && _this2.onEditClick(colorKey);
          }
        }, /*#__PURE__*/_react["default"].createElement(_Edit["default"], {
          style: {
            color: (0, _getContrastText["default"])(background)
          }
        })))), /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
          item: true,
          className: classes.gridGrow
        }, /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
          disabled: true,
          fullWidth: true,
          onClick: function onClick() {
            return !disableInputs && _this2.onEditClick(colorKey);
          },
          value: _this2.getColorName(vectorizeColorsMap[colorKey]),
          translate: "no",
          InputProps: {
            disableUnderline: true
          },
          inputProps: {
            className: classes.colorInput
          }
        })), /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
          item: true,
          className: classes.deleteContainer
        }, aggregatedColorKeys.length > 1 && /*#__PURE__*/_react["default"].createElement(_Close["default"], {
          disabled: true,
          className: (0, _clsx["default"])(classes.deleteButton, disableInputs && classes.editButtonDisabled),
          onClick: function onClick() {
            return !disableInputs && onColorRemoveClick(colorKey);
          }
        }))));
      }, this)), colorPalettes && colorPalettes.length > 0 && selectedColor && /*#__PURE__*/_react["default"].createElement(_Dialog["default"], {
        open: selectedColor !== null,
        maxWidth: "xs",
        fullWidth: true,
        fullScreen: (0, _withWidth.isWidthDown)('xs', width),
        onClose: this.onColorPaletteClose
      }, /*#__PURE__*/_react["default"].createElement(_ColorPalettes["default"], {
        selectedColor: vectorizeColorsMap[selectedColor],
        colorSelectClick: this.onColorSelectClick,
        colorPalettes: colorPalettes,
        usedColors: this.getColors(vectorizeColorsMap, colorPalettes),
        palette: this.getSelectedColorPalette(vectorizeColorsMap[selectedColor]),
        closeColorPalettes: this.onColorPaletteClose,
        colorPaletteChange: this.onColorPaletteChange
      })));
    }
  }, {
    key: "render",
    value: function render() {
      var _this3 = this;
      var _this$props5 = this.props,
        classes = _this$props5.classes,
        vectorize = _this$props5.vectorize,
        designProductionMethodName = _this$props5.designProductionMethodName;
      return vectorize ? this.renderColorizeTools() : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        variant: "body1",
        component: "div"
      }, (0, _i18n.T)('imageEditDialog.imageWithoutVectorization', {
        designProductionMethodName: designProductionMethodName
      })), /*#__PURE__*/_react["default"].createElement(_Button["default"], {
        variant: "outlined",
        startIcon: /*#__PURE__*/_react["default"].createElement(_FormatPaint["default"], null),
        className: classes.vectorsNotRequired,
        onClick: function onClick(e) {
          return _this3.onVectorizeToggleChange(e, true);
        }
      }, (0, _i18n.t)('imageEditDialog.editColors')));
    }
  }]);
  return ImageColorize;
}(_react["default"].Component);
var _default = exports["default"] = (0, _styles.withStyles)(styles, {
  name: 'ImageColorize'
})((0, _withWidth["default"])({
  initialWidth: 'lg'
})(ImageColorize));