"use strict";

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); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _configuration = require("../configuration");
var _ServiceLocator = require("../ServiceLocator");
var _AbstractInteractionService = _interopRequireDefault(require("../../Framework/Services/AbstractInteractionService"));
var _Api = _interopRequireDefault(require("../../Framework/Api"));
var _i18n = require("../../Framework/i18n");
var _Selectors = require("../Reducers/Configurator/Selectors");
var _Constant = require("../Constant");
var _createMessageInterface = require("../Utils/createMessageInterface");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _regeneratorRuntime() { "use strict"; var r = _regenerator(), e = r.m(_regeneratorRuntime), t = (Object.getPrototypeOf ? Object.getPrototypeOf(e) : e.__proto__).constructor; function n(r) { var e = "function" == typeof r && r.constructor; return !!e && (e === t || "GeneratorFunction" === (e.displayName || e.name)); } var o = { "throw": 1, "return": 2, "break": 3, "continue": 3 }; function a(r) { var e, t; return function (n) { e || (e = { stop: function stop() { return t(n.a, 2); }, "catch": function _catch() { return n.v; }, abrupt: function abrupt(r, e) { return t(n.a, o[r], e); }, delegateYield: function delegateYield(r, o, a) { return e.resultName = o, t(n.d, _regeneratorValues(r), a); }, finish: function finish(r) { return t(n.f, r); } }, t = function t(r, _t, o) { n.p = e.prev, n.n = e.next; try { return r(_t, o); } finally { e.next = n.n; } }), e.resultName && (e[e.resultName] = n.v, e.resultName = void 0), e.sent = n.v, e.next = n.n; try { return r.call(this, e); } finally { n.p = e.prev, n.n = e.next; } }; } return (_regeneratorRuntime = function _regeneratorRuntime() { return { wrap: function wrap(e, t, n, o) { return r.w(a(e), t, n, o && o.reverse()); }, isGeneratorFunction: n, mark: r.m, awrap: function awrap(r, e) { return new _OverloadYield(r, e); }, AsyncIterator: _regeneratorAsyncIterator, async: function async(r, e, t, o, u) { return (n(e) ? _regeneratorAsyncGen : _regeneratorAsync)(a(r), e, t, o, u); }, keys: _regeneratorKeys, values: _regeneratorValues }; })(); }
function _regeneratorValues(e) { if (null != e) { var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"], r = 0; if (t) return t.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) return { next: function next() { return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e }; } }; } throw new TypeError(_typeof(e) + " is not iterable"); }
function _regeneratorKeys(e) { var n = Object(e), r = []; for (var t in n) r.unshift(t); return function e() { for (; r.length;) if ((t = r.pop()) in n) return e.value = t, e.done = !1, e; return e.done = !0, e; }; }
function _regeneratorAsync(n, e, r, t, o) { var a = _regeneratorAsyncGen(n, e, r, t, o); return a.next().then(function (n) { return n.done ? n.value : a.next(); }); }
function _regeneratorAsyncGen(r, e, t, o, n) { return new _regeneratorAsyncIterator(_regenerator().w(r, e, t, o), n || Promise); }
function _regeneratorAsyncIterator(t, e) { function n(r, o, i, f) { try { var c = t[r](o), u = c.value; return u instanceof _OverloadYield ? e.resolve(u.v).then(function (t) { n("next", t, i, f); }, function (t) { n("throw", t, i, f); }) : e.resolve(u).then(function (t) { c.value = t, i(c); }, function (t) { return n("throw", t, i, f); }); } catch (t) { f(t); } } var r; this.next || (_regeneratorDefine2(_regeneratorAsyncIterator.prototype), _regeneratorDefine2(_regeneratorAsyncIterator.prototype, "function" == typeof Symbol && Symbol.asyncIterator || "@asyncIterator", function () { return this; })), _regeneratorDefine2(this, "_invoke", function (t, o, i) { function f() { return new e(function (e, r) { n(t, i, e, r); }); } return r = r ? r.then(f, f) : f(); }, !0); }
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
function _OverloadYield(e, d) { this.v = e, this.k = d; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
function 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 _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _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 _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
var InteractionService = exports["default"] = /*#__PURE__*/function (_AbstractInteractionS) {
  _inherits(InteractionService, _AbstractInteractionS);
  var _super = _createSuper(InteractionService);
  function InteractionService() {
    _classCallCheck(this, InteractionService);
    return _super.call(this);
  }
  _createClass(InteractionService, [{
    key: "init",
    value: function init() {
      _ServiceLocator.Services.store.observeStore(function (state) {
        return state.i18n.locale;
      }, function (language) {
        _ServiceLocator.Services.interaction.doLanguageSwitch(language);
      });
    }
  }, {
    key: "postMessageToContainer",
    value: function postMessageToContainer(data, options) {
      var conf = _objectSpread({
        targetOrigin: '*'
      }, options);
      var wnd = conf.window || window;
      if (wnd.parent.postMessage !== undefined) {
        var targetOrigin = conf.targetOrigin;
        wnd.parent.postMessage(data, targetOrigin);
      }
    }
  }, {
    key: "saveConfiguration",
    value: function () {
      var _saveConfiguration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
        var ui, configurator, code;
        return _regeneratorRuntime().wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              ui = _ServiceLocator.Services.ui, configurator = _ServiceLocator.Services.configurator;
              ui.dismissError();
              ui.beginWork('saveConfiguration');
              ui.hide('optionlist');
              ui.show('saveConfiguration');
              _context.prev = 5;
              _context.next = 8;
              return configurator.captureAndSaveConfiguration(_configuration.SaveTypes.USER);
            case 8:
              code = configurator.state.configuration.code;
              this.postMessageToContainer({
                method: _createMessageInterface.METHOD_CONFIGURATION_SAVED,
                code: code
              });
              _context.next = 16;
              break;
            case 12:
              _context.prev = 12;
              _context.t0 = _context["catch"](5);
              // eslint-disable-next-line no-console
              console.error(_context.t0);
              ui.reportError((0, _i18n.t)('saveConfiguration.error.savingFailed'));
            case 16:
              _context.prev = 16;
              ui.endWork('saveConfiguration');
              return _context.finish(16);
            case 19:
            case "end":
              return _context.stop();
          }
        }, _callee, this, [[5, 12, 16, 19]]);
      }));
      function saveConfiguration() {
        return _saveConfiguration.apply(this, arguments);
      }
      return saveConfiguration;
    }()
  }, {
    key: "shareConfiguration",
    value: function () {
      var _shareConfiguration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
        var ui, configurator;
        return _regeneratorRuntime().wrap(function _callee2$(_context2) {
          while (1) switch (_context2.prev = _context2.next) {
            case 0:
              ui = _ServiceLocator.Services.ui, configurator = _ServiceLocator.Services.configurator;
              ui.dismissError();
              ui.beginWork('shareConfiguration');
              ui.hide('optionlist');
              ui.show('shareConfiguration');
              _context2.prev = 5;
              _context2.next = 8;
              return configurator.captureAndSaveConfiguration(_configuration.SaveTypes.SHARE);
            case 8:
              _context2.next = 14;
              break;
            case 10:
              _context2.prev = 10;
              _context2.t0 = _context2["catch"](5);
              // eslint-disable-next-line no-console
              console.error(_context2.t0);
              ui.reportError((0, _i18n.t)('shareConfiguration.error.savingFailed'));
            case 14:
              _context2.prev = 14;
              ui.endWork('shareConfiguration');
              return _context2.finish(14);
            case 17:
            case "end":
              return _context2.stop();
          }
        }, _callee2, null, [[5, 10, 14, 17]]);
      }));
      function shareConfiguration() {
        return _shareConfiguration.apply(this, arguments);
      }
      return shareConfiguration;
    }()
  }, {
    key: "mailConfiguration",
    value: function () {
      var _mailConfiguration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
        var ui, configurator;
        return _regeneratorRuntime().wrap(function _callee3$(_context3) {
          while (1) switch (_context3.prev = _context3.next) {
            case 0:
              ui = _ServiceLocator.Services.ui, configurator = _ServiceLocator.Services.configurator;
              ui.dismissError();
              ui.beginWork('mailConfiguration');
              ui.hide('optionlist');
              ui.show('mailConfiguration');
              ui.show('globalLoader');
              _context3.prev = 6;
              _context3.next = 9;
              return configurator.captureAndSaveConfiguration(_configuration.SaveTypes.MAIL);
            case 9:
              _context3.next = 15;
              break;
            case 11:
              _context3.prev = 11;
              _context3.t0 = _context3["catch"](6);
              // eslint-disable-next-line no-console
              console.error(_context3.t0);
              ui.reportError((0, _i18n.t)('mailConfiguration.error.savingFailed'));
            case 15:
              _context3.prev = 15;
              ui.hide('globalLoader');
              ui.endWork('mailConfiguration');
              return _context3.finish(15);
            case 19:
            case "end":
              return _context3.stop();
          }
        }, _callee3, null, [[6, 11, 15, 19]]);
      }));
      function mailConfiguration() {
        return _mailConfiguration.apply(this, arguments);
      }
      return mailConfiguration;
    }()
  }, {
    key: "printConfiguration",
    value: function () {
      var _printConfiguration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
        var ui, configurator;
        return _regeneratorRuntime().wrap(function _callee4$(_context4) {
          while (1) switch (_context4.prev = _context4.next) {
            case 0:
              ui = _ServiceLocator.Services.ui, configurator = _ServiceLocator.Services.configurator;
              ui.dismissError();
              ui.beginWork('printConfiguration');
              ui.hide('optionlist');
              ui.show('printConfiguration');
              ui.show('globalLoader');
              _context4.prev = 6;
              _context4.next = 9;
              return configurator.captureAndSaveConfiguration(_configuration.SaveTypes.PRINT);
            case 9:
              _context4.next = 15;
              break;
            case 11:
              _context4.prev = 11;
              _context4.t0 = _context4["catch"](6);
              // eslint-disable-next-line no-console
              console.error(_context4.t0);
              ui.reportError((0, _i18n.t)('printConfiguration.error.savingFailed'));
            case 15:
              _context4.prev = 15;
              ui.endWork('printConfiguration');
              ui.hide('globalLoader');
              return _context4.finish(15);
            case 19:
            case "end":
              return _context4.stop();
          }
        }, _callee4, null, [[6, 11, 15, 19]]);
      }));
      function printConfiguration() {
        return _printConfiguration.apply(this, arguments);
      }
      return printConfiguration;
    }()
  }, {
    key: "loadConfiguration",
    value: function loadConfiguration() {
      var clearLoadCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
      if (clearLoadCode) {
        _ServiceLocator.Services.configurator.setLoadCode();
      }
      _ServiceLocator.Services.ui.dismissError();
      _ServiceLocator.Services.ui.show('loadConfiguration');
    }
  }, {
    key: "adminSaveConfiguration",
    value: function () {
      var _adminSaveConfiguration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(saveType) {
        var ui, configurator, configuration;
        return _regeneratorRuntime().wrap(function _callee5$(_context5) {
          while (1) switch (_context5.prev = _context5.next) {
            case 0:
              ui = _ServiceLocator.Services.ui, configurator = _ServiceLocator.Services.configurator;
              ui.dismissError();
              ui.beginWork('adminSaveConfiguration');
              ui.hide('optionlist');
              _context5.prev = 4;
              configuration = configurator.prepareConfigurationForSave(true);
              _context5.next = 8;
              return configurator.createMediaDataForConfiguration(configuration);
            case 8:
              return _context5.abrupt("return", _ServiceLocator.Services.adminArea.saveConfiguration(configuration, saveType));
            case 11:
              _context5.prev = 11;
              _context5.t0 = _context5["catch"](4);
              // eslint-disable-next-line no-console
              console.error(_context5.t0);
              ui.reportError((0, _i18n.t)('saveConfiguration.error.savingFailed'));
            case 15:
              _context5.prev = 15;
              ui.endWork('adminSaveConfiguration');
              return _context5.finish(15);
            case 18:
            case "end":
              return _context5.stop();
          }
        }, _callee5, null, [[4, 11, 15, 18]]);
      }));
      function adminSaveConfiguration(_x) {
        return _adminSaveConfiguration.apply(this, arguments);
      }
      return adminSaveConfiguration;
    }()
  }, {
    key: "adminGetConfiguration",
    value: function () {
      var _adminGetConfiguration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
        var ui, configurator, work, configuration;
        return _regeneratorRuntime().wrap(function _callee6$(_context6) {
          while (1) switch (_context6.prev = _context6.next) {
            case 0:
              ui = _ServiceLocator.Services.ui, configurator = _ServiceLocator.Services.configurator;
              work = ui.beginWork('adminGetConfiguration');
              ui.dismissError();
              ui.hide('optionlist');
              _context6.prev = 4;
              configuration = configurator.prepareConfigurationForSave(true);
              _context6.next = 8;
              return configurator.createMediaDataForConfiguration(configuration);
            case 8:
              return _context6.abrupt("return", configuration);
            case 11:
              _context6.prev = 11;
              _context6.t0 = _context6["catch"](4);
              // eslint-disable-next-line no-console
              console.error(_context6.t0);
              ui.reportError((0, _i18n.t)('saveConfiguration.error.savingFailed'));
            case 15:
              _context6.prev = 15;
              work.done();
              return _context6.finish(15);
            case 18:
            case "end":
              return _context6.stop();
          }
        }, _callee6, null, [[4, 11, 15, 18]]);
      }));
      function adminGetConfiguration() {
        return _adminGetConfiguration.apply(this, arguments);
      }
      return adminGetConfiguration;
    }()
  }, {
    key: "addToCart",
    value: function () {
      var _addToCart = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
        var ui, configurator, overwriteConfiguration, extraData, result;
        return _regeneratorRuntime().wrap(function _callee7$(_context7) {
          while (1) switch (_context7.prev = _context7.next) {
            case 0:
              ui = _ServiceLocator.Services.ui, configurator = _ServiceLocator.Services.configurator;
              ui.dismissError();
              ui.beginWork('addToCart');
              ui.hide('optionlist');
              ui.show('addToCartPopUpLoader');
              _context7.prev = 5;
              overwriteConfiguration = (0, _configuration.getConf)('fromBasket', false);
              extraData = overwriteConfiguration ? {
                code: _ServiceLocator.Services.configurator.state.configuration.code
              } : {};
              _context7.next = 10;
              return configurator.captureAndSaveConfiguration(_configuration.SaveTypes.CART, extraData);
            case 10:
              result = _context7.sent;
              _ServiceLocator.Services.configurator.addToCartCallback(result.data);
              _context7.next = 19;
              break;
            case 14:
              _context7.prev = 14;
              _context7.t0 = _context7["catch"](5);
              // eslint-disable-next-line no-console
              console.error(_context7.t0);
              ui.reportError((0, _i18n.t)('saveConfiguration.error.savingFailed'));
              throw _context7.t0;
            case 19:
              _context7.prev = 19;
              ui.endWork('addToCart');
              ui.hide('addToCartPopUpLoader');
              return _context7.finish(19);
            case 23:
            case "end":
              return _context7.stop();
          }
        }, _callee7, null, [[5, 14, 19, 23]]);
      }));
      function addToCart() {
        return _addToCart.apply(this, arguments);
      }
      return addToCart;
    }()
  }, {
    key: "sendReceiveOfferRequest",
    value: function () {
      var _sendReceiveOfferRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(formData) {
        var configuration, data;
        return _regeneratorRuntime().wrap(function _callee8$(_context8) {
          while (1) switch (_context8.prev = _context8.next) {
            case 0:
              if (!formData.hasError) {
                _context8.next = 2;
                break;
              }
              return _context8.abrupt("return", false);
            case 2:
              _context8.prev = 2;
              _ServiceLocator.Services.ui.show('addToCartPopUpLoader');
              _context8.next = 6;
              return _ServiceLocator.Services.configurator.captureAndSaveConfiguration(_configuration.SaveTypes.OFFERREQUEST);
            case 6:
              _ServiceLocator.Services.analytics.triggerEvent(_Constant.EventTypes.selected_amounts);
              _context8.next = 13;
              break;
            case 9:
              _context8.prev = 9;
              _context8.t0 = _context8["catch"](2);
              _ServiceLocator.Services.ui.reportError((0, _i18n.t)('receiveOfferForm.sentError'));
              return _context8.abrupt("return", false);
            case 13:
              _context8.prev = 13;
              _ServiceLocator.Services.ui.hide('addToCartPopUpLoader');
              return _context8.finish(13);
            case 16:
              configuration = _ServiceLocator.Services.configurator.state.configuration;
              data = {
                configurationCode: configuration.code,
                emailAddress: formData.email,
                name: formData.name,
                company: formData.company,
                phoneNumber: formData.phonenumber,
                street: formData.street,
                zip: formData.zip,
                city: formData.city,
                country: formData.country
              };
              _context8.prev = 18;
              _context8.next = 21;
              return _Api["default"].request({
                url: 'receiveoffers/request',
                method: 'post',
                data: data
              });
            case 21:
              this.postMessageToContainer({
                method: _createMessageInterface.METHOD_REQUEST_OFFER_FORM_SENT,
                code: configuration.code
              });
              _context8.next = 28;
              break;
            case 24:
              _context8.prev = 24;
              _context8.t1 = _context8["catch"](18);
              _ServiceLocator.Services.ui.reportError((0, _i18n.t)('receiveOfferForm.sentError'));
              return _context8.abrupt("return", false);
            case 28:
              _ServiceLocator.Services.ui.reportError((0, _i18n.t)('receiveOfferForm.sentOk'));
              return _context8.abrupt("return", true);
            case 30:
            case "end":
              return _context8.stop();
          }
        }, _callee8, this, [[2, 9, 13, 16], [18, 24]]);
      }));
      function sendReceiveOfferRequest(_x2) {
        return _sendReceiveOfferRequest.apply(this, arguments);
      }
      return sendReceiveOfferRequest;
    }()
  }, {
    key: "doLanguageSwitch",
    value: function doLanguageSwitch(language) {
      if (_Api["default"].setLanguage(language) === 1) {
        // if newly set, save and load the configuration
        return _ServiceLocator.Services.configurator.saveAndReloadConfiguration(_configuration.SaveTypes.LANGUAGESWITCH);
      }
    }
  }, {
    key: "setChannel",
    value: function setChannel(channel) {
      if (_Api["default"].setChannel(channel) === 1) {
        // if newly set, save and load the configuration
        if ((0, _configuration.getConf)('setChannelReloadOnly')) {
          return _ServiceLocator.Services.configurator.loadInitialConfiguration();
        } else {
          return _ServiceLocator.Services.configurator.saveAndReloadConfiguration(_configuration.SaveTypes.CHANNELSWITCH);
        }
      }
    }
  }, {
    key: "saveWidgetConfiguration",
    value: function () {
      var _saveWidgetConfiguration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
        var ui, configurator;
        return _regeneratorRuntime().wrap(function _callee9$(_context9) {
          while (1) switch (_context9.prev = _context9.next) {
            case 0:
              ui = _ServiceLocator.Services.ui, configurator = _ServiceLocator.Services.configurator;
              ui.dismissError();
              ui.beginWork('saveConfiguration');
              _context9.prev = 3;
              _context9.next = 6;
              return configurator.prepareAndSaveConfiguration(_configuration.SaveTypes.WIDGET);
            case 6:
              _context9.next = 12;
              break;
            case 8:
              _context9.prev = 8;
              _context9.t0 = _context9["catch"](3);
              // eslint-disable-next-line no-console
              console.error(_context9.t0);
              ui.reportError((0, _i18n.t)('saveConfiguration.error.savingFailed'));
            case 12:
              _context9.prev = 12;
              ui.endWork('saveConfiguration');
              return _context9.finish(12);
            case 15:
            case "end":
              return _context9.stop();
          }
        }, _callee9, null, [[3, 8, 12, 15]]);
      }));
      function saveWidgetConfiguration() {
        return _saveWidgetConfiguration.apply(this, arguments);
      }
      return saveWidgetConfiguration;
    }()
  }, {
    key: "openConfigurator",
    value: function openConfigurator() {
      var configuration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _Selectors.getConfiguration)(_ServiceLocator.Services.configurator.state);
      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      var conf = _objectSpread(_objectSpread({
        targetOrigin: '*'
      }, (0, _configuration.getConf)('openConfigurator') || {}), options);
      var code = configuration.code;
      var wnd = conf.window || window;
      switch (conf.method) {
        case _configuration.WidgetAfterSaveMethods.PostMessage:
          {
            if (wnd.parent.postMessage !== undefined) {
              var targetOrigin = conf.targetOrigin;
              wnd.parent.postMessage({
                method: 'openConfigurator',
                code: code
              }, targetOrigin);
            }
            break;
          }
        case _configuration.WidgetAfterSaveMethods.OpenNewWindow:
          {
            wnd.open("/code:".concat(code).concat(wnd.location.search));
            break;
          }
      }
    }
  }, {
    key: "createPdfUrl",
    value: function () {
      var _createPdfUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee0() {
        var documentType,
          configuration,
          queryParams,
          params,
          customKeys,
          keys,
          mergedKeys,
          query,
          queryString,
          _args0 = arguments;
        return _regeneratorRuntime().wrap(function _callee0$(_context0) {
          while (1) switch (_context0.prev = _context0.next) {
            case 0:
              documentType = _args0.length > 0 && _args0[0] !== undefined ? _args0[0] : 'user';
              configuration = _args0.length > 1 && _args0[1] !== undefined ? _args0[1] : (0, _Selectors.getConfiguration)(_ServiceLocator.Services.configurator.state);
              queryParams = _args0.length > 2 && _args0[2] !== undefined ? _args0[2] : {};
              params = _objectSpread(_objectSpread({}, _Api["default"].getGETParameters()), queryParams);
              customKeys = Object.keys(queryParams);
              keys = ['_language', '_client', '_channel', '_display_net_prices', '_share_url'];
              mergedKeys = keys.concat(customKeys);
              query = new URLSearchParams(location.search);
              queryString = Object.keys(params).filter(function (key) {
                return mergedKeys.indexOf(key) !== -1;
              }).map(function (key) {
                return key === '_share_url' ? key + '=' + encodeURIComponent(params[key]) : key + '=' + params[key];
              }).join('&');
              if (query.has('_hide_prices')) {
                queryString = queryString.concat('&_hide_prices=' + query.get('_hide_prices'));
              }
              if (query.has('_cta_element')) {
                queryString = queryString.concat('&_cta_element=' + query.get('_cta_element'));
              }
              return _context0.abrupt("return", "".concat((0, _configuration.getConf)('network.baseURL', '/'), "configurations/pdf/").concat(documentType, "/").concat(configuration.code, "?").concat(queryString));
            case 12:
            case "end":
              return _context0.stop();
          }
        }, _callee0);
      }));
      function createPdfUrl() {
        return _createPdfUrl.apply(this, arguments);
      }
      return createPdfUrl;
    }()
  }, {
    key: "printConfigurationAndOpenPdf",
    value: function () {
      var _printConfigurationAndOpenPdf = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee1() {
        return _regeneratorRuntime().wrap(function _callee1$(_context1) {
          while (1) switch (_context1.prev = _context1.next) {
            case 0:
              _context1.next = 2;
              return this.printConfiguration();
            case 2:
              _ServiceLocator.Services.interaction.showPdfDownloadDialog();
            case 3:
            case "end":
              return _context1.stop();
          }
        }, _callee1, this);
      }));
      function printConfigurationAndOpenPdf() {
        return _printConfigurationAndOpenPdf.apply(this, arguments);
      }
      return printConfigurationAndOpenPdf;
    }()
  }, {
    key: "saveWidgetConfigurationAndOpenPdf",
    value: function () {
      var _saveWidgetConfigurationAndOpenPdf = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
        var pdfUrl;
        return _regeneratorRuntime().wrap(function _callee10$(_context10) {
          while (1) switch (_context10.prev = _context10.next) {
            case 0:
              _context10.next = 2;
              return this.saveWidgetConfiguration();
            case 2:
              _context10.next = 4;
              return this.createPdfUrl('widget');
            case 4:
              pdfUrl = _context10.sent;
              window.open(pdfUrl);
            case 6:
            case "end":
              return _context10.stop();
          }
        }, _callee10, this);
      }));
      function saveWidgetConfigurationAndOpenPdf() {
        return _saveWidgetConfigurationAndOpenPdf.apply(this, arguments);
      }
      return saveWidgetConfigurationAndOpenPdf;
    }()
  }, {
    key: "saveWidgetConfigurationAndOpenConfigurator",
    value: function () {
      var _saveWidgetConfigurationAndOpenConfigurator = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
        return _regeneratorRuntime().wrap(function _callee11$(_context11) {
          while (1) switch (_context11.prev = _context11.next) {
            case 0:
              _context11.next = 2;
              return this.saveWidgetConfiguration();
            case 2:
              this.openConfigurator();
            case 3:
            case "end":
              return _context11.stop();
          }
        }, _callee11, this);
      }));
      function saveWidgetConfigurationAndOpenConfigurator() {
        return _saveWidgetConfigurationAndOpenConfigurator.apply(this, arguments);
      }
      return saveWidgetConfigurationAndOpenConfigurator;
    }()
  }, {
    key: "showLoadConfigurationDialog",
    value: function showLoadConfigurationDialog() {
      _ServiceLocator.Services.ui.show('loadConfiguration');
    }
  }, {
    key: "showSendEmailDialog",
    value: function showSendEmailDialog() {
      _ServiceLocator.Services.ui.show('sendEmail');
    }
  }, {
    key: "showPdfDownloadDialog",
    value: function showPdfDownloadDialog() {
      _ServiceLocator.Services.ui.show('pdfDownload');
    }
  }]);
  return InteractionService;
}(_AbstractInteractionService["default"]);