"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 _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _styles = require("@material-ui/core/styles");
var _withWidth = _interopRequireDefault(require("@material-ui/core/withWidth"));
var _i18n = require("../../../../Framework/i18n");
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));
var _InputAdornment = _interopRequireDefault(require("@material-ui/core/InputAdornment"));
var _Dialog = _interopRequireDefault(require("@material-ui/core/Dialog"));
var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
var _DialogTitle = _interopRequireDefault(require("@material-ui/core/DialogTitle"));
var _DialogContent = _interopRequireDefault(require("@material-ui/core/DialogContent"));
var _DialogActions = _interopRequireDefault(require("@material-ui/core/DialogActions"));
var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
var _TextField = _interopRequireDefault(require("@material-ui/core/TextField"));
var _Icon = _interopRequireDefault(require("@material-ui/core/Icon"));
var _AddCircle = _interopRequireDefault(require("@material-ui/icons/AddCircle"));
var _Delete = _interopRequireDefault(require("@material-ui/icons/Delete"));
var _MainButton = _interopRequireDefault(require("../../../../Shared/Components/MainButton"));
var _Grid = _interopRequireDefault(require("@material-ui/core/Grid"));
var _PlusMinusInput = require("../PlusMinusInput");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": 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 styles = function styles(theme) {
  return {
    dialogTitleRoot: {
      padding: '12px 12px 20px 30px',
      fontWeight: 400,
      borderTop: '7px solid ' + theme.palette.primary.main
    },
    dialogContentRoot: {
      padding: '0 32px 24px 30px'
    },
    TypographyCaption: {
      lineHeight: 2.7
    },
    CloseIcon: {
      position: 'absolute',
      right: 16,
      top: 16,
      '&:hover': {
        cursor: 'pointer'
      }
    },
    activeButton: {
      margin: '0 30px 16px 0',
      padding: '10px 24px'
    },
    addButton: {
      textTransform: 'none'
    },
    selectedVariant: {
      maxWidth: 150,
      width: '100%',
      height: 'auto',
      objectFit: 'contain'
    },
    textFieldBulkName: {
      width: 'calc(100% - 24px)'
    },
    buttonStyle: {
      color: theme.buttons.mainBtn.backgroundColor
    },
    rootIconButton: {
      padding: '12px 0'
    },
    variantLabel: {
      color: theme.palette.secondary.dark,
      fontSize: '15px',
      lineHeight: 2.1
    },
    addButtonGrid: {
      display: 'flex',
      justifyContent: 'center',
      marginTop: 24
    },
    textInput: {
      display: 'flex',
      marginTop: 24
    },
    textInputProp: {
      height: 10
    },
    textInputLabel: {
      transform: 'translate(14px, 14px) scale(1)'
    },
    newBulkName: {
      fontWeight: 'bold',
      lineHeight: 1,
      padding: '0 5px'
    },
    gridItem: {
      paddingRight: 15
    }
  };
};
var BulkNames = /*#__PURE__*/function (_React$Component) {
  _inherits(BulkNames, _React$Component);
  var _super = _createSuper(BulkNames);
  function BulkNames() {
    _classCallCheck(this, BulkNames);
    return _super.apply(this, arguments);
  }
  _createClass(BulkNames, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
        classes = _this$props.classes,
        width = _this$props.width,
        onClose = _this$props.onClose,
        showBulkNameForm = _this$props.showBulkNameForm,
        amountLabel = _this$props.amountLabel,
        selectedVariant = _this$props.selectedVariant,
        activeSizeVariant = _this$props.activeSizeVariant,
        totalAmount = _this$props.totalAmount,
        textInputs = _this$props.textInputs,
        handleDelete = _this$props.handleDelete,
        addTextField = _this$props.addTextField,
        handleText = _this$props.handleText,
        saveConfigurationBulkNames = _this$props.saveConfigurationBulkNames,
        size = _this$props.size;
      var dialogTitleId = 'bulk-names-edit-dialog-title';
      return /*#__PURE__*/_react["default"].createElement(_Dialog["default"], {
        open: showBulkNameForm,
        onClose: onClose,
        maxWidth: 'sm',
        fullWidth: true,
        fullScreen: width === 'sm' || width === 'xs',
        scroll: "paper",
        "aria-labelledby": dialogTitleId
      }, /*#__PURE__*/_react["default"].createElement(_DialogTitle["default"], {
        className: classes.dialogTitleRoot
      }, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        className: classes.TypographyCaption,
        variant: "body1",
        id: dialogTitleId
      }, /*#__PURE__*/_react["default"].createElement("b", null, (0, _i18n.t)('bulkNames.bulkNamesEdit'))), /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
        className: classes.CloseIcon,
        onClick: onClose
      }, /*#__PURE__*/_react["default"].createElement(_Icon["default"], null, "close"))), /*#__PURE__*/_react["default"].createElement(_DialogContent["default"], {
        className: classes.dialogContentRoot
      }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        container: true
      }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 3,
        className: classes.gridItem
      }, selectedVariant.url && /*#__PURE__*/_react["default"].createElement("img", {
        src: selectedVariant.url,
        alt: selectedVariant.title,
        "aria-label": selectedVariant.title,
        className: classes.selectedVariant
      })), /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 9
      }, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        classes: {
          root: classes.variantLabel
        }
      }, /*#__PURE__*/_react["default"].createElement("b", null, (0, _upperFirst["default"])(selectedVariant.title))), !(0, _isEmpty["default"])(activeSizeVariant) && /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        classes: {
          root: classes.variantLabel
        }
      }, (0, _i18n.t)('bulkNames.size'), /*#__PURE__*/_react["default"].createElement("b", null, size)), /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        classes: {
          root: classes.variantLabel
        }
      }, (0, _i18n.t)('bulkNames.amount'), /*#__PURE__*/_react["default"].createElement("b", null, totalAmount()))), /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 12
      }, textInputs.map(function (text, index) {
        return /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
          container: true,
          key: index,
          className: classes.textInput
        }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
          item: true,
          xs: 8
        }, /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
          id: toString(index),
          className: classes.textFieldBulkName,
          label: (0, _i18n.t)('bulkNames.name'),
          value: text.text,
          onChange: handleText('text', index),
          variant: "outlined",
          InputLabelProps: {
            classes: {
              outlined: classes.textInputLabel
            }
          },
          InputProps: {
            classes: {
              input: classes.textInputProp
            },
            endAdornment: /*#__PURE__*/_react["default"].createElement(_InputAdornment["default"], {
              position: "end"
            }, /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
              "aria-label": (0, _i18n.t)('bulkNames.deleteBulkName'),
              onClick: handleDelete(index),
              classes: {
                label: classes.buttonStyle,
                root: classes.rootIconButton
              }
            }, /*#__PURE__*/_react["default"].createElement(_Delete["default"], null)))
          }
        })), /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
          item: true,
          xs: 4
        }, /*#__PURE__*/_react["default"].createElement(_PlusMinusInput.PlusMinusInput, {
          maxSize: 9999,
          minSize: 1,
          amountLabel: amountLabel,
          value: text.amount,
          onChangeValue: handleText('amount', index)
        })));
      })), /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 12,
        className: classes.addButtonGrid
      }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
        className: classes.addButton,
        onClick: addTextField
      }, /*#__PURE__*/_react["default"].createElement(_AddCircle["default"], null), /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        classes: {
          root: classes.newBulkName
        }
      }, (0, _i18n.t)('bulkNames.addNewBulkName')))))), /*#__PURE__*/_react["default"].createElement(_DialogActions["default"], null, /*#__PURE__*/_react["default"].createElement(_MainButton["default"], {
        onClick: saveConfigurationBulkNames,
        variant: "contained",
        size: "medium",
        className: classes.activeButton
      }, (0, _i18n.t)('bulkNames.apply'))));
    }
  }]);
  return BulkNames;
}(_react["default"].Component);
var _default = exports["default"] = (0, _withWidth["default"])()((0, _styles.withStyles)(styles, {
  name: 'BulkNames'
})(BulkNames));