"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.validateConfiguration = exports.switchSelectedAmount = exports.switchOptionsBasic = exports.switchOptions = exports.skipNextAutoResolve = exports.setStockInformationOption = exports.setSelectedVariantIdentifier = exports.setSelectedCalculation = exports.setSelectedAmounts = exports.setSelectedAmount = exports.setOptionclassificationChecked = exports.setOptionInputText = exports.setLoadIdentifier = exports.setLoadCode = exports.setDefaultSelectedVariantIdentifier = exports.setCustomTitle = exports.setConflictingSwitchoptionData = exports.setComment = exports.setCalculationErrorsResolved = exports.setCalculationEnabled = exports.setCalculationAutoResolveEnabled = exports.selectOptionclassification = exports.selectOption = exports.selectMultipleOptions = exports.saveConfiguration = exports.saveBulkNames = exports.resolveConflicts = exports.resetOptionInputTexts = exports.receiveValidation = exports.receiveSwitchoptionsresult = exports.receiveSavedConfiguration = exports.receiveOptions = exports.receiveOptionDetails = exports.receiveInspirations = exports.receiveDesignerData = exports.receiveConfigurationVariants = exports.receiveConfiguration = exports.receiveCodesnippets = exports.receiveClientData = exports.receiveCalculation = exports.loadInitialOptionclassification = exports.loadDesignerData = exports.loadConfiguration = exports.invalidateCalculation = exports.inspectValidationResults = exports.inspectCheckResults = exports.fetchOptions = exports.fetchOptionDetails = exports.fetchInspirations = exports.fetchInitialConfiguration = exports.fetchConfigurationVariants = exports.fetchConfigurationForDesignerProductPreview = exports.fetchConfigurationByCodeAsync = exports.fetchConfigurationByCode = exports.fetchConfiguration = exports.fetchCodesnippets = exports.fetchClientData = exports.doCalculation = exports.deleteSelectedAmounts = exports.deleteSelectedAmount = exports.deleteMissingVariants = exports.clearOptionDetails = exports.clearBulkNames = exports.applyVariantAmountPreSelection = exports.applyOptionInputText = exports.SWITCH_SELECTED_AMOUNT = exports.SET_STOCK_INFORMATION_OPTION = exports.SET_SELECTED_VARIANT_IDENTIFIER = exports.SET_SELECTED_CALCULATION = exports.SET_SELECTED_AMOUNTS = exports.SET_SELECTED_AMOUNT = exports.SET_OPTION_INPUT_TEXT = exports.SET_OPTIONCLASSIFICATION_CHECKED = exports.SET_LOAD_IDENTIFIER = exports.SET_LOAD_CODE = exports.SET_CUSTOM_TITLE = exports.SET_CONFLICTING_SWITCHOPTION_DATA = exports.SET_COMMENT = exports.SET_CALCULATION_ERRORS_RESOLVED = exports.SET_CALCULATION_ENABLED = exports.SET_CALCULATION_AUTO_RESOLVE_ENABLED = exports.SELECT_OPTIONCLASSIFICATION = exports.SAVE_BULKNAMES = exports.RESET_OPTION_INPUT_TEXTS = exports.RECEIVE_VALIDATION = exports.RECEIVE_SWITCHOPTIONSRESULT = exports.RECEIVE_SAVEDCONFIGURATION = exports.RECEIVE_OPTIONS = exports.RECEIVE_OPTIONDETAILS = exports.RECEIVE_INSPIRATIONS = exports.RECEIVE_DESIGNER_DATA = exports.RECEIVE_CONFIGURATIONVARIANTS = exports.RECEIVE_CONFIGURATION = exports.RECEIVE_CODESNIPPETS = exports.RECEIVE_CLIENT_DATA = exports.RECEIVE_CALCULATION = exports.INVALIDATE_CALCULATION = exports.DELETE_SELECTED_AMOUNTS = exports.DELETE_SELECTED_AMOUNT = exports.CLEAR_BULKNAMES = void 0;
exports.viewOptionDetails = void 0;
var apiActions = _interopRequireWildcard(require("../Actions"));
var _first = _interopRequireDefault(require("lodash/first"));
var _isObject = _interopRequireDefault(require("lodash/isObject"));
var _get = _interopRequireDefault(require("lodash/get"));
var _isArray = _interopRequireDefault(require("lodash/isArray"));
var _flatten = _interopRequireDefault(require("lodash/flatten"));
var _find = _interopRequireDefault(require("lodash/find"));
var _uniq = _interopRequireDefault(require("lodash/uniq"));
var _i18n = require("../../../Framework/i18n");
var _Api = _interopRequireDefault(require("../../../Framework/Api"));
var _createActionWithGlobalState = require("../../../Utils/Redux/createActionWithGlobalState");
var _configuration = require("../../configuration");
var _ServiceLocator = require("../../ServiceLocator");
var _Actions2 = require("../UI/Actions");
var _Actions3 = require("../../Reducers/Fonts/Actions");
var _Actions4 = require("../../Reducers/ImageGallery/Actions");
var _Selectors = require("./Selectors");
var _Selectors2 = require("../ConfigurationMode/Selectors");
var _Constant = require("../../Constant");
var _Selectors3 = require("../Fonts/Selectors");
var _Actions5 = require("../Fonts/Actions");
var _Modifiers = require("./Modifiers");
var _Actions6 = require("../DesignData/Actions");
var _Transformers = require("../DesignArea/Transformers");
var _Reducer = require("../DesignData/Reducer");
var _Actions7 = require("../ConfigurationMode/Actions");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 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 _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 _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 _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) { function t(_x9, _x0, _x1) { return _t.apply(this, arguments); } t.toString = function () { return _t.toString(); }; return t; }(function (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); }); }; }
var RECEIVE_CONFIGURATION = exports.RECEIVE_CONFIGURATION = 'RECEIVE_CONFIGURATION';
var RECEIVE_DESIGNER_DATA = exports.RECEIVE_DESIGNER_DATA = 'RECEIVE_DESIGNER_DATA';
var SELECT_OPTIONCLASSIFICATION = exports.SELECT_OPTIONCLASSIFICATION = 'SELECT_OPTIONCLASSIFICATION';
var RECEIVE_OPTIONS = exports.RECEIVE_OPTIONS = 'RECEIVE_OPTIONS';
var RECEIVE_SWITCHOPTIONSRESULT = exports.RECEIVE_SWITCHOPTIONSRESULT = 'RECEIVE_SWITCHOPTIONSRESULT';
var RECEIVE_CALCULATION = exports.RECEIVE_CALCULATION = 'RECEIVE_CALCULATION';
var INVALIDATE_CALCULATION = exports.INVALIDATE_CALCULATION = 'INVALIDATE_CALCULATION';
var RECEIVE_OPTIONDETAILS = exports.RECEIVE_OPTIONDETAILS = 'RECEIVE_OPTIONDETAILS';
var RECEIVE_SAVEDCONFIGURATION = exports.RECEIVE_SAVEDCONFIGURATION = 'RECEIVE_SAVEDCONFIGURATION';
var RECEIVE_VALIDATION = exports.RECEIVE_VALIDATION = 'RECEIVE_VALIDATION';
var RECEIVE_CONFIGURATIONVARIANTS = exports.RECEIVE_CONFIGURATIONVARIANTS = 'RECEIVE_CONFIGURATIONVARIANTS';
var RECEIVE_CODESNIPPETS = exports.RECEIVE_CODESNIPPETS = 'RECEIVE_CODESNIPPETS';
var RECEIVE_CLIENT_DATA = exports.RECEIVE_CLIENT_DATA = 'RECEIVE_CLIENT_DATA';
var RECEIVE_INSPIRATIONS = exports.RECEIVE_INSPIRATIONS = 'RECEIVE_INSPIRATIONS';
var SET_CUSTOM_TITLE = exports.SET_CUSTOM_TITLE = 'SET_CUSTOM_TITLE';
var SET_LOAD_CODE = exports.SET_LOAD_CODE = 'SET_LOAD_CODE';
var SET_LOAD_IDENTIFIER = exports.SET_LOAD_IDENTIFIER = 'SET_LOAD_IDENTIFIER';
var SET_STOCK_INFORMATION_OPTION = exports.SET_STOCK_INFORMATION_OPTION = 'SET_STOCK_INFORMATION_OPTION';
var SET_SELECTED_VARIANT_IDENTIFIER = exports.SET_SELECTED_VARIANT_IDENTIFIER = 'SET_SELECTED_VARIANT_IDENTIFIER';
var SET_CALCULATION_ENABLED = exports.SET_CALCULATION_ENABLED = 'SET_CALCULATION_ENABLED';
var SET_CALCULATION_ERRORS_RESOLVED = exports.SET_CALCULATION_ERRORS_RESOLVED = 'SET_CALCULATION_ERRORS_RESOLVED';
var SET_CALCULATION_AUTO_RESOLVE_ENABLED = exports.SET_CALCULATION_AUTO_RESOLVE_ENABLED = 'SET_CALCULATION_AUTO_RESOLVE_ENABLED';
var SET_OPTIONCLASSIFICATION_CHECKED = exports.SET_OPTIONCLASSIFICATION_CHECKED = 'SET_OPTIONCLASSIFICATION_CHECKED';
var SET_CONFLICTING_SWITCHOPTION_DATA = exports.SET_CONFLICTING_SWITCHOPTION_DATA = 'SET_CONFLICTING_SWITCHOPTION_DATA';
var SET_SELECTED_AMOUNT = exports.SET_SELECTED_AMOUNT = 'SET_SELECTED_AMOUNT';
var SET_OPTION_INPUT_TEXT = exports.SET_OPTION_INPUT_TEXT = 'SET_OPTION_INPUT_TEXT';
var RESET_OPTION_INPUT_TEXTS = exports.RESET_OPTION_INPUT_TEXTS = 'RESET_OPTION_INPUT_TEXTS';
var SWITCH_SELECTED_AMOUNT = exports.SWITCH_SELECTED_AMOUNT = 'SWITCH_SELECTED_AMOUNT';
var SAVE_BULKNAMES = exports.SAVE_BULKNAMES = 'SAVE_BULKNAMES';
var CLEAR_BULKNAMES = exports.CLEAR_BULKNAMES = 'CLEAR_BULKNAMES';
var DELETE_SELECTED_AMOUNT = exports.DELETE_SELECTED_AMOUNT = 'DELETE_SELECTED_AMOUNT';
var SET_SELECTED_CALCULATION = exports.SET_SELECTED_CALCULATION = 'SET_SELECTED_CALCULATION';
var SET_COMMENT = exports.SET_COMMENT = 'SET_COMMENT';
var SET_SELECTED_AMOUNTS = exports.SET_SELECTED_AMOUNTS = 'SET_SELECTED_AMOUNTS';
var DELETE_SELECTED_AMOUNTS = exports.DELETE_SELECTED_AMOUNTS = 'DELETE_SELECTED_AMOUNTS';
var receiveConfiguration = exports.receiveConfiguration = function receiveConfiguration(json, _ref) {
  var checkValidation = _ref.checkValidation;
  return /*#__PURE__*/function () {
    var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(dispatch, getState) {
      var prevState, action, _getState, configurator, configuration, selectedoptionclassification, loadIdentifier, _getAvailableConfigur, designerEnabled, initialDesignData;
      return _regeneratorRuntime().wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            prevState = getState();
            dispatch(setCalculationEnabled(false));
            if (checkValidation) {
              dispatch(inspectValidationResults(json));
            }
            action = dispatch({
              type: RECEIVE_CONFIGURATION,
              data: (0, _Modifiers.patchViewImages)(json),
              receivedAt: Date.now()
            });
            dispatch(inspectCheckResults());
            _getState = getState(), configurator = _getState.configurator;
            configuration = configurator.configuration, selectedoptionclassification = configurator.selectedoptionclassification, loadIdentifier = configurator.loadIdentifier;
            _getAvailableConfigur = (0, _Selectors2.getAvailableConfigurationModes)(getState()), designerEnabled = _getAvailableConfigur.designer;
            if (configurator.loadCode) {
              dispatch((0, _Actions4.addImagesFromDesignArea)(configurator));
            }
            dispatch(deleteMissingVariants(configurator));

            // load first optionclassification if not selected yet
            if (!selectedoptionclassification.identifier && (0, _configuration.getConf)('showInitialOptionclassification')) {
              dispatch(loadInitialOptionclassification(configuration));
            }
            if ((0, _configuration.getConf)('loadInspirations')) {
              dispatch(fetchInspirations(configuration.item.identifier));
            }
            dispatch((0, _Actions2.setVisible)('configurationvariantSelection', false));
            if (prevState.configurator.configuration.item.identifier && prevState.configurator.configuration.item.identifier !== configuration.item.identifier) {
              dispatch(fetchConfigurationVariants(configuration.item.identifier));
            }
            applyVariantAmountPreSelection(configurator);
            setDefaultSelectedVariantIdentifier((0, _Selectors.getConfigurator)(getState()), loadIdentifier);
            if (!designerEnabled) {
              _context.next = 24;
              break;
            }
            _context.next = 19;
            return dispatch((0, _Actions3.fetchFonts)());
          case 19:
            dispatch((0, _Actions5.addCustomFonts)((0, _Selectors3.getUsedCustomFontsInEditor)(getState())));
            _context.next = 22;
            return dispatch(loadDesignerData((0, _Selectors.getConfiguration)((0, _Selectors.getConfigurator)(getState()))));
          case 22:
            initialDesignData = (0, _Transformers.createInitialDesignDataFromDesignAreas)((0, _get["default"])(getState(), 'designArea.filteredDesignAreas') || [], (0, _Reducer.getDesignData)((0, _Selectors.getConfigurator)(getState())));
            dispatch((0, _Actions6.setInitialDesignData)(initialDesignData));
          case 24:
            // enable calculation and trigger it
            dispatch(setCalculationEnabled(true));
            dispatch(invalidateCalculation());
            dispatch(doCalculation((0, _Selectors.getConfiguration)((0, _Selectors.getConfigurator)(getState()))));
            return _context.abrupt("return", action);
          case 28:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function (_x, _x2) {
      return _ref2.apply(this, arguments);
    };
  }();
};
var deleteMissingVariants = exports.deleteMissingVariants = function deleteMissingVariants(configurator) {
  return /*#__PURE__*/function () {
    var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(dispatch) {
      var children, selectedAmounts, item, result, itemGroupChildren, _iterator, _step, itemGroup, flattenendSubChildren, selectedVariant;
      return _regeneratorRuntime().wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            children = (0, _Selectors.getChildren)(configurator).map(function (variant) {
              return variant.identifier;
            });
            selectedAmounts = (0, _Selectors.getSelectedAmounts)(configurator);
            item = (0, _get["default"])(configurator, 'configuration.item');
            result = [];
            itemGroupChildren = (0, _get["default"])(item, 'itemGroup.children', []);
            if (itemGroupChildren.length > 0) {
              _iterator = _createForOfIteratorHelper(item.itemGroup.children);
              try {
                for (_iterator.s(); !(_step = _iterator.n()).done;) {
                  itemGroup = _step.value;
                  result.push(Object.values((0, _Selectors.getDeepestChildIdentifiers)(itemGroup)));
                }
              } catch (err) {
                _iterator.e(err);
              } finally {
                _iterator.f();
              }
            } else {
              result.push(item.identifier);
            }
            flattenendSubChildren = (0, _flatten["default"])(result);
            _context2.t0 = _regeneratorRuntime().keys(selectedAmounts);
          case 8:
            if ((_context2.t1 = _context2.t0()).done) {
              _context2.next = 15;
              break;
            }
            selectedVariant = _context2.t1.value;
            if (selectedAmounts.hasOwnProperty(selectedVariant)) {
              _context2.next = 12;
              break;
            }
            return _context2.abrupt("continue", 8);
          case 12:
            if (children.length !== 0 && children.indexOf(selectedVariant) === -1 && flattenendSubChildren.indexOf(selectedVariant) === -1) {
              dispatch(deleteSelectedAmount(selectedVariant));
              dispatch((0, _Actions2.reportError)((0, _i18n.t)('missingVariantError', {
                selectedVariant: selectedVariant
              })));
            }
            _context2.next = 8;
            break;
          case 15:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    }));
    return function (_x3) {
      return _ref3.apply(this, arguments);
    };
  }();
};
var setDefaultSelectedVariantIdentifier = exports.setDefaultSelectedVariantIdentifier = function setDefaultSelectedVariantIdentifier(configurator, loadIdentifier) {
  var variantChildren = (0, _Selectors.getChildren)(configurator).map(function (variant) {
    return variant.itemGroup ? variant.itemGroup.children : variant;
  });
  var children = (0, _uniq["default"])((0, _flatten["default"])(variantChildren).map(function (child) {
    return child.identifier;
  }));
  var firstSelectedAmountEntry = (0, _first["default"])(Object.keys((0, _Selectors.getSelectedAmounts)(configurator)));
  var item = (0, _Selectors.getItem)(configurator);
  var selectedVariant = children.length ? children[0] : null;
  if (children.indexOf(loadIdentifier) !== -1) {
    selectedVariant = loadIdentifier;
  } else if (firstSelectedAmountEntry) {
    selectedVariant = firstSelectedAmountEntry;
  } else {
    selectedVariant = item.identifier;
  }
  _ServiceLocator.Services.configurator.setSelectedVariantIdentifier(selectedVariant);
};
var applyVariantAmountPreSelection = exports.applyVariantAmountPreSelection = function applyVariantAmountPreSelection(configurator) {
  var designerPreSelection = (0, _configuration.getConf)('designerPreSelection', {});
  var itemAmounts = designerPreSelection.itemAmounts;
  if (itemAmounts) {
    var children = (0, _Selectors.getChildren)(configurator).map(function (variant) {
      return variant.identifier;
    });
    for (var preSelectionVariant in itemAmounts) {
      if (!itemAmounts.hasOwnProperty(preSelectionVariant)) {
        continue;
      }
      var amount = +itemAmounts[preSelectionVariant];
      if (children.indexOf(preSelectionVariant) !== -1 && amount > 0) {
        _ServiceLocator.Services.configurator.setSelectedAmount(preSelectionVariant, amount);
      }
    }
  }
};
var selectOptionclassification = exports.selectOptionclassification = function selectOptionclassification(optionclassification) {
  var triggerFetchOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  var showOptionlist = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  return function (dispatch, getState) {
    if (getState().ui.visibilityMap.startHere) {
      dispatch((0, _Actions2.setVisible)('startHere', false));
    }
    var action = dispatch({
      type: SELECT_OPTIONCLASSIFICATION,
      optionclassification: optionclassification
    });
    var configuration = getState().configurator.configuration;
    if (triggerFetchOptions) {
      _ServiceLocator.Services.analytics.triggerEvent(_Constant.EventTypes['select_component'], optionclassification.identifier);
      _ServiceLocator.Services.configurator.loadOptions(configuration.item.identifier, optionclassification.identifier, configuration);
    }
    dispatch((0, _Actions2.setVisible)('optionlist', showOptionlist));
    return action;
  };
};
var receiveOptions = exports.receiveOptions = function receiveOptions(json, extraData) {
  return function (dispatch, getState) {
    // it should wait until the options are loaded for the optionclassification...
    var optionclassification = extraData.optionclassification;

    // make sure the received option list belongs to the selected optionclassification,
    // it might have changed since the request was sent
    if (optionclassification === getState().configurator.selectedoptionclassification.identifier) {
      if ((0, _configuration.getConf)('checkOptionclassificationOnSelect')) {
        dispatch(setOptionclassificationChecked(optionclassification));
      }
      return dispatch({
        type: RECEIVE_OPTIONS,
        data: json,
        receivedAt: Date.now()
      });
    }
  };
};
var receiveSwitchoptionsresult = exports.receiveSwitchoptionsresult = function receiveSwitchoptionsresult(json, extraData) {
  return function (dispatch, getState) {
    var switchOptionData = extraData.switchOptionData,
      noCheck = extraData.noCheck,
      setChecked = extraData.setChecked,
      refreshOptions = extraData.refreshOptions;
    var action = dispatch({
      type: RECEIVE_SWITCHOPTIONSRESULT,
      data: (0, _Modifiers.patchViewImages)(json),
      receivedAt: Date.now()
    });
    var _getState2 = getState(),
      configurator = _getState2.configurator;
    var configuration = configurator.configuration,
      selectedoptionclassification = configurator.selectedoptionclassification;

    // if it was sent with noCheck param, there is nothing to do with the check results..
    // it should be a temporary configuration state
    if (noCheck) {
      return action;
    }
    var checkResultOk = dispatch(inspectCheckResults());
    if (checkResultOk) {
      if (setChecked) {
        dispatch(setOptionclassificationChecked((0, _first["default"])(Object.keys(switchOptionData))));
      }
      // do it only when there is a selected option classification
      if (refreshOptions && selectedoptionclassification) {
        _ServiceLocator.Services.configurator.loadOptions(configuration.item.identifier, selectedoptionclassification.identifier, configuration);
      }
    } else {
      dispatch(setConflictingSwitchoptionData(switchOptionData));
    }
    return action;
  };
};
var receiveCalculation = exports.receiveCalculation = function receiveCalculation(json) {
  return {
    type: RECEIVE_CALCULATION,
    data: json,
    receivedAt: Date.now()
  };
};
var invalidateCalculation = exports.invalidateCalculation = function invalidateCalculation() {
  return {
    type: INVALIDATE_CALCULATION
  };
};
var setCalculationErrorsResolved = exports.setCalculationErrorsResolved = function setCalculationErrorsResolved() {
  return {
    type: SET_CALCULATION_ERRORS_RESOLVED
  };
};
var setCalculationAutoResolveEnabled = exports.setCalculationAutoResolveEnabled = function setCalculationAutoResolveEnabled(enabled) {
  return {
    type: SET_CALCULATION_AUTO_RESOLVE_ENABLED,
    enabled: enabled
  };
};
var skipNextAutoResolve = exports.skipNextAutoResolve = function skipNextAutoResolve() {
  return setCalculationAutoResolveEnabled('skipNext');
};
var receiveOptionDetails = exports.receiveOptionDetails = function receiveOptionDetails(json) {
  return function (dispatch) {
    dispatch((0, _Actions2.setVisible)('optionDetails', true));
    return dispatch({
      type: RECEIVE_OPTIONDETAILS,
      data: json,
      receivedAt: Date.now()
    });
  };
};
var clearOptionDetails = exports.clearOptionDetails = function clearOptionDetails() {
  return {
    type: RECEIVE_OPTIONDETAILS,
    data: {},
    receivedAt: Date.now()
  };
};
var receiveSavedConfiguration = exports.receiveSavedConfiguration = function receiveSavedConfiguration(json) {
  return {
    type: RECEIVE_SAVEDCONFIGURATION,
    data: (0, _Modifiers.patchViewImages)(json),
    receivedAt: Date.now()
  };
};
var receiveValidation = exports.receiveValidation = function receiveValidation(json) {
  return function (dispatch, getState) {
    var action = dispatch({
      type: RECEIVE_VALIDATION,
      data: json,
      receivedAt: Date.now()
    });
    var validationResult = getState().configurator.validation;
    if ((0, _isObject["default"])(validationResult) && validationResult.success === false) {
      dispatch((0, _Actions2.setVisible)('validationResult', true));
      throw 'Invalid configuration!';
    }
    return action;
  };
};
var receiveConfigurationVariants = exports.receiveConfigurationVariants = function receiveConfigurationVariants(json) {
  return {
    type: RECEIVE_CONFIGURATIONVARIANTS,
    data: json,
    receivedAt: Date.now()
  };
};
var receiveCodesnippets = exports.receiveCodesnippets = function receiveCodesnippets(json) {
  return {
    type: RECEIVE_CODESNIPPETS,
    data: json,
    receivedAt: Date.now()
  };
};
var fetchConfigurationForDesignerProductPreview = exports.fetchConfigurationForDesignerProductPreview = function fetchConfigurationForDesignerProductPreview() {
  return /*#__PURE__*/function () {
    var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(dispatch, getState) {
      var itemIdentifier, _getAvailableConfigur2, designerEnabled, initialDesignData;
      return _regeneratorRuntime().wrap(function _callee3$(_context3) {
        while (1) switch (_context3.prev = _context3.next) {
          case 0:
            itemIdentifier = getState().configurator.loadIdentifier;
            dispatch(setCalculationEnabled(false));
            _context3.next = 4;
            return dispatch(apiActions.fetchData('configuration/loadbyitemidentifier/' + itemIdentifier, function (json) {
              return {
                type: RECEIVE_CONFIGURATION,
                data: (0, _Modifiers.patchViewImages)(json),
                receivedAt: Date.now()
              };
            }));
          case 4:
            setDefaultSelectedVariantIdentifier((0, _Selectors.getConfigurator)(getState()), itemIdentifier);
            _getAvailableConfigur2 = (0, _Selectors2.getAvailableConfigurationModes)(getState()), designerEnabled = _getAvailableConfigur2.designer;
            if (!designerEnabled) {
              _context3.next = 12;
              break;
            }
            dispatch((0, _Actions7.selectConfigurationMode)('designer'));
            _context3.next = 10;
            return dispatch(loadDesignerData((0, _Selectors.getConfiguration)((0, _Selectors.getConfigurator)(getState()))));
          case 10:
            initialDesignData = (0, _Transformers.createInitialDesignDataFromDesignAreas)((0, _get["default"])(getState(), 'designArea.filteredDesignAreas') || [], (0, _Reducer.getDesignData)((0, _Selectors.getConfigurator)(getState())));
            dispatch((0, _Actions6.setInitialDesignData)(initialDesignData));
          case 12:
          case "end":
            return _context3.stop();
        }
      }, _callee3);
    }));
    return function (_x4, _x5) {
      return _ref4.apply(this, arguments);
    };
  }();
};
var receiveClientData = exports.receiveClientData = function receiveClientData(json) {
  return function (dispatch, getState) {
    dispatch({
      type: RECEIVE_CLIENT_DATA,
      data: json,
      receivedAt: Date.now()
    });
    if (json.success === false) {
      return dispatch((0, _Actions2.reportError)((0, _i18n.t)('clientValidationError')));
    }
    var client = (0, _Selectors.getClient)(getState().configurator);
    _Api["default"].setChannel(client.channel);
    var requests = [];
    if ((0, _Selectors.isDesignerProductPreviewMode)()) {
      // initial configuration is not needed
    } else {
      requests.push(_ServiceLocator.Services.configurator.loadInitialConfiguration());
    }
    requests.push(_ServiceLocator.Services.configurator.loadCodeSnippets());
    return Promise.all(requests);
  };
};
var receiveInspirations = exports.receiveInspirations = function receiveInspirations(json) {
  return {
    type: RECEIVE_INSPIRATIONS,
    data: json
  };
};
var setCustomTitle = exports.setCustomTitle = function setCustomTitle(title) {
  return {
    type: SET_CUSTOM_TITLE,
    title: title
  };
};
var inspectCheckResults = exports.inspectCheckResults = function inspectCheckResults() {
  return function (dispatch, getState) {
    var _getState3 = getState(),
      ui = _getState3.ui,
      configurator = _getState3.configurator;
    var configuration = configurator.configuration;
    if ((0, _isObject["default"])(configuration.check_results)) {
      if (configuration.check_results.status) {
        if (ui.visibilityMap.incompatibility) {
          dispatch((0, _Actions2.setVisible)('incompatibility', false));
        }
        return true;
      } else {
        dispatch((0, _Actions2.setVisible)('incompatibility', true));
        return false;
      }
    }
    return true;
  };
};
var inspectValidationResults = exports.inspectValidationResults = function inspectValidationResults(configuration) {
  return function (dispatch) {
    var validationResult = (0, _get["default"])(configuration, 'information.validation_result');
    if ((0, _isObject["default"])(validationResult) && validationResult.success === false) {
      dispatch((0, _Actions2.setVisible)('validationResult', true));
    }
  };
};
var fetchConfiguration = exports.fetchConfiguration = function fetchConfiguration(itemidentifier) {
  var selectOptions = (0, _configuration.getConf)('selectOptions');
  var urlToCall = "configuration/loadbyitemidentifier/".concat(itemidentifier);
  if (selectOptions) {
    var switchOptionData = JSON.stringify(getSwitchOptionData(selectOptions));
    urlToCall = "".concat(urlToCall, "?_switch_options=").concat(switchOptionData);
  }
  return apiActions.fetchData(urlToCall, receiveConfiguration);
};
var fetchConfigurationByCode = exports.fetchConfigurationByCode = function fetchConfigurationByCode(code) {
  var checkValidation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  return apiActions.fetchData('configuration/loadbyconfigurationcode/' + code, receiveConfiguration, {
    checkValidation: checkValidation
  });
};
var fetchConfigurationByCodeAsync = exports.fetchConfigurationByCodeAsync = function fetchConfigurationByCodeAsync(code) {
  var checkValidation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  return apiActions.fetchDataAsync('configuration/loadbyconfigurationcode/' + code, receiveConfiguration, {
    checkValidation: checkValidation
  });
};
var fetchOptions = exports.fetchOptions = function fetchOptions(itemidentifier, optionclassification, configuration) {
  return apiActions.postData('options/list/' + itemidentifier + '/' + optionclassification, {
    configuration: configuration
  }, receiveOptions, {},
  // config
  {
    optionclassification: optionclassification
  } // extraData
  );
};

