"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
var _uniqBy = _interopRequireDefault(require("lodash/uniqBy"));
var _styles = require("@material-ui/core/styles");
var _Grid = _interopRequireDefault(require("@material-ui/core/Grid"));
var _Card = _interopRequireDefault(require("@material-ui/core/Card"));
var _CardContent = _interopRequireDefault(require("@material-ui/core/CardContent"));
var _Select = _interopRequireDefault(require("@material-ui/core/Select"));
var _Input = _interopRequireDefault(require("@material-ui/core/Input"));
var _MenuItem = _interopRequireDefault(require("@material-ui/core/MenuItem"));
var _ListItemText = _interopRequireDefault(require("@material-ui/core/ListItemText"));
var _FormControl = _interopRequireDefault(require("@material-ui/core/FormControl"));
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 _FormControlLabel = _interopRequireDefault(require("@material-ui/core/FormControlLabel"));
var _Switch = _interopRequireDefault(require("@material-ui/core/Switch"));
var _CardActions = _interopRequireDefault(require("@material-ui/core/CardActions"));
var _Search = _interopRequireDefault(require("@material-ui/icons/Search"));
var _withWidth = _interopRequireWildcard(require("@material-ui/core/withWidth"));
var _i18n = require("../../../../../Framework/i18n");
var _isMobileDevice = require("../../../../../Framework/Helpers/isMobileDevice");
var _createSelectionRangeMemo = require("../../../../../Utils/Helper/createSelectionRangeMemo");
var _MainButton = _interopRequireDefault(require("../../../../../Shared/Components/MainButton"));
var _ResizeDetect = require("../../../../../Shared/HOCs/ResizeDetect/ResizeDetect");
var _AnalyticsWrapper = _interopRequireDefault(require("../../../../Shared/Components/Analytics/AnalyticsWrapper"));
var _ColorPalettesSearch = require("./ColorPalettesSearch");
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 _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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
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 _colorPaletteButton;
  return {
    container: {
      pointerEvents: 'all' // catch the pointer events again
    },

    containerInPortraitMode: {
      width: '40%',
      position: 'fixed',
      bottom: 0,
      paddingBottom: 20,
      left: 16
    },
    card: _defineProperty({
      height: '100%',
      borderTop: '7px solid ' + theme.palette.primary.main,
      position: 'relative'
    }, theme.breakpoints.down('xs'), {
      boxShadow: 'none'
    }),
    colorCardActions: _defineProperty({
      padding: '0 16px 16px 16px'
    }, theme.breakpoints.down('xs'), {
      padding: '0 16px',
      display: 'flex',
      height: 56,
      bottom: 16,
      right: 0,
      left: 0,
      position: 'fixed',
      background: 'white'
    }),
    cardUnboxed: _defineProperty({
      height: '100%',
      borderTop: 'none',
      boxShadow: 'none'
    }, theme.breakpoints.down('xs'), {
      boxShadow: 'none'
    }),
    customColorGrid: {
      textAlign: 'center',
      margin: 'auto'
    },
    alignTypo: _defineProperty({
      marginBottom: '16px'
    }, theme.breakpoints.down('xs'), {
      marginBottom: '9px'
    }),
    colorPaletteTitle: {},
    arrowNone: {
      display: 'none !important'
    },
    colorPaletteColors: {
      border: '1px solid ' + theme.palette.secondary.light,
      borderRadius: '50%',
      width: 32,
      height: 32,
      minWidth: 32,
      minHeight: 32,
      cursor: 'pointer'
    },
    colorPaletteWrapper: function colorPaletteWrapper(_ref) {
      var heightColorPaletteWrapper = _ref.heightColorPaletteWrapper,
        width = _ref.width,
        isCustomColorChecked = _ref.isCustomColorChecked;
      return {
        maxHeight: (0, _withWidth.isWidthDown)('xs', width) ? isCustomColorChecked ? heightColorPaletteWrapper - 90 : heightColorPaletteWrapper : 290,
        padding: '0 16px',
        display: 'flex',
        flexWrap: 'wrap',
        marginBottom: 16,
        overflowY: 'auto'
      };
    },
    switchBaseSpacing: {
      padding: 9
    },
    colorPaletteSearchWrapper: {
      marginBottom: 16
    },
    colorPaletteDisabled: {
      color: theme.palette.secondary.lighter
    },
    colorWrapper: {
      height: 40,
      display: 'flex',
      alignItems: 'center',
      marginTop: 11,
      marginBottom: 5,
      width: 'calc(100% / 2)',
      '&:hover': {
        cursor: 'pointer'
      }
    },
    usedColorWrapper: {
      display: 'inline-flex',
      padding: 12
    },
    searchPaletteGrid: {
      padding: 0
    },
    selectedColorText: {
      '& span': {
        fontSize: '12px',
        fontWeight: 'bold',
        fontStyle: 'italic',
        textDecoration: 'underline'
      }
    },
    selectColorMenu: {
      '& div': {
        '& span': {
          fontSize: 14,
          padding: '0 16px'
        }
      }
    },
    colorPaletteButton: (_colorPaletteButton = {
      marginTop: 24,
      padding: 8
    }, _defineProperty(_colorPaletteButton, theme.breakpoints.down('sm'), {
      marginTop: '0'
    }), _defineProperty(_colorPaletteButton, theme.breakpoints.down('xs'), {
      height: 56
    }), _colorPaletteButton),
    selectedColorGrid: {
      margin: '0 auto'
    },
    cardContentRoot: {},
    gridColorContent: {
      maxHeight: '100%'
    },
    RootListItem: _defineProperty({
      margin: '0 16px',
      padding: 0,
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      display: 'flex',
      alignItems: 'center',
      '& span': {
        fontSize: '15px',
        maxWidth: 80,
        maxHeight: 45,
        lineHeight: 1.5,
        webkitLineClamp: 2,
        webkitBoxOrient: 'vertical',
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        display: 'block'
      }
    }, theme.breakpoints.between('xs', 'sm'), {
      width: '100%'
    }),
    selectedColorField: {
      padding: '15px 14px',
      fontSize: 15
    },
    selectedColorLabel: {
      fontSize: 15
    },
    disabledColorWrap: {
      cursor: 'unset',
      background: theme.palette.secondary.lighter + ' !important',
      border: '1px solid ' + theme.palette.secondary.lighter
    },
    disabledColorText: {
      '& span': {
        color: theme.palette.secondary.lighter + ' !important'
      }
    },
    selectedColorWrap: {
      border: 'solid 1px ' + theme.palette.secondary.light,
      boxShadow: '3px 2px 5px ' + theme.palette.secondary.light,
      borderRadius: '50%'
    },
    DialogCloseIcon: {
      position: 'absolute',
      right: 16,
      top: 20,
      '&:hover': {
        cursor: 'pointer'
      }
    },
    searchColorIcon: {
      left: 15,
      top: 6,
      position: 'relative',
      color: theme.palette.primary.darkText,
      '&:hover': {
        cursor: 'pointer'
      }
    },
    iconColorWrap: _defineProperty({
      height: 24
    }, theme.breakpoints.down('sm'), {
      height: 34
    }),
    formControlCustomColor: _defineProperty({
      marginLeft: -8
    }, theme.breakpoints.down('sm'), {
      paddingLeft: 16,
      paddingTop: 12
    }),
    underlineInputText: {
      marginBottom: 8,
      //https://github.com/mui-org/material-ui/issues/12192#issuecomment-406182809
      '&&&&:hover:before': {
        borderBottom: '1px solid rgba(0, 0, 0, 0.42)'
      },
      '&:after': {
        borderBottom: '1px solid transparent'
      }
    },
    outlinedInput: {
      fontSize: 15,
      height: 40,
      padding: '0 0 0 16px',
      cursor: 'default',
      lineHeight: '40px'
    },
    underlineSelectItem: {
      '&:after': {
        borderBottom: '2px solid ' + theme.palette.primary.main
      }
    }
  };
};
var selectionRangeMemo = (0, _createSelectionRangeMemo.createSelectionRangeMemo)();
// height of header footer = 283
// height of one color element = 58
var heightColorPalette = function heightColorPalette() {
  return Math.floor((window.innerHeight - (225 + 58)) / 58) * 58;
};
var ColorPaletteColorsWrapper = (0, _styles.withStyles)(styles, {
  name: 'ColorPaletteColorsWrapper'
})(function (_ref2) {
  var palette = _ref2.palette,
    classes = _ref2.classes,
    isSearchActive = _ref2.isSearchActive,
    renderColors = _ref2.renderColors;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: classes.colorPaletteWrapper
  }, !isSearchActive && renderColors(palette));
});
var ColorPalettes = /*#__PURE__*/function (_React$Component) {
  _inherits(ColorPalettes, _React$Component);
  var _super = _createSuper(ColorPalettes);
  function ColorPalettes(props) {
    var _this;
    _classCallCheck(this, ColorPalettes);
    _this = _super.call(this, props);
    _defineProperty(_assertThisInitialized(_this), "textInputRef", /*#__PURE__*/_react["default"].createRef());
    _defineProperty(_assertThisInitialized(_this), "colorSelectChange", function (evt, color, paletteIdentifier, isCustomColorChecked) {
      if (isCustomColorChecked) {
        return;
      }
      if (!(0, _isMobileDevice.isMobileDevice)()) {
        // only for desktop to prevent losing the focus
        evt.preventDefault();
      }
      selectionRangeMemo.restore();
      if ((0, _isFunction["default"])(_this.props.colorSelectClick)) {
        _this.props.colorSelectClick(color.hex_value, color.identifier, paletteIdentifier, false);
      }
      selectionRangeMemo.save();
      if ((0, _isMobileDevice.isMobileDevice)()) {
        // on mobile the soft keyboard is opened by the selection restore step
        // so it has to be closed again by removing the ranges
        window.getSelection().removeAllRanges();
      }
    });
    _defineProperty(_assertThisInitialized(_this), "onColorPaletteChange", function (evt) {
      _this.props.colorPaletteChange(evt.target.value);
    });
    _defineProperty(_assertThisInitialized(_this), "onCustomColorChange", function (evt) {
      _this.setState({
        customColor: evt.target.value,
        customColorError: null
      });
    });
    _defineProperty(_assertThisInitialized(_this), "onApplyColor", function () {
      var customColor = _this.state.customColor;
      if (!customColor) {
        _this.setState({
          customColorError: (0, _i18n.t)('colorPalettes.emptyColorCode')
        });
        return;
      }
      _this.props.closeColorPalettes();
      selectionRangeMemo.restore();
      _this.props.colorSelectClick(customColor, customColor, null, true);
    });
    _defineProperty(_assertThisInitialized(_this), "toggleCustomColor", function (event) {
      _this.setState({
        isCustomColorChecked: event.target.checked
      });
    });
    _defineProperty(_assertThisInitialized(_this), "changeText", function (event) {
      _this.setState({
        searchText: event.target.value
      });
    });
    _defineProperty(_assertThisInitialized(_this), "activateSearch", function () {
      _this.setState({
        isSearchActive: true
      });
    });
    _defineProperty(_assertThisInitialized(_this), "closeSearch", function () {
      _this.setState({
        isSearchActive: false
      });
      _this.setState({
        searchText: ''
      });
    });
    _defineProperty(_assertThisInitialized(_this), "searchPaletteColors", function (palettes) {
      var _ref4;
      var colorsArray = palettes.map(function (_ref3) {
        var identifier = _ref3.identifier,
          colors = _ref3.colors;
        return colors.map(function (color) {
          return _objectSpread(_objectSpread({}, color), {}, {
            paletteIdentifier: identifier
          });
        });
      });
      var searchColors = (_ref4 = []).concat.apply(_ref4, _toConsumableArray(colorsArray));
      return {
        colors: (0, _uniqBy["default"])(searchColors, 'identifier')
      };
    });
    _defineProperty(_assertThisInitialized(_this), "renderColors", function (palette) {
      var _this$props = _this.props,
        classes = _this$props.classes,
        selectedColor = _this$props.selectedColor;
      var isCustomColorChecked = _this.state.isCustomColorChecked;
      var selectedColorData = _objectSpread({}, selectedColor);
      try {
        selectedColorData.identifier = JSON.parse(selectedColorData.identifier);
      } catch (e) {
        //No action required
      }
      var classesColorWrapSelected = classes.colorPaletteColors + ' ' + classes.selectedColorWrap;
      var classesDisabledColorWrap = classes.colorPaletteColors + ' ' + classes.disabledColorWrap;
      return palette && palette.colors && palette.colors.map(function (color, colorIndex) {
        return /*#__PURE__*/_react["default"].createElement("div", {
          key: colorIndex,
          className: classes.colorWrapper,
          onMouseDown: function onMouseDown(evt) {
            return _this.colorSelectChange(evt, color, palette.identifier ? palette.identifier : color.paletteIdentifier, isCustomColorChecked);
          }
        }, /*#__PURE__*/_react["default"].createElement("div", {
          className: !isCustomColorChecked ? selectedColorData && selectedColorData.identifier && selectedColorData.identifier.color === color.identifier ? classesColorWrapSelected : classes.colorPaletteColors : classesDisabledColorWrap,
          style: {
            background: '#' + color.hex_value
          },
          "aria-label": color.title,
          key: color.identifier
        }), /*#__PURE__*/_react["default"].createElement(_ListItemText["default"], {
          className: !isCustomColorChecked ? selectedColorData && selectedColorData.identifier && selectedColorData.identifier.color === color.identifier ? classes.selectedColorText : 'variant-list' : classes.disabledColorText,
          classes: {
            root: classes.RootListItem
          },
          primary: (0, _upperFirst["default"])(color.title)
        }));
      });
    });
    var _selectedColor = _this.props.selectedColor;
    var _selectedColorData = _selectedColor && _selectedColor.identifier ? _selectedColor.identifier : {};
    try {
      _selectedColorData = JSON.parse(_selectedColorData);
    } catch (e) {
      //No action required
    }
    var _customColor = _selectedColorData.custom ? _selectedColorData.color : '';
    var _isCustomColorChecked = !!_selectedColorData.custom;
    _this.state = {
      customColor: _customColor,
      customColorError: null,
      isCustomColorChecked: _isCustomColorChecked,
      isSearchActive: false,
      searchText: '',
      heightColorPaletteWrapper: heightColorPalette()
    };
    selectionRangeMemo.save();
    return _this;
  }
  _createClass(ColorPalettes, [{
    key: "componentDidUpdate",
    value: function componentDidUpdate(prevProps, prevState) {
      var selectedColor = this.props.selectedColor;
      if (selectedColor.identifier.custom !== prevProps.selectedColor.identifier.custom) {
        this.setState({
          isCustomColorChecked: selectedColor.identifier.custom
        });
        if (selectedColor.identifier.custom) {
          this.setState({
            customColor: selectedColor.identifier.color
          });
        }
      }
      var isCustomColorChecked = this.state.isCustomColorChecked;
      // set focus to custom color field when toggling
      if (isCustomColorChecked && !prevState.isCustomColorChecked) {
        this.textInputRef.current.focus();
      }
      if (this.props.size !== prevProps.size) {
        this.setState({
          heightColorPaletteWrapper: heightColorPalette()
        });
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;
      var _this$props2 = this.props,
        boxed = _this$props2.boxed,
        classes = _this$props2.classes,
        colorPalettes = _this$props2.colorPalettes,
        closeColorPalettes = _this$props2.closeColorPalettes,
        selectedColor = _this$props2.selectedColor,
        width = _this$props2.width,
        palette = _this$props2.palette,
        usedColors = _this$props2.usedColors,
        isPortraitMode = _this$props2.isPortraitMode;
      var _this$state = this.state,
        customColor = _this$state.customColor,
        customColorError = _this$state.customColorError,
        isCustomColorChecked = _this$state.isCustomColorChecked,
        isSearchActive = _this$state.isSearchActive,
        searchText = _this$state.searchText,
        heightColorPaletteWrapper = _this$state.heightColorPaletteWrapper;
      var multiplePalettes = colorPalettes.length > 1;
      var arrowVisible = !multiplePalettes ? classes.arrowNone : '';
      var classesColorWrap = classes.colorPaletteColors;
      var classesDisabledColorWrap = classes.colorPaletteColors + ' ' + classes.disabledColorWrap;
      return /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        container: true,
        className: classes.container + ' ' + (isPortraitMode && width !== 'xs' ? classes.containerInPortraitMode : '')
      }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 12,
        md: 12
      }, /*#__PURE__*/_react["default"].createElement(_Card["default"], {
        className: boxed ? classes.card : classes.cardUnboxed
      }, /*#__PURE__*/_react["default"].createElement(_CardContent["default"], {
        className: classes.cardContentRoot
      }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        container: true
      }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 12,
        md: 12,
        lg: 12
      }, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        variant: "h5",
        className: classes.alignTypo + ' ' + classes.colorPaletteTitle
      }, /*#__PURE__*/_react["default"].createElement("b", null, (0, _i18n.t)('colorPalettes.title')), /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
        className: classes.DialogCloseIcon,
        onClick: closeColorPalettes
      }, "close"))), /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 12,
        md: 12,
        lg: 12
      }, usedColors && usedColors.map(function (color, colorIndex) {
        return /*#__PURE__*/_react["default"].createElement("div", {
          key: colorIndex,
          className: classes.usedColorWrapper,
          onMouseDown: function onMouseDown(evt) {
            return _this2.colorSelectChange(evt, color, color.palette ? color.palette : palette.identifier, isCustomColorChecked);
          }
        }, /*#__PURE__*/_react["default"].createElement("div", {
          className: isCustomColorChecked ? classesDisabledColorWrap : classesColorWrap,
          style: {
            background: color.value || color.identifier
          },
          key: color.identifier
        }));
      })), /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        className: classes.gridColorContent,
        item: true,
        xs: 12,
        md: 12,
        lg: 12
      }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        container: true
      }, !isSearchActive ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 10
      }, /*#__PURE__*/_react["default"].createElement(_FormControl["default"], {
        fullWidth: true,
        className: classes.formControl
      }, colorPalettes.length > 1 ? /*#__PURE__*/_react["default"].createElement(_Select["default"], {
        value: palette && palette.identifier,
        onChange: this.onColorPaletteChange,
        input: /*#__PURE__*/_react["default"].createElement(_Input["default"], {
          id: "colorPaletteInput",
          readOnly: !multiplePalettes,
          classes: {
            underline: classes.underlineSelectItem
          }
        }),
        classes: {
          selectMenu: classes.selectColorMenu,
          icon: arrowVisible
        }
      }, colorPalettes.map(function (colorPalette, colorPaletteIndex) {
        return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
          key: colorPaletteIndex,
          value: colorPalette.identifier,
          "aria-label": colorPalette.title
        }, /*#__PURE__*/_react["default"].createElement(_ListItemText["default"], {
          primary: colorPalette.title
        }));
      })) : colorPalettes.map(function (colorPalette, colorPaletteIndex) {
        return /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
          key: colorPaletteIndex,
          readOnly: true,
          inputProps: {
            readOnly: true
          },
          fullWidth: true,
          value: colorPalette.title,
          translate: "no",
          InputProps: {
            classes: {
              input: classes.outlinedInput,
              underline: classes.underlineInputText
            }
          }
        });
      }))), /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 2
      }, /*#__PURE__*/_react["default"].createElement(_Search["default"], {
        className: classes.searchColorIcon,
        onClick: this.activateSearch
      }))) : /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 12,
        className: classes.searchPaletteGrid
      }, /*#__PURE__*/_react["default"].createElement(_ColorPalettesSearch.ColorPalettesSearch, {
        heightColorPaletteWrapper: isCustomColorChecked ? heightColorPaletteWrapper - 150 // 135 height of custom fields
        : heightColorPaletteWrapper - 50 // 35 height of search clear button
        ,

        onSearch: this.onSearch,
        closeSearch: this.closeSearch,
        isSearchActive: isSearchActive,
        searchText: searchText,
        changeText: this.changeText,
        searchPalette: this.searchPaletteColors(colorPalettes),
        renderColors: this.renderColors,
        width: width
      }))), /*#__PURE__*/_react["default"].createElement(ColorPaletteColorsWrapper, {
        palette: palette,
        heightColorPaletteWrapper: heightColorPaletteWrapper,
        isCustomColorChecked: isCustomColorChecked,
        isSearchActive: isSearchActive,
        renderColors: this.renderColors,
        width: width
      }), /*#__PURE__*/_react["default"].createElement(_FormControlLabel["default"], {
        classes: {
          root: classes.formControlCustomColor
        },
        control: /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
          classes: {
            switchBase: classes.switchBaseSpacing
          },
          checked: this.state.isCustomColorChecked,
          onChange: this.toggleCustomColor,
          value: (0, _i18n.t)('colorPalettes.ownColorRequest'),
          color: "primary"
        }),
        label: (0, _i18n.t)('colorPalettes.ownColorRequest')
      }), isCustomColorChecked && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        variant: "body2",
        className: classes.alignTypo
      }, (0, _i18n.t)('colorPalettes.description')), /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        item: true,
        xs: 12,
        md: 12,
        lg: 12
      }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        className: classes.customColorGrid,
        item: true,
        xs: 12,
        md: 12,
        lg: 12
      }, /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
        inputRef: this.textInputRef,
        value: customColor,
        onChange: this.onCustomColorChange,
        variant: "outlined",
        label: (0, _i18n.t)('colorPalettes.colorCode'),
        placeholder: (0, _i18n.t)('colorPalettes.colorSpecify'),
        translate: "no",
        fullWidth: true,
        InputProps: {
          classes: {
            input: classes.selectedColorField
          }
        },
        InputLabelProps: {
          classes: {
            formControl: classes.selectedColorLabel
          }
        },
        error: !!customColorError,
        helperText: customColorError
      }))))))), /*#__PURE__*/_react["default"].createElement(_CardActions["default"], {
        className: classes.colorCardActions
      }, /*#__PURE__*/_react["default"].createElement(_Grid["default"], {
        className: classes.customColorGrid,
        item: true,
        xs: 12,
        md: 12,
        lg: 12
      }, /*#__PURE__*/_react["default"].createElement(_AnalyticsWrapper["default"], {
        targetId: "text_color",
        data: !isCustomColorChecked ? selectedColor : customColor
      }, /*#__PURE__*/_react["default"].createElement(_MainButton["default"], {
        fullWidth: true,
        onClick: !isCustomColorChecked ? closeColorPalettes : this.onApplyColor,
        className: classes.colorPaletteButton,
        size: "medium",
        variant: "contained"
      }, (0, _i18n.t)('colorPalettes.apply'))))))));
    }
  }]);
  return ColorPalettes;
}(_react["default"].Component);
var _default = exports["default"] = (0, _ResizeDetect.withResizeDetectWrapper)((0, _withWidth["default"])({
  initialWidth: 'lg'
})((0, _styles.withStyles)(styles, {
  name: 'ColorPalettes'
})(ColorPalettes)));