"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.PreviewButton = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _clsx = _interopRequireDefault(require("clsx"));
var _styles = require("@material-ui/core/styles");
var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
var _Icon = _interopRequireDefault(require("@material-ui/core/Icon"));
var _Grid = _interopRequireDefault(require("@material-ui/core/Grid"));
var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
var _withWidth = _interopRequireWildcard(require("@material-ui/core/withWidth"));
var _i18n = require("../../../../../Framework/i18n");
var _AnalyticsWrapper = _interopRequireDefault(require("../../../../Shared/Components/Analytics/AnalyticsWrapper"));
var _customClassName = _interopRequireDefault(require("../../../../Utils/customClassName"));
var _Thumbnail = _interopRequireDefault(require("../../Containers/Thumbnail"));
var _PreviewPortal = _interopRequireDefault(require("../PreviewPortal"));
var _excluded = ["width", "areAllDesignAreasEmpty"];
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 _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 _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 _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
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 _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var styles = function styles(theme) {
  var _button, _thumbnailGrid, _buttonView;
  return {
    viewsContainer: {
      position: 'absolute',
      bottom: 0
    },
    fullScreenWrapper: {
      display: 'flex;',
      justifyContent: 'center'
    },
    button: (_button = {
      textTransform: 'none',
      left: 'calc(50%)',
      zIndex: 2,
      transform: 'translate(-50%, 0)',
      pointerEvents: 'all'
    }, _defineProperty(_button, theme.breakpoints.down('sm'), {
      zIndex: 5
    }), _defineProperty(_button, '@media (min-aspect-ratio: 13/9) and (min-height: 280px) and (max-width: 950px)', {
      display: 'none'
    }), _button),
    buttonBottom: {},
    buttonTop: {},
    buttonIcon: {
      paddingRight: 8,
      position: 'relative',
      top: -1
    },
    thumbnailGrid: (_thumbnailGrid = {}, _defineProperty(_thumbnailGrid, theme.breakpoints.between('xs', 'md'), {
      width: 'calc(100% - 360px)',
      // subtract with right toolbar width
      maxWidth: 'calc(100% - 360px)'
    }), _defineProperty(_thumbnailGrid, theme.breakpoints.up('md'), {
      position: 'absolute',
      bottom: 0,
      left: 'calc(50% - 175px)',
      // subtract half of the right sidebar width
      width: 453,
      // 2 x 24 (arrow width) + 425 (carousel width)
      transform: 'translateX(-50%)'
    }), _defineProperty(_thumbnailGrid, theme.breakpoints.down('xs'), {
      width: '100%',
      maxWidth: '100%',
      bottom: '-40px'
    }), _thumbnailGrid),
    buttonView: (_buttonView = {
      textTransform: 'none',
      bottom: 35,
      position: 'absolute',
      left: 'calc(50% - 200px)'
    }, _defineProperty(_buttonView, theme.breakpoints.down('xs'), {
      left: 'calc(50% - 75px)',
      bottom: 0,
      height: 56
    }), _defineProperty(_buttonView, '@media (min-aspect-ratio: 13/9) and (min-height: 280px) and (max-width: 950px)', {
      display: 'none'
    }), _buttonView)
  };
};
var PreviewButton = exports.PreviewButton = function PreviewButton(_ref) {
  var classes = _ref.classes,
    bottom = _ref.bottom,
    top = _ref.top,
    onClick = _ref.onClick;
  return /*#__PURE__*/_react["default"].createElement(_AnalyticsWrapper["default"], {
    targetId: "preview_open"
  }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
    className: (0, _clsx["default"])(classes.button, bottom && classes.buttonBottom, top && classes.buttonTop, (0, _customClassName["default"])('preview-button')),
    onClick: onClick
  }, /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
    className: classes.buttonIcon
  }, "remove_red_eye"), /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
    className: "text"
  }, (0, _i18n.t)('configurator.previewButton'))));
};
var FullScreenView = /*#__PURE__*/function (_React$Component) {
  _inherits(FullScreenView, _React$Component);
  var _super = _createSuper(FullScreenView);
  function FullScreenView() {
    var _this;
    _classCallCheck(this, FullScreenView);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _super.call.apply(_super, [this].concat(args));
    _defineProperty(_assertThisInitialized(_this), "state", {
      previewOpen: false
    });
    _defineProperty(_assertThisInitialized(_this), "openPreview", function () {
      _this.setState({
        previewOpen: true
      }, function () {
        return _this.props.handleOpenPreview();
      });
    });
    _defineProperty(_assertThisInitialized(_this), "closePreview", function () {
      _this.setState({
        previewOpen: false
      }, function () {
        return _this.props.handleClosePreview();
      });
    });
    return _this;
  }
  _createClass(FullScreenView, [{
    key: "render",
    value: function render() {
      var previewOpen = this.state.previewOpen;
      var _this$props = this.props,
        hasItems = _this$props.hasItems,
        classes = _this$props.classes,
        children = _this$props.children,
        showPreviewButton = _this$props.showPreviewButton,
        showDesignViewList = _this$props.showDesignViewList,
        width = _this$props.width,
        dialogStyle = _this$props.dialogStyle,
        renderTopPreviewButton = _this$props.renderTopPreviewButton,
        ThumbnailComponent = _this$props.ThumbnailComponent,
        thumbnailProps = _this$props.thumbnailProps,
        thumbnailDotMode = _this$props.thumbnailDotMode,
        renderButtonOnTop = _this$props.renderButtonOnTop;
      var topPreviewButton = renderTopPreviewButton(_objectSpread(_objectSpread({}, this.props), {}, {
        onClick: this.openPreview
      }));
      return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, previewOpen && /*#__PURE__*/_react["default"].createElement(_PreviewPortal["default"], {
        closePreviewMode: this.closePreview,
        thumbnailClick: this.handleViewChange,
        previewOpen: previewOpen,
        hasItems: hasItems,
        dialogStyle: dialogStyle
      }, children), topPreviewButton, !previewOpen && children, showDesignViewList ? /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        container: true,
        direction: "column",
        justifyContent: "space-between",
        className: (0, _clsx["default"])(classes.viewsContainer, (0, _customClassName["default"])('views'))
      }, showPreviewButton && /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 12,
        sm: 12,
        md: 8,
        className: (0, _clsx["default"])(classes.thumbnailGrid, thumbnailDotMode || (0, _withWidth.isWidthDown)('md', width) ? 'dots-container' : 'image-container')
      }, renderButtonOnTop ? /*#__PURE__*/_react["default"].createElement(ThumbnailComponent, thumbnailProps) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(ThumbnailComponent, thumbnailProps), !topPreviewButton && /*#__PURE__*/_react["default"].createElement(PreviewButton, _extends({}, this.props, {
        bottom: true,
        onClick: this.openPreview
      }))))) : !topPreviewButton && showPreviewButton && width !== 'xs' && /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        container: true,
        direction: "column",
        justifyContent: "space-between",
        alignItems: "center"
      }, /*#__PURE__*/_react["default"].createElement(PreviewButton, _extends({}, this.props, {
        onClick: this.openPreview,
        classes: {
          button: classes.buttonView,
          buttonIcon: classes.buttonIcon
        }
      }))));
    }
  }]);
  return FullScreenView;
}(_react["default"].Component);
_defineProperty(FullScreenView, "defaultProps", {
  showPreviewButton: true,
  renderTopPreviewButton: function renderTopPreviewButton(_ref2) {
    var width = _ref2.width,
      areAllDesignAreasEmpty = _ref2.areAllDesignAreasEmpty,
      props = _objectWithoutProperties(_ref2, _excluded);
    return (0, _withWidth.isWidthDown)('sm', width) && !areAllDesignAreasEmpty && /*#__PURE__*/_react["default"].createElement(PreviewButton, _extends({}, props, {
      top: true
    }));
  },
  ThumbnailComponent: _Thumbnail["default"],
  renderButtonOnTop: false
});
var _default = exports["default"] = (0, _withWidth["default"])({
  initialWidth: 'lg'
})((0, _styles.withStyles)(styles, {
  name: 'FullScreenView'
})(FullScreenView));