"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = 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 _Card = _interopRequireDefault(require("@material-ui/core/Card"));
var _CardContent = _interopRequireDefault(require("@material-ui/core/CardContent"));
var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
var _Grid = _interopRequireDefault(require("@material-ui/core/Grid"));
var _MenuItem = _interopRequireDefault(require("@material-ui/core/MenuItem"));
var _TextField = _interopRequireDefault(require("@material-ui/core/TextField"));
var _CheckCircle = _interopRequireDefault(require("@material-ui/icons/CheckCircle"));
var _Error = _interopRequireDefault(require("@material-ui/icons/Error"));
var _Icon = _interopRequireDefault(require("@material-ui/core/Icon"));
var _Modal = _interopRequireDefault(require("@material-ui/core/Modal"));
var _withWidth = _interopRequireDefault(require("@material-ui/core/withWidth"));
var _i18n = require("../../../../../Framework/i18n");
var _AnalyticsWrapper = _interopRequireDefault(require("../../../../Shared/Components/Analytics/AnalyticsWrapper"));
var _InformationTag = _interopRequireDefault(require("../../../../Shared/Components/InformationTag/InformationTag"));
var _customClassName = _interopRequireDefault(require("../../../../Utils/customClassName"));
var _Select = _interopRequireDefault(require("../Select"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 _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 _cardContentRoot, _underlineInputText;
  return {
    card: _defineProperty({}, theme.breakpoints.down('xs'), {
      zIndex: 1
    }),
    cardBoxed: {
      borderTop: '7px solid ' + theme.palette.primary.main,
      overflow: 'inherit'
    },
    cardUnboxed: {
      borderTop: 'none',
      boxShadow: 'none',
      borderRadius: 0,
      pointerEvents: 'all'
    },
    cardContent: _defineProperty({
      padding: 10
    }, theme.breakpoints.down('xs'), {
      paddingTop: 0,
      '&:last-child': {
        paddingBottom: 8
      }
    }),
    cardContentRoot: (_cardContentRoot = {
      padding: '0 16px'
    }, _defineProperty(_cardContentRoot, theme.breakpoints.down('xs'), {
      padding: 0
    }), _defineProperty(_cardContentRoot, '&:last-child', _defineProperty({}, theme.breakpoints.up('sm'), {
      paddingBottom: 16
    })), _cardContentRoot),
    listItemText: _defineProperty({
      fontSize: '12px',
      lineHeight: '40px'
    }, theme.breakpoints.down('xs'), {
      lineHeight: '56px'
    }),
    listItem: _defineProperty({
      display: 'flex'
    }, theme.breakpoints.down('sm'), {
      minWidth: 100
    }),
    GridItemXS: _defineProperty({}, theme.breakpoints.down('xs'), {
      paddingRight: 15
    }),
    GridContainer: _defineProperty({
      paddingTop: 9
    }, theme.breakpoints.down('xs'), {
      paddingRight: 48,
      paddingTop: 0
    }),
    arrowNone: {
      display: 'none'
    },
    outlinedInput: _defineProperty({
      fontSize: 15,
      height: 40,
      padding: '0 0 0 16px',
      cursor: 'default',
      lineHeight: '40px',
      overflow: 'hidden',
      textOverflow: 'ellipsis'
    }, theme.breakpoints.down('xs'), {
      height: 56,
      padding: 0
    }),
    iconedItem: _defineProperty({}, theme.breakpoints.down('xs'), {
      paddingRight: '6px !important'
    }),
    underlineInputText: (_underlineInputText = {
      marginBottom: 0
    }, _defineProperty(_underlineInputText, theme.breakpoints.up('sm'), {
      marginBottom: 8
    }), _defineProperty(_underlineInputText, '&:before', _defineProperty({
      borderBottom: 0
    }, theme.breakpoints.up('sm'), {
      borderBottom: '1px solid rgba(0, 0, 0, 0.42)'
    })), _defineProperty(_underlineInputText, '&&&&:hover:before', _defineProperty({
      borderBottom: 0
    }, theme.breakpoints.up('sm'), {
      borderBottom: '1px solid rgba(0, 0, 0, 0.42)'
    })), _defineProperty(_underlineInputText, '&:after', _defineProperty({
      borderBottom: 0
    }, theme.breakpoints.up('sm'), {
      borderBottom: '1px solid transparent'
    })), _underlineInputText),
    iconRootCheck: _defineProperty({
      position: 'absolute',
      right: 30,
      height: 40,
      lineHeight: '40px'
    }, theme.breakpoints.down('xs'), {
      position: 'unset',
      paddingRight: 18,
      height: 56,
      lineHeight: '56px'
    }),
    colorAmountMessage: _defineProperty({
      display: 'inline-flex',
      backgroundColor: '#4FC36D',
      marginTop: 16,
      borderRadius: '4px',
      minHeight: 40,
      color: '#fff',
      padding: '10px 16px'
    }, theme.breakpoints.down('xs'), {
      minHeight: 56,
      position: 'absolute',
      margin: 0,
      right: 0
    }),
    colorAmountMessageText: _defineProperty({
      verticalAlign: 'middle',
      color: '#fff',
      padding: '0 10px',
      fontSize: 15,
      fontWeight: 500
    }, theme.breakpoints.down('xs'), {
      display: 'none',
      '.colorAmountMessageOpen &': {
        display: 'inline',
        lineHeight: '40px'
      }
    }),
    colorAmountMessageWarning: {
      backgroundColor: '#ED1C29'
    },
    colorAmountMessageIcon: _defineProperty({
      marginTop: '-2px'
    }, theme.breakpoints.down('xs'), {
      marginTop: 8
    }),
    alignInfoButton: {
      display: 'flex',
      '& .info-btn': {
        '& button': {
          '@media (min-width: 320px) and (max-width: 480px)': {
            padding: '12px 0'
          }
        }
      }
    }
  };
};
var DesignAreaControlbox = /*#__PURE__*/function (_React$Component) {
  _inherits(DesignAreaControlbox, _React$Component);
  var _super = _createSuper(DesignAreaControlbox);
  function DesignAreaControlbox(props) {
    var _this;
    _classCallCheck(this, DesignAreaControlbox);
    _this = _super.call(this, props);
    _defineProperty(_assertThisInitialized(_this), "openAmountIndicatorModal", function () {
      _this.setState({
        amountIndicatorOpen: true
      });
    });
    _defineProperty(_assertThisInitialized(_this), "closeAmountIndicatorModal", function () {
      _this.setState({
        amountIndicatorOpen: false
      });
    });
    _defineProperty(_assertThisInitialized(_this), "getColorAmountMessageClass", function () {
      var _this$props = _this.props,
        classes = _this$props.classes,
        hasAmountIndicatorWarning = _this$props.hasAmountIndicatorWarning;
      var amountIndicatorOpen = _this.state.amountIndicatorOpen;
      var className = "".concat(classes.GridItemXS, " ").concat(classes.colorAmountMessage);
      if (hasAmountIndicatorWarning) {
        className += " ".concat(classes.colorAmountMessageWarning);
      }
      if (amountIndicatorOpen) {
        className += ' colorAmountMessageOpen';
      }
      return className;
    });
    _defineProperty(_assertThisInitialized(_this), "getColorAmountMessage", function () {
      var _this$props2 = _this.props,
        colorAmount = _this$props2.colorAmount,
        maxColorAmount = _this$props2.maxColorAmount;
      if (!maxColorAmount) {
        return (0, _i18n.t)('colorAmountIndicator.unlimitedColors');
      }
      if (colorAmount > maxColorAmount) {
        return (0, _i18n.t)('colorAmountIndicator.warning', {
          colorAmount: colorAmount,
          maxColorAmount: maxColorAmount
        });
      }
      return (0, _i18n.t)('colorAmountIndicator.ok', {
        colorAmount: colorAmount
      });
    });
    _this.state = {
      amountIndicatorOpen: false
    };
    return _this;
  }
  _createClass(DesignAreaControlbox, [{
    key: "render",
    value: function render() {
      var _this$props3 = this.props,
        classes = _this$props3.classes,
        boxed = _this$props3.boxed,
        handleChangeDesignArea = _this$props3.handleChangeDesignArea,
        handleChangeProductionMethod = _this$props3.handleChangeProductionMethod,
        valueProductionMethod = _this$props3.valueProductionMethod,
        valueDesignArea = _this$props3.valueDesignArea,
        designAreas = _this$props3.designAreas,
        designedAreas = _this$props3.designedAreas,
        width = _this$props3.width,
        colorDisabled = _this$props3.colorDisabled,
        hasAmountIndicatorWarning = _this$props3.hasAmountIndicatorWarning;
      var amountIndicatorOpen = this.state.amountIndicatorOpen;
      if (!valueDesignArea || !valueProductionMethod) {
        return null;
      }
      var designProductionMethods = valueDesignArea.designProductionMethods;
      return /*#__PURE__*/_react["default"].createElement(_Card["default"], {
        className: (0, _clsx["default"])(classes.card, boxed ? classes.cardBoxed : classes.cardUnboxed, (0, _customClassName["default"])('design-area-box'))
      }, /*#__PURE__*/_react["default"].createElement(_CardContent["default"], {
        className: boxed ? '' : classes.cardContent,
        classes: {
          root: classes.cardContentRoot
        }
      }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        container: true,
        className: classes.GridContainer
      }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 6,
        sm: 12,
        md: 12,
        lg: 12,
        className: classes.GridItemXS + ((0, _i18n.translationExists)('designAreaInformation') ? ' ' + classes.alignInfoButton : '')
      }, designAreas.length > 1 ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_AnalyticsWrapper["default"], {
        targetId: "design_area_switch"
      }, /*#__PURE__*/_react["default"].createElement(_Select["default"], {
        bold: true,
        value: valueDesignArea.identifier,
        onChange: handleChangeDesignArea,
        readOnly: false,
        iconClass: '',
        autoWidth: width === 'xs'
      }, designAreas.map(function (area) {
        return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
          key: area.identifier,
          value: area.identifier,
          "aria-label": area.title
        }, /*#__PURE__*/_react["default"].createElement("div", {
          className: classes.listItem
        }, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
          className: classes.listItemText + ' ' + (designedAreas[area.identifier] ? classes.iconedItem : ''),
          noWrap: true
        }, area.title), designedAreas[area.identifier] && /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
          className: classes.iconRootCheck
        }, "check_circle_outline")));
      }))), (0, _i18n.translationExists)('designAreaInformation') && /*#__PURE__*/_react["default"].createElement("div", {
        className: "info-btn"
      }, /*#__PURE__*/_react["default"].createElement(_InformationTag["default"], {
        infoText: (0, _i18n.t)('designAreaInformation')
      }))) : designAreas.map(function (area) {
        return /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
          key: area.identifier,
          readOnly: true,
          inputProps: {
            readOnly: true
          },
          fullWidth: true,
          value: area.title,
          translate: "no",
          InputProps: {
            classes: {
              input: classes.outlinedInput,
              underline: classes.underlineInputText
            }
          }
        });
      })), designProductionMethods && /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 6,
        sm: 12,
        md: 12,
        lg: 12,
        className: classes.GridItemXS + ((0, _i18n.translationExists)('designProductionInformation') ? ' ' + classes.alignInfoButton : '')
      }, designProductionMethods.length > 1 ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_AnalyticsWrapper["default"], {
        targetId: "design_production_switch",
        data: valueProductionMethod.identifier
      }, /*#__PURE__*/_react["default"].createElement(_Select["default"], {
        bold: true,
        value: valueProductionMethod.identifier,
        onChange: handleChangeProductionMethod,
        readOnly: false,
        iconClass: ''
      }, designProductionMethods.map(function (productionMethod) {
        return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
          key: productionMethod.identifier,
          value: productionMethod.identifier,
          "aria-label": productionMethod.title
        }, ' ', /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
          className: classes.listItemText,
          noWrap: true
        }, productionMethod.title));
      }))), (0, _i18n.translationExists)('designProductionInformation') && /*#__PURE__*/_react["default"].createElement("div", {
        className: "info-btn"
      }, /*#__PURE__*/_react["default"].createElement(_InformationTag["default"], {
        infoText: (0, _i18n.t)('designProductionInformation')
      }))) : designProductionMethods.map(function (productionMethod) {
        return /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
          key: productionMethod.identifier,
          readOnly: true,
          inputProps: {
            readOnly: true
          },
          fullWidth: true,
          value: productionMethod.title,
          translate: "no",
          InputProps: {
            classes: {
              input: classes.outlinedInput,
              underline: classes.underlineInputText
            }
          }
        });
      })), !colorDisabled && /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 12,
        sm: 12,
        md: 12,
        lg: 12,
        className: this.getColorAmountMessageClass(),
        onClick: this.openAmountIndicatorModal
      }, hasAmountIndicatorWarning ? /*#__PURE__*/_react["default"].createElement(_Error["default"], {
        className: classes.colorAmountMessageIcon
      }) : /*#__PURE__*/_react["default"].createElement(_CheckCircle["default"], {
        className: classes.colorAmountMessageIcon
      }), /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        variant: "body1",
        component: "span",
        className: classes.colorAmountMessageText
      }, this.getColorAmountMessage())), /*#__PURE__*/_react["default"].createElement(_Modal["default"], {
        open: width === 'xs' && amountIndicatorOpen,
        BackdropProps: {
          invisible: true
        },
        onClick: this.closeAmountIndicatorModal
      }, /*#__PURE__*/_react["default"].createElement("div", null)))));
    }
  }]);
  return DesignAreaControlbox;
}(_react["default"].Component);
var _default = exports["default"] = (0, _withWidth["default"])({
  initialWidth: 'lg'
})((0, _styles.withStyles)(styles, {
  name: 'DesignAreaControlbox'
})(DesignAreaControlbox));