var switchOptionsBasic = exports.switchOptionsBasic = function switchOptionsBasic(configuration, switchedOptions) {
  var noCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  var config = {};
  if (noCheck) {
    config.params = {
      nocheck: 1
    };
  }
  return apiActions.postData('configuration/switchoption', {
    configuration: configuration,
    switchedOptions: switchedOptions
  }, function (data) {
    return {
      // dummy receiver
      type: 'RECEIVE_SWITCHOPTIONSRESULT_BASIC',
      data: data
    };
  }, config);
};
var switchOptions = exports.switchOptions = function switchOptions(configuration, switchOptionData) {
  var noCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  var refreshOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  var setChecked = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  return function (dispatch) {
    return dispatch(switchOptionsBasic(configuration, switchOptionData, noCheck)).then(function (action) {
      var extraData = {
        switchOptionData: switchOptionData,
        noCheck: noCheck,
        refreshOptions: refreshOptions,
        setChecked: setChecked
      };
      return dispatch(receiveSwitchoptionsresult(action.data, extraData));
    });
  };
};
var doCalculation = exports.doCalculation = function doCalculation() {
  return function (dispatch, getState) {
    var configuration = (0, _Selectors.getConfiguration)((0, _Selectors.getConfigurator)(getState()));
    if (!configuration.item.identifier) {
      return {};
    }
    return dispatch(apiActions.postDataAsync('calculation', configuration, receiveCalculation));
  };
};
var fetchOptionDetails = exports.fetchOptionDetails = function fetchOptionDetails(optionidentifier, configuration) {
  return apiActions.postData('options/detail/' + optionidentifier, {
    configuration: configuration
  }, receiveOptionDetails);
};
var saveConfiguration = exports.saveConfiguration = function saveConfiguration(configuration, configurationtype) {
  return apiActions.postDataAsync('configurations', {
    configuration: configuration,
    configurationtype: configurationtype
  }, receiveSavedConfiguration);
};
var validateConfiguration = exports.validateConfiguration = function validateConfiguration(configuration) {
  return apiActions.postData('configuration/validate', {
    configuration: configuration
  }, receiveValidation);
};
var fetchConfigurationVariants = exports.fetchConfigurationVariants = function fetchConfigurationVariants(itemidentifier) {
  return apiActions.fetchData('items/getconfigurationvariants/' + itemidentifier, receiveConfigurationVariants);
};
var fetchCodesnippets = exports.fetchCodesnippets = function fetchCodesnippets() {
  return apiActions.fetchData('codesnippets/getcurrent', receiveCodesnippets);
};
var fetchClientData = exports.fetchClientData = function fetchClientData() {
  return apiActions.fetchData('client', receiveClientData);
};
var fetchInspirations = exports.fetchInspirations = function fetchInspirations(itemidentifier) {
  return apiActions.fetchData('inspirations/' + itemidentifier, receiveInspirations);
};
var setLoadCode = exports.setLoadCode = function setLoadCode() {
  var loadCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  return {
    type: SET_LOAD_CODE,
    loadCode: loadCode
  };
};
var setLoadIdentifier = exports.setLoadIdentifier = function setLoadIdentifier(loadIdentifier) {
  return {
    type: SET_LOAD_IDENTIFIER,
    loadIdentifier: loadIdentifier
  };
};
var setStockInformationOption = exports.setStockInformationOption = function setStockInformationOption(option) {
  return {
    type: SET_STOCK_INFORMATION_OPTION,
    stockInformationOption: option
  };
};
var setSelectedVariantIdentifier = exports.setSelectedVariantIdentifier = function setSelectedVariantIdentifier(identifier) {
  return {
    type: SET_SELECTED_VARIANT_IDENTIFIER,
    selectedVariantIdentifier: identifier
  };
};
var setCalculationEnabled = exports.setCalculationEnabled = function setCalculationEnabled(enabled) {
  return {
    type: SET_CALCULATION_ENABLED,
    enabled: enabled
  };
};
var setOptionclassificationChecked = exports.setOptionclassificationChecked = function setOptionclassificationChecked(optionclassification) {
  return function (dispatch, getState) {
    if (_typeof(optionclassification) !== 'object') {
      optionclassification = (0, _find["default"])(getState().configurator.configuration.optionclassifications, {
        identifier: optionclassification
      });
    }
    if (!getState().configurator.checkedOptionclassifications[optionclassification.identifier]) {
      return dispatch({
        type: SET_OPTIONCLASSIFICATION_CHECKED,
        optionclassification: optionclassification
      });
    }
  };
};
var setConflictingSwitchoptionData = exports.setConflictingSwitchoptionData = function setConflictingSwitchoptionData(switchOptionData) {
  return {
    type: SET_CONFLICTING_SWITCHOPTION_DATA,
    switchOptionData: switchOptionData
  };
};
var fetchInitialConfiguration = exports.fetchInitialConfiguration = function fetchInitialConfiguration() {
  return function (dispatch, getState) {
    var _getState$configurato = getState().configurator,
      loadCode = _getState$configurato.loadCode,
      loadIdentifier = _getState$configurato.loadIdentifier;
    var defaultLoadIdentifier = (0, _configuration.getConf)('defaultLoadIdentifier');
    if (loadCode) {
      // Load the configuration by code
      return dispatch(fetchConfigurationByCode(loadCode)).then(function (configuration) {
        if (configuration.error) {
          dispatch((0, _Actions2.reportConfigurationNotFoundError)((0, _i18n.t)('loadConfiguration.error.loadingFailed')));
        } else {
          _ServiceLocator.Services.analytics.triggerEvent(_Constant.EventTypes.load_item, configuration.data.item.identifier);
          dispatch(setLoadCode(null));
        }
      });
    } else if ((0, _configuration.getConf)('loadVariantsFirst')) {
      // Load variants by identifier
      dispatch((0, _Actions2.setVisible)('configurationvariantSelection', true));
      return dispatch(fetchConfigurationVariants(loadIdentifier)).then(function (result) {
        // if the result contains error just return, do nothing else
        if (result.error) {
          return;
        }
        var _getState$configurato2 = getState().configurator,
          configurationvariants = _getState$configurato2.configurationvariants,
          loadIdentifier = _getState$configurato2.loadIdentifier;

        // If there is only one variant or the list is empty, fall back to fetchConfiguration
        if ((0, _isArray["default"])(configurationvariants)) {
          if (configurationvariants.length === 0) {
            // Load the options for the initially selected optionclassification
            dispatch(fetchConfiguration(loadIdentifier));
          }
          if (configurationvariants.length === 1) {
            // There is only one variant in the list, just load it
            dispatch(fetchConfiguration(configurationvariants[0].identifier));
          }
        }
      });
    } else if (loadIdentifier === '__empty__') {
      return Promise.resolve();
    } else if (loadIdentifier) {
      return dispatch(fetchConfiguration(loadIdentifier));
    } else if (defaultLoadIdentifier) {
      return dispatch(fetchConfiguration(defaultLoadIdentifier));
    }
  };
};
var loadInitialOptionclassification = exports.loadInitialOptionclassification = function loadInitialOptionclassification(configuration) {
  return function (dispatch) {
    var identifier = configuration.item.identifier;
    var optionclassification = (0, _get["default"])(configuration, 'optionclassifications[0]');
    dispatch(selectOptionclassification(optionclassification));
    _ServiceLocator.Services.configurator.loadOptions(identifier, optionclassification.identifier, configuration);
    dispatch((0, _Actions2.setVisible)('optionlist', true));
  };
};
var resolveConflicts = exports.resolveConflicts = function resolveConflicts() {
  return function (dispatch, getState) {
    var _getState4 = getState(),
      configurator = _getState4.configurator;
    var configuration = configurator.configuration;
    var incompatibilityCheckResults = configuration.check_results;
    var p = false;
    if ((0, _isArray["default"])(incompatibilityCheckResults.check_results)) {
      dispatch(setCalculationEnabled(false)); // disable calculation while waiting for all options to be switched
      var _iterator2 = _createForOfIteratorHelper(incompatibilityCheckResults.check_results),
        _step2;
      try {
        var _loop = function _loop() {
          var result = _step2.value;
          if (result.status === false) {
            // check for data to perform automated option switching
            var switchOptionsData = (0, _get["default"])(result, 'data.switchOptions');
            if (switchOptionsData) {
              if (p) {
                p = p.then(function (action) {
                  return dispatch(switchOptionsBasic(action.data, switchOptionsData, true));
                });
              } else {
                p = dispatch(switchOptionsBasic(configuration, switchOptionsData, true));
              }
            }
          }
        };
        for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
          _loop();
        }
      } catch (err) {
        _iterator2.e(err);
      } finally {
        _iterator2.f();
      }
      if (p) {
        p = p.then(function (action) {
          // after all conflicts resolved, the desired option can be set
          var conflictingSwitchOptionData = getState().configurator.conflictingSwitchOptionData;
          return dispatch(switchOptions(action.data, conflictingSwitchOptionData, false, true, true));
        }).then(function (action) {
          if ((0, _get["default"])(action, 'data.check_results.status') === false) {
            throw 'There are new conflicts..';
          }
          var configuration = getState().configurator.configuration;

          // enable calculation and refresh it
          dispatch(setCalculationEnabled(true));
          dispatch(invalidateCalculation());
          dispatch(doCalculation(configuration));

          // hide the incompatibility dialog
          dispatch((0, _Actions2.setVisible)('incompatibility', false));
          return action;
        })["catch"](function (e) {
          // eslint-disable-next-line no-console
          console.warn('Problem when resolving conflicts:', e);
        });
      } else {
        dispatch((0, _Actions2.setVisible)('incompatibility', false));
        dispatch(setCalculationEnabled(true));
      }
    }
    return p;
  };
};
var selectOption = exports.selectOption = function selectOption(option) {
  var refreshOptionlist = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  var showOptionDetails = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  var optionclassification = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  return function (dispatch, getState) {
    var _getState$configurato3 = getState().configurator,
      configuration = _getState$configurato3.configuration,
      selectedoptionclassification = _getState$configurato3.selectedoptionclassification;
    if (!optionclassification) {
      optionclassification = selectedoptionclassification;
    }
    _ServiceLocator.Services.analytics.triggerEvent(_Constant.EventTypes['switch_option'], {
      component: optionclassification.identifier,
      option: option.identifier
    });
    var switchOptionData = _defineProperty({}, optionclassification.identifier, _objectSpread(_objectSpread({}, option), {}, {
      amount: isNaN(parseInt(option.amount)) ? 0 : option.amount,
      check_results: null // it can mess the response, so should remove it.
    }));

    dispatch((0, _Actions2.setVisible)('optionDetails', showOptionDetails));
    return dispatch(switchOptions(configuration, switchOptionData, false, refreshOptionlist, true));
  };
};
var applyOptionInputText = exports.applyOptionInputText = function applyOptionInputText(optionClassification) {
  return function (dispatch, getState) {
    var switchOptionData = _defineProperty({}, optionClassification.identifier, []);
    var _getState$configurato4 = getState().configurator,
      configuration = _getState$configurato4.configuration,
      optionInputTexts = _getState$configurato4.optionInputTexts;
    if (!optionClassification.selectedoptions) {
      return;
    }
    var _iterator3 = _createForOfIteratorHelper(optionClassification.selectedoptions),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var selectedOption = _step3.value;
        var inputText = (0, _get["default"])((0, _find["default"])(optionInputTexts, ['optionIdentifier', selectedOption.identifier]), 'inputText', null);
        if (inputText && inputText !== selectedOption.inputText) {
          switchOptionData[optionClassification.identifier].push(_objectSpread(_objectSpread({}, selectedOption), {}, {
            inputText: inputText,
            check_results: null
          }));
        }
      }
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    dispatch(resetOptionInputTexts());
    if (switchOptionData[optionClassification.identifier].length > 0) {
      return dispatch(switchOptions(configuration, switchOptionData, false, true, true));
    }
  };
};
var selectMultipleOptions = exports.selectMultipleOptions = function selectMultipleOptions(optionsList) {
  return function (dispatch, getState) {
    var configuration = (0, _Selectors.getConfiguration)((0, _Selectors.getConfigurator)(getState()));
    var switchOptionData = getSwitchOptionData(optionsList);
    return dispatch(switchOptions(configuration, switchOptionData, false, false, true));
  };
};
var getSwitchOptionData = function getSwitchOptionData(optionsList) {
  var switchOptionData = {};
  var _iterator4 = _createForOfIteratorHelper(optionsList),
    _step4;
  try {
    for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
      var component = _step4.value;
      switchOptionData[component.identifier] = component.selectedoptions.map(function (_ref5) {
        var identifier = _ref5.identifier,
          amount = _ref5.amount,
          inputText = _ref5.inputText;
        return {
          identifier: identifier,
          inputText: inputText,
          amount: typeof amount === 'undefined' ? 1 : amount,
          check_results: null
        };
      });
    }
  } catch (err) {
    _iterator4.e(err);
  } finally {
    _iterator4.f();
  }
  return switchOptionData;
};
var viewOptionDetails = exports.viewOptionDetails = function viewOptionDetails(option) {
  return function (dispatch, getState) {
    if (!option) {
      return;
    }
    var _getState$configurato5 = getState().configurator,
      configuration = _getState$configurato5.configuration,
      optiondetails = _getState$configurato5.optiondetails;
    if (optiondetails.identifier !== option.identifier) {
      dispatch(fetchOptionDetails(option.identifier, configuration));
    } else {
      dispatch((0, _Actions2.setVisible)('optionDetails', true));
    }
  };
};
var loadConfiguration = exports.loadConfiguration = function loadConfiguration() {
  return /*#__PURE__*/function () {
    var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(dispatch, getState) {
      var loadCode, action;
      return _regeneratorRuntime().wrap(function _callee4$(_context4) {
        while (1) switch (_context4.prev = _context4.next) {
          case 0:
            loadCode = getState().configurator.loadCode;
            if (loadCode) {
              _context4.next = 3;
              break;
            }
            throw new Error((0, _i18n.t)('loadConfiguration.error.emptyCode'));
          case 3:
            dispatch((0, _Actions2.dismissError)());
            dispatch((0, _Actions2.setWorkInProgress)('loadConfiguration', true));
            _context4.prev = 5;
            _context4.next = 8;
            return dispatch(fetchConfigurationByCodeAsync(loadCode));
          case 8:
            action = _context4.sent;
            dispatch((0, _Actions2.setVisible)('loadConfiguration', false));
            return _context4.abrupt("return", action);
          case 13:
            _context4.prev = 13;
            _context4.t0 = _context4["catch"](5);
            dispatch((0, _Actions2.dismissError)()); // ignore original REQUEST_ERROR, should be handled by the caller
            throw new Error((0, _i18n.t)('loadConfiguration.error.loadingFailed'));
          case 17:
            _context4.prev = 17;
            dispatch((0, _Actions2.setWorkInProgress)('loadConfiguration', false));
            return _context4.finish(17);
          case 20:
          case "end":
            return _context4.stop();
        }
      }, _callee4, null, [[5, 13, 17, 20]]);
    }));
    return function (_x6, _x7) {
      return _ref6.apply(this, arguments);
    };
  }();
};
var receiveDesignerData = exports.receiveDesignerData = function receiveDesignerData(data) {
  return (0, _createActionWithGlobalState.createActionWithGlobalState)({
    type: RECEIVE_DESIGNER_DATA,
    data: data,
    receivedAt: Date.now()
  });
};
var loadDesignerData = exports.loadDesignerData = function loadDesignerData(configuration) {
  return /*#__PURE__*/function () {
    var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(dispatch) {
      return _regeneratorRuntime().wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            if (!(!configuration || !configuration.item || !configuration.item.identifier)) {
              _context5.next = 2;
              break;
            }
            return _context5.abrupt("return", dispatch((0, _Actions2.reportError)((0, _i18n.t)('loadConfigurationModes.error.missingItemIdentifier'))));
          case 2:
            dispatch((0, _Actions2.dismissError)());
            dispatch((0, _Actions2.setWorkInProgress)('loadConfigurationModes', true));
            _context5.prev = 4;
            _context5.next = 7;
            return dispatch(apiActions.postDataAsync('/configurationmodes/designer/getdata', {
              configuration: configuration
            }, receiveDesignerData));
          case 7:
            return _context5.abrupt("return", _context5.sent);
          case 10:
            _context5.prev = 10;
            _context5.t0 = _context5["catch"](4);
            return _context5.abrupt("return", dispatch((0, _Actions2.reportError)((0, _i18n.t)('loadConfigurationModes.error.loadingFailed'))));
          case 13:
            _context5.prev = 13;
            dispatch((0, _Actions2.setWorkInProgress)('loadConfigurationModes', false));
            return _context5.finish(13);
          case 16:
          case "end":
            return _context5.stop();
        }
      }, _callee5, null, [[4, 10, 13, 16]]);
    }));
    return function (_x8) {
      return _ref7.apply(this, arguments);
    };
  }();
};
var setSelectedAmount = exports.setSelectedAmount = function setSelectedAmount(identifier, amount) {
  var isUpdatedByUser = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  return {
    type: SET_SELECTED_AMOUNT,
    identifier: identifier,
    amount: amount,
    isUpdatedByUser: isUpdatedByUser
  };
};
var saveBulkNames = exports.saveBulkNames = function saveBulkNames(identifier, bulkNamesData) {
  return {
    type: SAVE_BULKNAMES,
    identifier: identifier,
    bulkNamesData: bulkNamesData
  };
};
var clearBulkNames = exports.clearBulkNames = function clearBulkNames() {
  return {
    type: CLEAR_BULKNAMES
  };
};
var deleteSelectedAmount = exports.deleteSelectedAmount = function deleteSelectedAmount(identifier) {
  return {
    type: DELETE_SELECTED_AMOUNT,
    identifier: identifier
  };
};
var setSelectedAmounts = exports.setSelectedAmounts = function setSelectedAmounts(variant, sizes, isUpdatedByUser) {
  return {
    type: SET_SELECTED_AMOUNTS,
    variant: variant,
    sizes: sizes,
    isUpdatedByUser: isUpdatedByUser
  };
};
var deleteSelectedAmounts = exports.deleteSelectedAmounts = function deleteSelectedAmounts(variant, sizes) {
  return {
    type: DELETE_SELECTED_AMOUNTS,
    variant: variant,
    sizes: sizes
  };
};
var setComment = exports.setComment = function setComment(comment) {
  return {
    type: SET_COMMENT,
    comment: comment
  };
};
var switchSelectedAmount = exports.switchSelectedAmount = function switchSelectedAmount(srcIdentifier, dstIdentifier) {
  return {
    type: SWITCH_SELECTED_AMOUNT,
    srcIdentifier: srcIdentifier,
    dstIdentifier: dstIdentifier
  };
};
var setSelectedCalculation = exports.setSelectedCalculation = function setSelectedCalculation(identifier, value) {
  return {
    type: SET_SELECTED_CALCULATION,
    identifier: identifier,
    value: value
  };
};
var setOptionInputText = exports.setOptionInputText = function setOptionInputText(identifier, value) {
  return {
    type: SET_OPTION_INPUT_TEXT,
    identifier: identifier,
    value: value
  };
};
var resetOptionInputTexts = exports.resetOptionInputTexts = function resetOptionInputTexts() {
  return {
    type: RESET_OPTION_INPUT_TEXTS
  };
};