"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
var _exportNames = {
  getDesignProductionMethods: true,
  getDesignDataByDesignAreaIdentifier: true,
  getDesignDataColorAmounts: true,
  getUsedColorsForDesignAreas: true,
  getAvailableColorsForDesignProductionMethod: true,
  getDesignDataUsedColors: true,
  getPreviousEditedDesignAreaIdentifier: true,
  getDesignAreaIdentifierToOpen: true,
  getFirstEditedDesignAreafromDesignData: true,
  getDesignDataForFilteredDesignAreas: true,
  getDesignDataForSelectedDesignArea: true,
  getSelectedDesignProductionMethod: true,
  isActiveBulkName: true,
  isBulkNamesSelected: true,
  isCanvasUpdateRequired: true,
  hasSelectedBulkName: true,
  getSelectedDesignProductionMethodIdentifier: true,
  getSelectedDesignProductionMethodForDesignArea: true,
  getDesignProductionMethodByIdentifier: true,
  getSelectedDesignAreaProperties: true,
  getActiveDesignAreas: true,
  getSelectedDesignArea: true,
  isAnyDesignAreaSelected: true,
  isThereAFatalError: true,
  getSelectedViewName: true,
  hasPlaceHolderImagesForActiveDesignArea: true,
  isHighlighted: true,
  getMaxUploadSize: true,
  get2DMaxZoom: true,
  getCurrentCanvasSize: true,
  getCanvasSizeFromDesignProductionMethod: true,
  getCanvasSizeFromDesignArea: true,
  getFontSizeMin: true,
  getElementLockState: true,
  hasEngravingBackgroundColor: true,
  isColoringDisabled: true,
  getVisualizationEffect: true,
  designProductionMethodHasEmbroideryVisualizationEffect: true,
  designProductionMethodHasEngravingVisualizationEffect: true,
  getEngravingBackgroundColor: true,
  getColorOverlayData: true,
  getVisualizationEffectWithOptions: true,
  getColorPalettes: true,
  getColors: true,
  getColorsWithPalette: true,
  isValidHex: true,
  hexToRgb: true,
  hexToRgbNumbers: true,
  calculateColorDistance: true,
  rgbToHex: true,
  rgbString2hex: true,
  rgbObjToHex: true,
  getColorsFromCanvasData: true,
  getColorsFromCanvasDataWithPalette: true,
  findSmallestFontSizeInCanvasData: true,
  createColorData: true,
  parseColorData: true,
  getCameraViewListForDesignAreaList: true,
  getDesignViewListForDesignAreas: true,
  getDesignAreaFromSelectedDesignView: true,
  getDefaultDesignAreaIdentifierFromProductionMethod: true,
  getDefaultColorsFromDesignProductionMethod: true,
  getDefaultTextColor: true,
  isPlaceholderContent: true,
  contentHasText: true,
  getDesignAreaImageCompatibilityInfo: true,
  getCurrentCompatibilityInfoHash: true,
  areHashesCompatible: true,
  getVectorizedImageColor: true,
  areAllDesignAreasEmpty: true,
  hasLastEditedDesignArea: true,
  getDesignAreaPreSelection: true,
  getDesignAreaColorAmount: true,
  isVectorizedLogoMandatory: true,
  getVectorizeForDesignProductionMethods: true,
  getMandatoryVectorizationForDesignProductionMethods: true,
  getImagesByDesignArea: true,
  isOneLineText: true
};
exports.createColorData = exports.contentHasText = exports.calculateColorDistance = exports.areHashesCompatible = exports.areAllDesignAreasEmpty = void 0;
exports.designProductionMethodHasEmbroideryVisualizationEffect = designProductionMethodHasEmbroideryVisualizationEffect;
exports.designProductionMethodHasEngravingVisualizationEffect = designProductionMethodHasEngravingVisualizationEffect;
exports.findSmallestFontSizeInCanvasData = findSmallestFontSizeInCanvasData;
exports.get2DMaxZoom = get2DMaxZoom;
exports.getActiveDesignAreas = getActiveDesignAreas;
exports.getAvailableColorsForDesignProductionMethod = getAvailableColorsForDesignProductionMethod;
exports.getCameraViewListForDesignAreaList = void 0;
exports.getCanvasSizeFromDesignArea = getCanvasSizeFromDesignArea;
exports.getCanvasSizeFromDesignProductionMethod = getCanvasSizeFromDesignProductionMethod;
exports.getColorOverlayData = getColorOverlayData;
exports.getColorPalettes = void 0;
exports.getColors = getColors;
exports.getColorsFromCanvasData = getColorsFromCanvasData;
exports.getColorsFromCanvasDataWithPalette = getColorsFromCanvasDataWithPalette;
exports.getColorsWithPalette = getColorsWithPalette;
exports.getCurrentCanvasSize = getCurrentCanvasSize;
exports.getDesignAreaPreSelection = exports.getDesignAreaImageCompatibilityInfo = exports.getDesignAreaIdentifierToOpen = exports.getDesignAreaFromSelectedDesignView = exports.getDesignAreaColorAmount = exports.getDefaultTextColor = exports.getDefaultDesignAreaIdentifierFromProductionMethod = exports.getDefaultColorsFromDesignProductionMethod = exports.getCurrentCompatibilityInfoHash = void 0;
exports.getDesignDataByDesignAreaIdentifier = getDesignDataByDesignAreaIdentifier;
exports.getDesignDataColorAmounts = getDesignDataColorAmounts;
exports.getDesignDataForFilteredDesignAreas = getDesignDataForFilteredDesignAreas;
exports.getDesignDataForSelectedDesignArea = getDesignDataForSelectedDesignArea;
exports.getDesignDataUsedColors = getDesignDataUsedColors;
exports.getDesignProductionMethodByIdentifier = getDesignProductionMethodByIdentifier;
exports.getDesignProductionMethods = getDesignProductionMethods;
exports.getDesignViewListForDesignAreas = void 0;
exports.getElementLockState = getElementLockState;
exports.getEngravingBackgroundColor = getEngravingBackgroundColor;
exports.getFirstEditedDesignAreafromDesignData = getFirstEditedDesignAreafromDesignData;
exports.getFontSizeMin = getFontSizeMin;
exports.getMandatoryVectorizationForDesignProductionMethods = exports.getImagesByDesignArea = void 0;
exports.getMaxUploadSize = getMaxUploadSize;
exports.getPreviousEditedDesignAreaIdentifier = getPreviousEditedDesignAreaIdentifier;
exports.getSelectedDesignArea = getSelectedDesignArea;
exports.getSelectedDesignAreaProperties = getSelectedDesignAreaProperties;
exports.getSelectedDesignProductionMethod = getSelectedDesignProductionMethod;
exports.getSelectedDesignProductionMethodForDesignArea = getSelectedDesignProductionMethodForDesignArea;
exports.getSelectedDesignProductionMethodIdentifier = getSelectedDesignProductionMethodIdentifier;
exports.getSelectedViewName = getSelectedViewName;
exports.getUsedColorsForDesignAreas = getUsedColorsForDesignAreas;
exports.getVectorizedImageColor = exports.getVectorizeForDesignProductionMethods = void 0;
exports.getVisualizationEffect = getVisualizationEffect;
exports.getVisualizationEffectWithOptions = getVisualizationEffectWithOptions;
exports.hasEngravingBackgroundColor = hasEngravingBackgroundColor;
exports.hasPlaceHolderImagesForActiveDesignArea = exports.hasLastEditedDesignArea = void 0;
exports.hasSelectedBulkName = hasSelectedBulkName;
exports.hexToRgbNumbers = exports.hexToRgb = void 0;
exports.isActiveBulkName = isActiveBulkName;
exports.isAnyDesignAreaSelected = isAnyDesignAreaSelected;
exports.isBulkNamesSelected = isBulkNamesSelected;
exports.isCanvasUpdateRequired = isCanvasUpdateRequired;
exports.isColoringDisabled = isColoringDisabled;
exports.isHighlighted = isHighlighted;
exports.isOneLineText = isOneLineText;
exports.isPlaceholderContent = void 0;
exports.isThereAFatalError = isThereAFatalError;
exports.rgbToHex = exports.rgbString2hex = exports.rgbObjToHex = exports.parseColorData = exports.isVectorizedLogoMandatory = exports.isValidHex = void 0;
var _get = _interopRequireDefault(require("lodash/get"));
var _first = _interopRequireDefault(require("lodash/first"));
var _find2 = _interopRequireDefault(require("lodash/find"));
var _findKey = _interopRequireDefault(require("lodash/findKey"));
var _uniq = _interopRequireDefault(require("lodash/uniq"));
var _uniqWith = _interopRequireDefault(require("lodash/uniqWith"));
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
var _replace = _interopRequireDefault(require("lodash/replace"));
var _isObject = _interopRequireDefault(require("lodash/isObject"));
var _uniqBy = _interopRequireDefault(require("lodash/uniqBy"));
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
var _intersectionBy = _interopRequireDefault(require("lodash/intersectionBy"));
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
var _values = _interopRequireDefault(require("lodash/values"));
var _createSelector = _interopRequireDefault(require("../../../Utils/Function/createSelector"));
var _memoize = _interopRequireDefault(require("../../../Utils/Function/memoize"));
var _configuration = require("../../configuration");
var _DesignDataService = require("../../Services/DesignDataService");
var _Selectors = require("../Configurator/Selectors");
var _Transformers = require("../DesignView/Transformers");
var _Selectors2 = require("../ImageGallery/Selectors");
var _Transformers2 = require("./Transformers");
var _Actions = require("../UI/Actions");
var _MaskSelectors = require("./MaskSelectors");
Object.keys(_MaskSelectors).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _MaskSelectors[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function get() {
      return _MaskSelectors[key];
    }
  });
});
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
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 _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); }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function getDesignProductionMethods(state) {
  return (0, _get["default"])(state, 'designArea.selectedDesignArea.designProductionMethods');
}
function getDesignDataByDesignAreaIdentifier(_ref, designAreaIdentifier) {
  var configurator = _ref.configurator;
  var configuration = configurator.configuration;
  return (0, _get["default"])(configuration, "designdata.".concat(designAreaIdentifier), {});
}
function getDesignDataColorAmounts(_ref2) {
  var configurator = _ref2.configurator;
  var configuration = configurator.configuration;
  var designdata = (0, _get["default"])(configuration, 'designdata', {});
  var colorAmounts = {};
  for (var key in designdata) {
    if (!designdata.hasOwnProperty(key)) {
      continue;
    }
    colorAmounts[key] = designdata[key].colorAmount;
  }
  return colorAmounts;
}
function getUsedColorsForDesignAreas(state) {
  var designdata = (0, _get["default"])(state, 'configurator.configuration.designdata', {});
  var colors = [];
  for (var key in designdata) {
    if (!designdata.hasOwnProperty(key)) {
      continue;
    }
    if (!(0, _isEmpty["default"])(designdata[key].canvasData)) {
      var _iterator = _createForOfIteratorHelper(designdata[key].canvasData.objects),
        _step;
      try {
        for (_iterator.s(); !(_step = _iterator.n()).done;) {
          var object = _step.value;
          var objectColors = void 0;
          if (object.type === 'Image') {
            objectColors = (0, _values["default"])((0, _get["default"])(object, 'imageData.operations.vectorizeColorsMap')) || [];
          } else if (object.type === 'Text') {
            objectColors = object.style.colors;
          }
          var _iterator2 = _createForOfIteratorHelper(objectColors),
            _step2;
          try {
            for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
              var colorObj = _step2.value;
              var color = _objectSpread({}, colorObj);
              var colorData = color.identifier;
              try {
                colorData = JSON.parse(color.identifier);
              } catch (e) {
                // eslint-disable-next-line no-console
                console.error("failed to parse color data: ".concat(color.identifier));
              }
              if ((0, _isObject["default"])(colorData) && colorData.custom) {
                continue;
              }
              if ((0, _isObject["default"])(colorData)) {
                color.identifier = colorData.color;
                color.palette = colorData.palette;
              }
              var isColorValueHex = isValidHex(color.value);
              color.hex_value = (0, _replace["default"])(isColorValueHex ? color.value : rgbString2hex(color.value), '#', '');
              colors.push(color);
            }
          } catch (err) {
            _iterator2.e(err);
          } finally {
            _iterator2.f();
          }
        }
      } catch (err) {
        _iterator.e(err);
      } finally {
        _iterator.f();
      }
    }
  }
  return (0, _uniqBy["default"])(colors, 'identifier');
}
function getAvailableColorsForDesignProductionMethod(productionMethod) {
  var _ref4;
  if (!productionMethod || _typeof(productionMethod) !== 'object') {
    return [];
  }
  var colorPalettes = productionMethod.colorPalettes;
  var colorsArray = colorPalettes.map(function (_ref3) {
    var identifier = _ref3.identifier,
      colors = _ref3.colors;
    return colors.map(function (color) {
      return _objectSpread(_objectSpread({}, color), {}, {
        paletteIdentifier: identifier
      });
    });
  });
  return (_ref4 = []).concat.apply(_ref4, _toConsumableArray(colorsArray));
}
function getDesignDataUsedColors(state) {
  var usedColors = getUsedColorsForDesignAreas(state);
  var prodMethodColors = getAvailableColorsForDesignProductionMethod(getSelectedDesignProductionMethod(state));
  return (0, _intersectionBy["default"])(usedColors, prodMethodColors, 'identifier');
}
function getPreviousEditedDesignAreaIdentifier(state) {
  var previousEditedDesignArea = state.designArea.previousEditedDesignArea;
  return previousEditedDesignArea.identifier;
}
var getDesignAreaIdentifierToOpen = exports.getDesignAreaIdentifierToOpen = function getDesignAreaIdentifierToOpen(state) {
  var identifier = state.designArea.selectedDesignArea.identifier;
  var previousEditedDesignAreaIdentifier = getPreviousEditedDesignAreaIdentifier(state);
  var firstEditedDesignAreafromDesignData = getFirstEditedDesignAreafromDesignData(state);
  var designAreaFromSelectedDesignView = getDesignAreaFromSelectedDesignView(state);
  var defaultDesignAreaFromProductionMethod = getDefaultDesignAreaIdentifierFromProductionMethod(state);
  return identifier || previousEditedDesignAreaIdentifier || firstEditedDesignAreafromDesignData || designAreaFromSelectedDesignView || defaultDesignAreaFromProductionMethod || null;
};
function getFirstEditedDesignAreafromDesignData(state) {
  var designdata = state.configurator.configuration.designdata;
  var editedDesignAreaIdentifier = (0, _findKey["default"])(designdata, function (_ref5) {
    var canvasData = _ref5.canvasData;
    return canvasData && canvasData.objects.length > 0;
  });
  return editedDesignAreaIdentifier;
}
function getDesignDataForFilteredDesignAreas(state) {
  var filteredDesignAreas = state.designArea.filteredDesignAreas;
  var hasDesign = {};
  filteredDesignAreas.forEach(function (designArea) {
    hasDesign[designArea.identifier] = (0, _get["default"])(getDesignDataByDesignAreaIdentifier(state, designArea.identifier), 'canvasData.objects.length', 0) > 0;
  });
  return hasDesign;
}
function getDesignDataForSelectedDesignArea(state) {
  var selectedDesignArea = (0, _get["default"])(state, 'designArea.selectedDesignArea');
  if (!selectedDesignArea) {
    return {};
  }
  return getDesignDataByDesignAreaIdentifier(state, selectedDesignArea.identifier);
}
function getSelectedDesignProductionMethod(state) {
  var designProductionMethods = getDesignProductionMethods(state);
  var designAreaData = getDesignDataForSelectedDesignArea(state);
  var designProductionMethodIdentifier = designAreaData.designProductionMethodIdentifier;
  return (0, _find2["default"])(designProductionMethods, {
    identifier: designProductionMethodIdentifier
  }) || (0, _first["default"])(designProductionMethods);
}
function isActiveBulkName(state) {
  var designArea = state.designArea;
  var designedAreas = (0, _get["default"])(designArea, 'filteredDesignAreas', []);
  var _iterator3 = _createForOfIteratorHelper(designedAreas),
    _step3;
  try {
    for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
      var da = _step3.value;
      if (da.designProductionMethods && da.designProductionMethods.length > 0) {
        var _iterator4 = _createForOfIteratorHelper(da.designProductionMethods),
          _step4;
        try {
          for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
            var designProductionMethod = _step4.value;
            if (designProductionMethod.allowBulkNames) {
              return true;
            }
          }
        } catch (err) {
          _iterator4.e(err);
        } finally {
          _iterator4.f();
        }
      }
    }
  } catch (err) {
    _iterator3.e(err);
  } finally {
    _iterator3.f();
  }
  return false;
}
function isBulkNamesSelected(configuratorState) {
  var configuration = configuratorState.configuration;
  var designData = (0, _get["default"])(configuration, 'designdata', {}) || {};
  for (var _i = 0, _Object$values = Object.values(designData); _i < _Object$values.length; _i++) {
    var dd = _Object$values[_i];
    if (dd.canvasData && dd.canvasData.objects.length > 0) {
      var _iterator5 = _createForOfIteratorHelper(dd.canvasData.objects),
        _step5;
      try {
        for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
          var object = _step5.value;
          if (object.isBulkName) {
            return true;
          }
        }
      } catch (err) {
        _iterator5.e(err);
      } finally {
        _iterator5.f();
      }
    }
  }
  return false;
}
function isCanvasUpdateRequired(_ref6, _ref7) {
  var position = _ref6.position;
  var width = _ref7.width,
    height = _ref7.height;
  return position.width !== width || position.height !== height;
}
function hasSelectedBulkName(designArea) {
  var canvasDataObjs = (0, _get["default"])(designArea, 'canvasData.objects', []);
  return canvasDataObjs.filter(function (obj) {
    return obj.type === 'Text' && obj.isBulkName;
  }).length > 0;
}
function getSelectedDesignProductionMethodIdentifier(state) {
  var configuration = state.configurator.configuration,
    selectedDesignArea = state.designArea.selectedDesignArea;
  return (0, _get["default"])(configuration, "designdata.".concat(selectedDesignArea.identifier, ".designProductionMethodIdentifier"));
}
function getSelectedDesignProductionMethodForDesignArea(state, designArea) {
  var designProductionMethods = designArea.designProductionMethods;
  var designAreaData = getDesignDataByDesignAreaIdentifier(state, designArea.identifier);
  var _ref8 = designAreaData || {},
    designProductionMethodIdentifier = _ref8.designProductionMethodIdentifier;
  return (0, _find2["default"])(designProductionMethods, {
    identifier: designProductionMethodIdentifier
  }) || (0, _find2["default"])(designProductionMethods, {
    isDefault: true
  }) || (0, _first["default"])(designProductionMethods);
}
function getDesignProductionMethodByIdentifier(state, identifier) {
  var designProductionMethods = getDesignProductionMethods(state);
  return (0, _find2["default"])(designProductionMethods, {
    identifier: identifier
  });
}
function getSelectedDesignAreaProperties(state) {
  var designArea = state.designArea;
  var filteredDesignAreas = designArea.filteredDesignAreas,
    selectedDesignArea = designArea.selectedDesignArea;
  if (!filteredDesignAreas || !selectedDesignArea) {
    return {};
  }
  if (!selectedDesignArea) {
    return {};
  }
  var designAreaData = getDesignDataForSelectedDesignArea(state);
  var colorAmount = designAreaData.colorAmount;
  var designProductionMethod = getSelectedDesignProductionMethod(state);
  var maxColorAmount = (0, _get["default"])(designProductionMethod, 'options.maxColorAmount', 0);
  var hasEngravingBackgroundColors = designProductionMethodHasEngravingVisualizationEffect(designProductionMethod);
  return {
    filteredDesignAreas: filteredDesignAreas,
    colorAmount: colorAmount,
    maxColorAmount: maxColorAmount,
    hasEngravingBackgroundColors: hasEngravingBackgroundColors,
    designProductionMethod: designProductionMethod,
    selectedDesignArea: selectedDesignArea
  };
}
function getActiveDesignAreas(state) {
  var filteredDesignAreas = state.designArea.filteredDesignAreas;
  return filteredDesignAreas.reduce(function (obj, designArea) {
    var designData = getDesignDataByDesignAreaIdentifier(state, designArea.identifier);
    return _objectSpread(_objectSpread({}, obj), {}, _defineProperty({}, designArea.identifier, (0, _get["default"])(designData, 'canvasData.objects.length', 0) > 0));
  }, {});
}
function getSelectedDesignArea(state) {
  return (0, _get["default"])(state, 'designArea.selectedDesignArea');
}
function isAnyDesignAreaSelected(state) {
  return Object.keys(getSelectedDesignArea(state)).length > 0;
}
function isIt500Error(_ref9) {
  var error = _ref9.ui.error;
  return error && error.response && error.response.status === 500;
}
function isConfigurationNotFound(_ref0) {
  var error = _ref0.ui.error;
  return error && error.source && error.response && error.response.status === 404 && ['loadbyitemidentifier', 'getconfigurationvariants'].indexOf((error.source.url || error.source).split('/')[1]) !== -1 || error && error.type === _Actions.CONFIGURATION_NOT_FOUND_ERROR;
}
function isThereAFatalError(state) {
  return isIt500Error(state) || isConfigurationNotFound(state);
}
function getSelectedViewName(designArea) {
  return (0, _get["default"])(designArea, 'customData.selectedCameraView') ||
  // used by the 3D camera positions
  (0, _get["default"])(designArea, 'designView.identifier') ||
  // used by the 2D design view associations
  (0, _get["default"])(designArea, 'identifier') ||
  // fallback to the design area identifier (currently no known use case)
  'default' // if no design area selected use the default view
  ;
}

