"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.CreatorScreen = CreatorScreen;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _ReactComponent = _interopRequireDefault(require("../../../Shared/PropTypes/ReactComponent"));
var _DefaultLayout = _interopRequireDefault(require("./Layouts/DefaultLayout"));
var _Header = _interopRequireDefault(require("../../Shared/Containers/Header"));
var _CreatorAlignTarget = require("../Visualization/CreatorAlignTarget");
var _ServiceLocator = require("../../ServiceLocator");
var configuratorActions = _interopRequireWildcard(require("../../Reducers/Configurator/Actions"));
var _AmountPrice = _interopRequireDefault(require("./Containers/AmountPrice"));
var _ConfigurationvariantSelection = _interopRequireDefault(require("./Containers/ConfigurationvariantSelection"));
var _CustomTitleEditor = _interopRequireDefault(require("./Containers/CustomTitleEditor"));
var _Incompatibility = _interopRequireDefault(require("./Containers/Incompatibility"));
var _Error = _interopRequireDefault(require("../../Shared/Containers/Error"));
var _FastConfiguration = _interopRequireDefault(require("./Containers/FastConfiguration"));
var _Optiondetail = _interopRequireDefault(require("./Containers/Optiondetail"));
var _OptionsList = _interopRequireDefault(require("./Containers/OptionsList"));
var _ProductPartsList = _interopRequireDefault(require("./Containers/ProductPartsList"));
var _InvalidConfigurationNotice = _interopRequireDefault(require("../../Shared/Containers/InvalidConfigurationNotice"));
var _FullScreenView = _interopRequireDefault(require("./Components/FullScreenView/FullScreenView"));
var _Option = _interopRequireDefault(require("./Components/Option"));
var _excluded = ["renderAmountPrice"];
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 _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); 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 _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
function CreatorScreen(props) {
  var imageOnly = props.imageOnly,
    fallbackMode = props.fallbackMode,
    isPortraitMode = props.isPortraitMode,
    showAddToCartButton = props.showAddToCartButton,
    showConfigurationVariantSelection = props.showConfigurationVariantSelection,
    vertical = props.vertical,
    fullScreenViewProps = props.fullScreenViewProps,
    configuration = props.configuration,
    _renderAmountPrice = props._renderAmountPrice,
    _onToggleOptionList = props._onToggleOptionList,
    renderConfigurationVariantSelection = props.renderConfigurationVariantSelection,
    renderCustomScreenComponents = props.renderCustomScreenComponents,
    renderCustomTitleEditorContainer = props.renderCustomTitleEditorContainer,
    renderErrorContainer = props.renderErrorContainer,
    renderFastConfigurationContainer = props.renderFastConfigurationContainer,
    renderHeader = props.renderHeader,
    renderIncompatibilityDialog = props.renderIncompatibilityDialog,
    renderInspirationsList = props.renderInspirationsList,
    renderLoadConfiguration = props.renderLoadConfiguration,
    renderLoader = props.renderLoader,
    renderOptionDetailContainer = props.renderOptionDetailContainer,
    renderOptionsList = props.renderOptionsList,
    renderPdfDownload = props.renderPdfDownload,
    renderProductParts = props.renderProductParts,
    renderSaveConfiguration = props.renderSaveConfiguration,
    renderSendEmail = props.renderSendEmail,
    _renderVisualization = props.renderVisualization,
    renderLicenseNotice = props.renderLicenseNotice,
    renderInvalidConfigurationNotice = props.renderInvalidConfigurationNotice,
    dispatchAction = props.dispatchAction,
    onOptionClassificationSelect = props.onOptionClassificationSelect,
    onToggleOptionList = props.onToggleOptionList,
    resolveConflicts = props.resolveConflicts,
    selectOption = props.selectOption,
    selectOptionClassification = props.selectOptionClassification,
    setVisible = props.setVisible,
    viewOptionDetails = props.viewOptionDetails,
    Layout = props.Layout,
    OptionsListContainer = props.OptionsListContainer;
  (0, _react.useEffect)(function () {
    setVisible('optionclassificationList', true);
    setVisible('addToCartButton', configuration.showAddToCartButton);
    if (!configuration.showInitialOptionClassification && configuration.showStartHere) {
      setVisible('startHere', true);
    }
  }, [configuration.showAddToCartButton, configuration.showInitialOptionClassification, configuration.showStartHere, setVisible]);
  return /*#__PURE__*/_react["default"].createElement(Layout, {
    imageOnly: imageOnly,
    displayVerticalList: vertical,
    fallbackMode: fallbackMode,
    isPortraitMode: isPortraitMode,
    renderHeader: renderHeader,
    renderInForeground: function renderInForeground() {
      return renderConfigurationVariantSelection(showConfigurationVariantSelection);
    },
    renderLoader: renderLoader,
    renderMain: function renderMain() {
      return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, !fallbackMode && /*#__PURE__*/_react["default"].createElement(_CreatorAlignTarget.CreatorAlignTarget, null), renderSaveConfiguration(), renderSendEmail(), renderPdfDownload(), renderLoadConfiguration(), configuration.editCustomTitle ? renderCustomTitleEditorContainer() : null, renderCustomScreenComponents(), renderErrorContainer(), renderFastConfigurationContainer(dispatchAction, onOptionClassificationSelect, selectOption, selectOptionClassification), renderInspirationsList(), renderOptionsList(selectOption, dispatchAction, viewOptionDetails, _onToggleOptionList, onToggleOptionList, OptionsListContainer), renderOptionDetailContainer(selectOption, dispatchAction, viewOptionDetails), renderIncompatibilityDialog(viewOptionDetails, resolveConflicts, dispatchAction));
    },
    renderProductsList: function renderProductsList() {
      return renderProductParts(dispatchAction, onOptionClassificationSelect, selectOptionClassification);
    },
    renderShoppingCart: function renderShoppingCart() {
      return showAddToCartButton ? _renderAmountPrice(props) : null;
    },
    renderVisualization: function renderVisualization() {
      return _renderVisualization({
        fullScreenViewProps: {
          showPreviewButton: !!fullScreenViewProps.showPreviewButton,
          Component: _FullScreenView["default"]
        }
      });
    },
    renderLicenseNotice: renderLicenseNotice,
    renderInvalidConfigurationNotice: renderInvalidConfigurationNotice
  });
}
CreatorScreen.defaultProps = {
  fullScreenViewProps: {
    showPreviewButton: true
  },
  _renderAmountPrice: function _renderAmountPrice(_ref) {
    var renderAmountPrice = _ref.renderAmountPrice,
      props = _objectWithoutProperties(_ref, _excluded);
    return renderAmountPrice(_objectSpread({
      AmountPriceContainer: _AmountPrice["default"]
    }, props));
  },
  _onToggleOptionList: function _onToggleOptionList(onToggleOptionList) {
    return onToggleOptionList(_ServiceLocator.Services.configurator.state.selectedoptionclassification);
  },
  renderConfigurationVariantSelection: function renderConfigurationVariantSelection(showConfigurationVariantSelection) {
    if (showConfigurationVariantSelection) {
      return /*#__PURE__*/_react["default"].createElement(_ConfigurationvariantSelection["default"], null);
    }
    return null;
  },
  renderCustomScreenComponents: function renderCustomScreenComponents() {
    return null;
  },
  renderCustomTitleEditorContainer: function renderCustomTitleEditorContainer() {
    return /*#__PURE__*/_react["default"].createElement(_CustomTitleEditor["default"], null);
  },
  renderErrorContainer: function renderErrorContainer() {
    return /*#__PURE__*/_react["default"].createElement(_Error["default"], null);
  },
  renderFastConfigurationContainer: function renderFastConfigurationContainer(dispatchAction, onOptionClassificationSelect, selectOption, selectOptionClassification) {
    return /*#__PURE__*/_react["default"].createElement(_FastConfiguration["default"], {
      onOptionclassificationSelect: function onOptionclassificationSelect(optionClassification, showOptionList) {
        return onOptionClassificationSelect(dispatchAction, optionClassification, selectOptionClassification, showOptionList);
      },
      onOptionSelect: function onOptionSelect(option) {
        return selectOption(dispatchAction, option);
      }
    });
  },
  renderHeader: function renderHeader() {
    return /*#__PURE__*/_react["default"].createElement(_Header["default"], null);
  },
  renderIncompatibilityDialog: function renderIncompatibilityDialog(viewOptionDetails, _resolveConflicts, dispatchAction) {
    return /*#__PURE__*/_react["default"].createElement(_Incompatibility["default"], {
      ruleComponentProps: {
        Optionlistitem: _Option["default"],
        viewDetails: viewOptionDetails
      },
      resolveConflicts: function resolveConflicts() {
        return _resolveConflicts(dispatchAction);
      }
    });
  },
  renderInspirationsList: function renderInspirationsList() {
    return null;
  },
  renderOptionDetailContainer: function renderOptionDetailContainer(selectOption, dispatchAction, viewOptionDetails) {
    return /*#__PURE__*/_react["default"].createElement(_Optiondetail["default"], {
      onSelect: function onSelect(option) {
        return selectOption(dispatchAction, option);
      },
      viewDetails: function viewDetails(option) {
        return viewOptionDetails(dispatchAction, option);
      }
    });
  },
  renderOptionsList: function renderOptionsList(selectOption, dispatchAction, viewOptionDetails, _onToggle, onToggleOptionList, OptionsListContainer) {
    return /*#__PURE__*/_react["default"].createElement(OptionsListContainer, {
      onSelect: function onSelect(option) {
        return selectOption(dispatchAction, option);
      },
      viewDetails: function viewDetails(option) {
        return viewOptionDetails(dispatchAction, option);
      },
      onToggle: function onToggle() {
        return _onToggle(onToggleOptionList);
      }
    });
  },
  renderProductParts: function renderProductParts(dispatchAction, onOptionClassificationSelect, selectOptionClassification) {
    return /*#__PURE__*/_react["default"].createElement(_ProductPartsList["default"], {
      onSelect: function onSelect(optionClassification) {
        return onOptionClassificationSelect(dispatchAction, optionClassification, selectOptionClassification);
      }
    });
  },
  renderInvalidConfigurationNotice: function renderInvalidConfigurationNotice() {
    return /*#__PURE__*/_react["default"].createElement(_InvalidConfigurationNotice["default"], null);
  },
  onOptionClassificationSelect: function onOptionClassificationSelect(dispatchAction, optionClassification, selectOptionClassification) {
    var showOptionList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
    return selectOptionClassification(dispatchAction, optionClassification, true, showOptionList);
  },
  resolveConflicts: function resolveConflicts(dispatchAction) {
    return dispatchAction(configuratorActions.resolveConflicts());
  },
  selectOption: function selectOption(dispatchAction, option) {
    var refreshOptionList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
    var showOptionDetails = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
    var optionClassification = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
    return dispatchAction(configuratorActions.selectOption(option, refreshOptionList, showOptionDetails, optionClassification));
  },
  selectOptionClassification: function selectOptionClassification(dispatchAction) {
    var optionClassification = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    var triggerFetchOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
    var showOptionList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
    return dispatchAction(configuratorActions.selectOptionclassification(optionClassification, triggerFetchOptions, showOptionList));
  },
  onToggleOptionList: function onToggleOptionList() {},
  viewOptionDetails: function viewOptionDetails(dispatchAction, option) {
    return dispatchAction(configuratorActions.viewOptionDetails(option));
  },
  Layout: _DefaultLayout["default"],
  OptionsListContainer: _OptionsList["default"]
};