var hasPlaceHolderImagesForActiveDesignArea = exports.hasPlaceHolderImagesForActiveDesignArea = function hasPlaceHolderImagesForActiveDesignArea(state) {
  var designData = getDesignDataForSelectedDesignArea(state);
  var canvasObjects = (0, _get["default"])(designData, 'canvasData.objects') || null;
  return canvasObjects && !!canvasObjects.find(function (object) {
    return object.type === 'Image' && object.imageData.isPlaceHolderImage;
  });
};
function isHighlighted(state) {
  return (0, _get["default"])(state, 'designArea.showHighlight') || false;
}
function getMaxUploadSize(state) {
  return (0, _get["default"])(state, 'designArea.uploadMaxSize') || 20000000;
}
function get2DMaxZoom(state) {
  return (0, _get["default"])(state, 'designArea.maxZoom2d') || 2.0;
}
var zeroSize = {
  width: 0,
  height: 0
};

/**
 * Returns the canvas size in mm-s
 * @param state
 * @param defaultSize
 * @returns {*}
 */
function getCurrentCanvasSize(state) {
  var defaultSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : zeroSize;
  var _getSelectedDesignAre = getSelectedDesignAreaProperties(state),
    designProductionMethod = _getSelectedDesignAre.designProductionMethod;
  if (!designProductionMethod) {
    return defaultSize;
  }
  return getCanvasSizeFromDesignProductionMethod(designProductionMethod);
}
var memoizedCanvasSize = (0, _memoize["default"])(function (width, height, isMetric, dpi) {
  return {
    width: width,
    height: height,
    isMetric: isMetric,
    dpi: dpi
  };
});
function getCanvasSizeFromDesignProductionMethod(designProductionMethod) {
  var defaultSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : zeroSize;
  var width = designProductionMethod.width,
    height = designProductionMethod.height,
    dpi = designProductionMethod.dpi;
  if (!width || !height) {
    return defaultSize;
  }
  return memoizedCanvasSize(width, height, true, dpi || (0, _configuration.getConf)('designer.dpi', 300));
}
function getCanvasSizeFromDesignArea(state, designArea) {
  var defaultSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : zeroSize;
  var designProductionMethod = getSelectedDesignProductionMethodForDesignArea(state, designArea);
  return designProductionMethod ? getCanvasSizeFromDesignProductionMethod(designProductionMethod) : defaultSize;
}
function getFontSizeMin(state) {
  var designProductionMethodIdentifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  var designProductionMethod = designProductionMethodIdentifier ? getDesignProductionMethodByIdentifier(state, designProductionMethodIdentifier) : getSelectedDesignProductionMethod(state);
  return Number((0, _get["default"])(designProductionMethod, 'options.minFontSize')) || 5;
}
function getElementLockState(state) {
  var designProductionMethodIdentifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  var designProductionMethod = designProductionMethodIdentifier ? getDesignProductionMethodByIdentifier(state, designProductionMethodIdentifier) : getSelectedDesignProductionMethod(state);
  return (0, _get["default"])(designProductionMethod, 'designElementsLocked');
}
function hasEngravingBackgroundColor(state) {
  var designProductionMethodIdentifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  var designProductionMethod = designProductionMethodIdentifier ? getDesignProductionMethodByIdentifier(state, designProductionMethodIdentifier) : getSelectedDesignProductionMethod(state);
  return designProductionMethodHasEngravingVisualizationEffect(designProductionMethod);
}
function isColoringDisabled(state) {
  var designProductionMethodIdentifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  var designProductionMethod = designProductionMethodIdentifier ? getDesignProductionMethodByIdentifier(state, designProductionMethodIdentifier) : getSelectedDesignProductionMethod(state);
  var visualizationEffect = (0, _get["default"])(designProductionMethod, 'options.visualizationEffect', 'print');
  return ['engraving', 'embossing'].indexOf(visualizationEffect) !== -1;
}
function getVisualizationEffect(designProductionMethod) {
  return (0, _get["default"])(designProductionMethod, 'options.visualizationEffect', 'print');
}
function designProductionMethodHasEmbroideryVisualizationEffect(designProductionMethod) {
  return 'embroidery' === getVisualizationEffect(designProductionMethod);
}
function designProductionMethodHasEngravingVisualizationEffect(designProductionMethod) {
  return 'engraving' === getVisualizationEffect(designProductionMethod);
}
function getEngravingBackgroundColor(state, designProductionMethod) {
  var variantIdentifier = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  var _designProductionMethod = designProductionMethod || getSelectedDesignProductionMethod(state) || {};
  var engravingBackgroundColors = _designProductionMethod.engravingBackgroundColors;
  return (0, _get["default"])((0, _find2["default"])(engravingBackgroundColors, {
    itemIdentifier: variantIdentifier || (0, _Selectors.getSelectedVariantIdentifier)((0, _Selectors.getConfigurator)(state))
  }), 'colorHex', 'rgba(0, 0, 0, 0.5)');
}
function getColorOverlayData(state, designArea) {
  var variantIdentifier = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  var designProductionMethod = getSelectedDesignProductionMethodForDesignArea(state, designArea);
  if (!designProductionMethodHasEngravingVisualizationEffect(designProductionMethod)) {
    return null;
  }
  return {
    color: getEngravingBackgroundColor(state, designArea, variantIdentifier)
  };
}
function getVisualizationEffectWithOptions(state, designArea) {
  var variantIdentifier = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  var designProductionMethod = getSelectedDesignProductionMethodForDesignArea(state, designArea);
  var effect = getVisualizationEffect(designProductionMethod);
  var effectOptions = _objectSpread({}, designProductionMethodHasEngravingVisualizationEffect(designProductionMethod) && {
    fillColor: getEngravingBackgroundColor(state, designProductionMethod, variantIdentifier)
  });
  return {
    effect: effect,
    effectOptions: effectOptions
  };
}
var getColorPalettes = exports.getColorPalettes = (0, _createSelector["default"])(function (state) {
  var _getSelectedDesignAre2 = getSelectedDesignAreaProperties(state),
    designProductionMethod = _getSelectedDesignAre2.designProductionMethod;
  return designProductionMethod;
}, function (designProductionMethod) {
  return designProductionMethod ? designProductionMethod.colorPalettes : [];
});
function getColors(state) {
  return getColorsFromCanvasData(getDesignDataForSelectedDesignArea(state).canvasData);
}
function getColorsWithPalette(state) {
  return getColorsFromCanvasDataWithPalette(getDesignDataForSelectedDesignArea(state).canvasData);
}
var isValidHex = exports.isValidHex = function isValidHex(hex) {
  return /^#([0-9A-F]{3}){1,2}$/i.test(hex);
};
var hexToRgb = exports.hexToRgb = function hexToRgb(hex) {
  var stringify = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
  hex = hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, function (m, r, g, b) {
    return r + r + g + g + b + b;
  });
  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  if (!result) {
    return null;
  }
  var _map = [1, 2, 3].map(function (i) {
      return parseInt(result[i], 16);
    }),
    _map2 = _slicedToArray(_map, 3),
    r = _map2[0],
    g = _map2[1],
    b = _map2[2];
  if (!stringify) {
    return {
      r: r,
      g: g,
      b: b
    };
  }
  return "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")");
};
var hexToRgbNumbers = exports.hexToRgbNumbers = function hexToRgbNumbers(hex) {
  var rgbAsString = hexToRgb(hex);
  return rgbAsString && rgbAsString.slice(4, rgbAsString.length - 1).split(',').map(function (numString) {
    return parseInt(numString);
  });
};
var calculateColorDistance = exports.calculateColorDistance = function calculateColorDistance(firstColor, secondColor) {
  var firstRgb = hexToRgbNumbers(firstColor);
  var secondRgb = hexToRgbNumbers(secondColor);
  if (!firstRgb || !secondRgb) {
    return null;
  }
  return firstRgb.map(function (color, index) {
    return Math.pow(color - secondRgb[index], 2);
  }).reduce(function (accumulator, value) {
    return accumulator + value;
  });
};
var rgbToHex = exports.rgbToHex = function rgbToHex(r, g, b) {
  if (r > 255 || g > 255 || b > 255) {
    throw new Error('Invalid color component');
  }
  var value = (r << 16 | g << 8 | b).toString(16);
  return '#' + ('000000' + value).slice(-6);
};
var rgbString2hex = exports.rgbString2hex = function rgbString2hex(rgb) {
  rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
  return rgb && rgb.length === 4 ? '#' + ('0' + parseInt(rgb[1], 10).toString(16)).slice(-2) + ('0' + parseInt(rgb[2], 10).toString(16)).slice(-2) + ('0' + parseInt(rgb[3], 10).toString(16)).slice(-2) : '';
};
var rgbObjToHex = exports.rgbObjToHex = function rgbObjToHex(_ref1) {
  var r = _ref1.r,
    g = _ref1.g,
    b = _ref1.b;
  return rgbToHex(r, g, b);
};
function getColorsFromCanvasData(canvasData) {
  var objects = (0, _get["default"])(canvasData, 'objects', []);
  var colors = [];
  var _iterator6 = _createForOfIteratorHelper(objects),
    _step6;
  try {
    for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
      var object = _step6.value;
      if (object.type === 'Text') {
        var objectColors = (0, _get["default"])(object, 'style.colors') || [];
        var _iterator7 = _createForOfIteratorHelper(objectColors),
          _step7;
        try {
          for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
            var color = _step7.value;
            colors.push(color.value);
          }
        } catch (err) {
          _iterator7.e(err);
        } finally {
          _iterator7.f();
        }
      } else if (object.type === 'Image') {
        var _objectColors = Object.values((0, _get["default"])(object, 'imageData.operations.vectorizeColorsMap') || {});
        for (var _i2 = 0, _objectColors2 = _objectColors; _i2 < _objectColors2.length; _i2++) {
          var _color = _objectColors2[_i2];
          colors.push(_color.value.startsWith('#') ? hexToRgb(_color.value) : _color.value);
        }
      }
    }
  } catch (err) {
    _iterator6.e(err);
  } finally {
    _iterator6.f();
  }
  return (0, _uniq["default"])(colors);
}
function getColorsFromCanvasDataWithPalette(canvasData) {
  var objects = (0, _get["default"])(canvasData, 'objects', []);
  var colors = [];
  var _iterator8 = _createForOfIteratorHelper(objects),
    _step8;
  try {
    for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
      var object = _step8.value;
      if (object.type === 'Text') {
        var objectColors = (0, _get["default"])(object, 'style.colors') || [];
        var _iterator9 = _createForOfIteratorHelper(objectColors),
          _step9;
        try {
          for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
            var color = _step9.value;
            colors.push(color);
          }
        } catch (err) {
          _iterator9.e(err);
        } finally {
          _iterator9.f();
        }
      } else if (object.type === 'Image') {
        var _objectColors3 = (0, _cloneDeep["default"])(Object.values((0, _get["default"])(object, 'imageData.operations.vectorizeColorsMap') || {}));
        var _iterator0 = _createForOfIteratorHelper(_objectColors3),
          _step0;
        try {
          for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
            var _color2 = _step0.value;
            if (_color2.value.startsWith('#')) {
              _color2.value = hexToRgb(_color2.value);
            }
            colors.push(_color2);
          }
        } catch (err) {
          _iterator0.e(err);
        } finally {
          _iterator0.f();
        }
      }
    }
  } catch (err) {
    _iterator8.e(err);
  } finally {
    _iterator8.f();
  }
  return (0, _uniqWith["default"])(colors, function (color1, color2) {
    return color1.identifier === color2.identifier && color1.value === color2.value;
  });
}
function findSmallestFontSizeInCanvasData(canvasData) {
  var objects = (0, _get["default"])(canvasData, 'objects', []);
  return Math.min.apply(0, objects.map(function (object) {
    return object.fontSize || Infinity;
  }));
}
var createColorData = exports.createColorData = function createColorData(identifier, paletteIdentifier, custom, value) {
  var data = {
    color: identifier,
    palette: paletteIdentifier
  };
  if (custom) {
    data.custom = true;
  }
  return {
    identifier: JSON.stringify(data),
    value: value.toLowerCase()
  };
};
var parseColorData = exports.parseColorData = function parseColorData(jsonStr) {
  var colorData;
  try {
    colorData = JSON.parse(jsonStr);
  } catch (e) {
    // eslint-disable-next-line no-console
    console.error("failed to parse color data: ".concat(jsonStr));
  }
  return _objectSpread({
    palette: null,
    color: null
  }, colorData);
};
var getCameraViewListForDesignAreaList = exports.getCameraViewListForDesignAreaList = function getCameraViewListForDesignAreaList(filteredDesignAreas, designedAreas) {
  return ['default'].concat(filteredDesignAreas
  // get the design area objects by their id
  .filter(function (designArea) {
    return designedAreas.indexOf(designArea.identifier) !== -1;
  })
  // get the camera view values
  .map(function (designArea) {
    return (0, _get["default"])(designArea, 'customData.selectedCameraView');
  })
  // remove empty values and duplicates
  .filter(function (viewName, index, arr) {
    return viewName && index === arr.indexOf(viewName);
  })
  // make them lower case
  .map(function (viewName) {
    return viewName.toLowerCase();
  }));
};
var getDesignViewListForDesignAreas = exports.getDesignViewListForDesignAreas = function getDesignViewListForDesignAreas(state, designAreas) {
  var designViews = state.designView.designViews,
    designerAvailable = state.configurationMode.availableModes.designer;
  if (!designerAvailable) {
    return designViews;
  }
  var designViewList = [];
  var _iterator1 = _createForOfIteratorHelper(designViews),
    _step1;
  try {
    for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
      var designView = _step1.value;
      var designAreaList = [];
      var _iterator10 = _createForOfIteratorHelper(designView.designAreas),
        _step10;
      try {
        for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
          var designArea = _step10.value;
          if (!designAreas || designAreas.indexOf(designArea.identifier) !== -1) {
            designAreaList.push((0, _Transformers2.recalculateSingleDesignArea)(state, designArea));
          }
        }
      } catch (err) {
        _iterator10.e(err);
      } finally {
        _iterator10.f();
      }
      if (designAreaList.length) {
        designViewList.push(_objectSpread(_objectSpread({}, designView), {}, {
          designAreas: designAreaList.sort(_Transformers.compareDesignAreasBySize)
        }));
      }
    }
  } catch (err) {
    _iterator1.e(err);
  } finally {
    _iterator1.f();
  }
  return designViewList;
};
var getDesignAreaFromSelectedDesignView = exports.getDesignAreaFromSelectedDesignView = function getDesignAreaFromSelectedDesignView(state) {
  var _find;
  var filteredDesignAreas = state.designArea.filteredDesignAreas,
    selectedDesignView = state.designView.selectedDesignView;
  return (_find = (0, _find2["default"])(filteredDesignAreas, ['designView.identifier', selectedDesignView.identifier])) === null || _find === void 0 ? void 0 : _find.identifier;
};
var getDefaultDesignAreaIdentifierFromProductionMethod = exports.getDefaultDesignAreaIdentifierFromProductionMethod = function getDefaultDesignAreaIdentifierFromProductionMethod(state) {
  //return the first designArea with isDefault: true due to api call accepts multiple productionmethods to be default
  var filteredDesignAreas = state.designArea.filteredDesignAreas;
  var defaultDesignArea = filteredDesignAreas && filteredDesignAreas.find(function (designArea) {
    return !!designArea.designProductionMethods.find(function (method) {
      return method.isDefault;
    });
  });
  if (defaultDesignArea) {
    return defaultDesignArea.identifier;
  } else {
    return null;
  }
};
var getDefaultColorsFromDesignProductionMethod = exports.getDefaultColorsFromDesignProductionMethod = function getDefaultColorsFromDesignProductionMethod(designProductionMethod) {
  return (0, _get["default"])(designProductionMethod, 'defaultColors') || {};
};
var getDefaultTextColor = exports.getDefaultTextColor = function getDefaultTextColor(state) {
  var colorIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  var colorPalettes = getColorPalettes(state);
  var defaultColor = {
    identifier: 'ff0000',
    paletteIdentifier: null,
    custom: true,
    value: '#ff0000'
  };
  if (!colorPalettes.length) {
    return defaultColor;
  }
  if (colorIndex !== null) {
    if (colorPalettes[0].colors.length <= colorIndex) {
      return defaultColor;
    }
    return {
      identifier: colorPalettes[0].colors[colorIndex].identifier,
      paletteIdentifier: colorPalettes[0].identifier,
      custom: false,
      value: '#' + colorPalettes[0].colors[colorIndex].hex_value
    };
  }
  var designProductionMethod = getSelectedDesignProductionMethod(state);
  var defaultColors = getDefaultColorsFromDesignProductionMethod(designProductionMethod);
  var variantIdentifier = (0, _Selectors.getSelectedVariantIdentifier)((0, _Selectors.getConfigurator)(state));
  if (defaultColors && defaultColors[variantIdentifier]) {
    var colorPalette = (0, _find2["default"])(colorPalettes, {
      identifier: Object.keys(defaultColors[variantIdentifier])[0]
    });
    if (colorPalette) {
      var color = (0, _find2["default"])(colorPalette.colors, {
        identifier: defaultColors[variantIdentifier][colorPalette.identifier]
      });
      if (color) {
        return {
          identifier: color.identifier,
          paletteIdentifier: colorPalette.identifier,
          custom: false,
          value: '#' + color.hex_value
        };
      }
    }
  }
  var paletteDefaultColorIdentifier = (0, _get["default"])(colorPalettes[0], 'defaultColor.identifier', '');
  var paletteDefaultColor = (0, _find2["default"])(colorPalettes[0].colors, {
    identifier: paletteDefaultColorIdentifier
  });
  if (paletteDefaultColor) {
    return {
      identifier: paletteDefaultColor.identifier,
      paletteIdentifier: colorPalettes[0].identifier,
      custom: false,
      value: '#' + paletteDefaultColor.hex_value
    };
  }
  if (colorPalettes[0].colors.length) {
    return {
      identifier: colorPalettes[0].colors[0].identifier,
      paletteIdentifier: colorPalettes[0].identifier,
      custom: false,
      value: '#' + colorPalettes[0].colors[0].hex_value
    };
  }
  return defaultColor;
};
var isPlaceholderContent = exports.isPlaceholderContent = function isPlaceholderContent(content) {
  return content.indexOf('data-placeholder="true"') !== -1;
};
var contentHasText = exports.contentHasText = function contentHasText(content) {
  var div = document.createElement('div');
  div.innerHTML = content;
  return /\S/.test(div.textContent);
};
var getDesignAreaImageCompatibilityInfo = exports.getDesignAreaImageCompatibilityInfo = function getDesignAreaImageCompatibilityInfo(designProductionMethod) {
  var colorPalettes = ((0, _get["default"])(designProductionMethod, 'colorPalettes') || []).map(function (_ref10) {
    var identifier = _ref10.identifier;
    return identifier;
  }).sort();
  var vectorsRequired = !!(0, _get["default"])(designProductionMethod, 'options.vectorsRequired');
  var maxColorAmount = (0, _get["default"])(designProductionMethod, 'options.maxColorAmount', 0);
  var vectorizedLogoMandatory = (0, _get["default"])(designProductionMethod, 'options.vectorizedLogoMandatory', false);
  return {
    colorPalettes: colorPalettes,
    vectorsRequired: vectorsRequired,
    maxColorAmount: maxColorAmount,
    vectorizedLogoMandatory: vectorizedLogoMandatory
  };
};
var getCurrentCompatibilityInfoHash = exports.getCurrentCompatibilityInfoHash = function getCurrentCompatibilityInfoHash(state) {
  return getDesignAreaImageCompatibilityInfo(getSelectedDesignProductionMethod(state));
};
var areHashesCompatible = exports.areHashesCompatible = function areHashesCompatible(storedHash, targetHash) {
  return Boolean(!targetHash || storedHash && (0, _isEqual["default"])(storedHash.colorPalettes, targetHash.colorPalettes) && (!targetHash.vectorsRequired || storedHash.vectorsRequired) && (!targetHash.vectorizedLogoMandatory || storedHash.vectorizedLogoMandatory) && (!targetHash.maxColorAmount || storedHash.maxColorAmount <= targetHash.maxColorAmount));
};
var getVectorizedImageColor = exports.getVectorizedImageColor = function getVectorizedImageColor(state) {
  var selectedDesignProductionMethod = getSelectedDesignProductionMethod(state);
  var selectedImage = (0, _get["default"])(state, 'imageGallery.selectedImage', {});
  var reversedUserImages = (0, _get["default"])(state, 'imageGallery.userImages', []).slice().reverse();
  if (selectedImage && reversedUserImages.length > 0 && reversedUserImages.find(function (image) {
    return image.originalFileName === selectedImage.originalFileName;
  }) && selectedImage.originalFileName !== reversedUserImages[0].originalFileName) {
    var currentLastImage = reversedUserImages.find(function (image) {
      return image.originalFileName === selectedImage.originalFileName;
    });
    var imagesWithoutSelectedImage = reversedUserImages.filter(function (image) {
      return image !== currentLastImage;
    });
    reversedUserImages = [currentLastImage].concat(_toConsumableArray(imagesWithoutSelectedImage));
  }
  var _iterator11 = _createForOfIteratorHelper(reversedUserImages),
    _step11;
  try {
    for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
      var image = _step11.value;
      var objectColors = (0, _values["default"])((0, _get["default"])(image, 'operations.vectorizeColorsMap'));
      if (!objectColors || !objectColors.length) {
        continue;
      }
      if ((0, _Selectors2.isImageCompatible)(state, image)) {
        return (0, _first["default"])(objectColors);
      } else {
        var replacedColor = (0, _first["default"])((0, _DesignDataService.getMissingColorPalettesColors)((0, _first["default"])(objectColors) ? [(0, _first["default"])(objectColors)] : [], selectedDesignProductionMethod ? selectedDesignProductionMethod.colorPalettes : []));
        return (0, _get["default"])(replacedColor, 'closestColor');
      }
    }
  } catch (err) {
    _iterator11.e(err);
  } finally {
    _iterator11.f();
  }
  return {};
};
var areAllDesignAreasEmpty = exports.areAllDesignAreasEmpty = function areAllDesignAreasEmpty(_ref11) {
  var configuration = _ref11.configuration;
  var designdata = (0, _get["default"])(configuration, 'designdata', {});
  for (var key in designdata) {
    if (!designdata.hasOwnProperty(key)) {
      continue;
    }
    if (designdata[key].canvasData) {
      return false;
    }
  }
  return true;
};
var hasLastEditedDesignArea = exports.hasLastEditedDesignArea = function hasLastEditedDesignArea(designArea) {
  var lastSelectedDesignAreaIdentifier = (0, _get["default"])(designArea, 'lastSelectedDesignAreaIdentifier', {});
  var previousEditedDesignArea = (0, _get["default"])(designArea, 'previousEditedDesignArea', {});
  return !(0, _isEmpty["default"])(lastSelectedDesignAreaIdentifier) || !(0, _isEmpty["default"])(previousEditedDesignArea);
};
var getDesignAreaPreSelection = exports.getDesignAreaPreSelection = function getDesignAreaPreSelection(identifier) {
  var designerPreSelection = (0, _configuration.getConf)('designerPreSelection', {});
  if (!designerPreSelection.designAreas || !designerPreSelection.designAreas.length) {
    return {};
  }
  var preSelection = (0, _find2["default"])(designerPreSelection.designAreas, {
    identifier: identifier
  });
  return preSelection ? preSelection : {};
};
var getDesignAreaColorAmount = exports.getDesignAreaColorAmount = function getDesignAreaColorAmount(maxColorAmount, preSelectionColorAmount) {
  var amount = maxColorAmount > 0 ? 1 : null;
  if (preSelectionColorAmount > 0) {
    amount = preSelectionColorAmount > maxColorAmount ? maxColorAmount : preSelectionColorAmount;
  }
  return amount;
};
var isVectorizedLogoMandatory = exports.isVectorizedLogoMandatory = function isVectorizedLogoMandatory(designProductionMethod) {
  var _designProductionMeth;
  return !!(designProductionMethod !== null && designProductionMethod !== void 0 && (_designProductionMeth = designProductionMethod.options) !== null && _designProductionMeth !== void 0 && _designProductionMeth.vectorizedLogoMandatory);
};
var getVectorizeForDesignProductionMethods = exports.getVectorizeForDesignProductionMethods = function getVectorizeForDesignProductionMethods(state, designProductionMethodIdentifier) {
  var _getSelectedDesignAre3 = getSelectedDesignAreaProperties(state),
    designProductionMethod = _getSelectedDesignAre3.designProductionMethod;
  var newProductionMethod = getDesignProductionMethodByIdentifier(state, designProductionMethodIdentifier);
  var currentVectorsRequired = !!(0, _get["default"])(designProductionMethod, 'options.vectorsRequired');
  var newVectorsRequired = !!(0, _get["default"])(newProductionMethod, 'options.vectorsRequired');
  return {
    currentVectorsRequired: currentVectorsRequired,
    newVectorsRequired: newVectorsRequired
  };
};
var getMandatoryVectorizationForDesignProductionMethods = exports.getMandatoryVectorizationForDesignProductionMethods = function getMandatoryVectorizationForDesignProductionMethods(state, designProductionMethodIdentifier) {
  var _getSelectedDesignAre4 = getSelectedDesignAreaProperties(state),
    designProductionMethod = _getSelectedDesignAre4.designProductionMethod;
  var newProductionMethod = getDesignProductionMethodByIdentifier(state, designProductionMethodIdentifier);
  var currentVectorsMandatory = isVectorizedLogoMandatory(designProductionMethod);
  var newVectorsMandatory = isVectorizedLogoMandatory(newProductionMethod);
  return {
    currentVectorsMandatory: currentVectorsMandatory,
    newVectorsMandatory: newVectorsMandatory
  };
};
var getImagesByDesignArea = exports.getImagesByDesignArea = function getImagesByDesignArea(state, designAreaIdentifier) {
  if (!designAreaIdentifier) {
    designAreaIdentifier = getSelectedDesignArea(state).identifier;
  }
  var designData = getDesignDataByDesignAreaIdentifier(state, designAreaIdentifier);
  return (0, _get["default"])(designData, 'canvasData.objects', []).filter(function (_ref12) {
    var type = _ref12.type;
    return type === 'Image';
  });
};
function isOneLineText(state) {
  return (0, _get["default"])(getSelectedDesignProductionMethod(state), 'oneLineText', false);
}