"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _propTypes = require("prop-types");

var _utils = require("@vincent_za/utils");

var _component = _interopRequireDefault(require("../../Base/component"));

var _component2 = _interopRequireDefault(require("../../Header/component"));

var _component3 = _interopRequireDefault(require("../../List/component"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

var VariantSimple =
/*#__PURE__*/
function (_React$Component) {
  _inherits(VariantSimple, _React$Component);

  function VariantSimple() {
    _classCallCheck(this, VariantSimple);

    return _possibleConstructorReturn(this, _getPrototypeOf(VariantSimple).apply(this, arguments));
  }

  _createClass(VariantSimple, [{
    key: "shouldComponentUpdate",
    value: function shouldComponentUpdate(nextProps) {
      if (nextProps.isClick !== this.props.isClick) return true;
      if (nextProps.isDisabled !== this.props.isDisabled) return true;
      if (nextProps.placeholder !== this.props.placeholder) return true;
      if (nextProps.list !== this.props.list) return true;
      if (nextProps.activeItem !== this.props.activeItem) return true;
      if (nextProps.activeItems !== this.props.activeItems) return true;
      if (nextProps.activeItemRaw !== this.props.activeItemRaw) return true;
      if (nextProps.asyncStatus !== this.props.asyncStatus) return true;
      if (nextProps.asyncStatusList !== this.props.asyncStatusList) return true;
      return false;
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          isFormVariant = _this$props.isFormVariant,
          isClick = _this$props.isClick,
          isDisabled = _this$props.isDisabled,
          isHeaderStretchWidth = _this$props.isHeaderStretchWidth,
          isMenuHeaderWidth = _this$props.isMenuHeaderWidth,
          isMenuHeaderWidthMin = _this$props.isMenuHeaderWidthMin,
          isIcon = _this$props.isIcon,
          isInWidget = _this$props.isInWidget,
          isCloseOnSelect = _this$props.isCloseOnSelect,
          domScrollSelector = _this$props.domScrollSelector,
          placeholder = _this$props.placeholder,
          list = _this$props.list,
          itemKey = _this$props.itemKey,
          activeItem = _this$props.activeItem,
          activeItems = _this$props.activeItems,
          activeItemRaw = _this$props.activeItemRaw,
          fieldName = _this$props.fieldName,
          onItemClick = _this$props.onItemClick,
          className = _this$props.className,
          isFloatErrorVariant = _this$props.isFloatErrorVariant,
          infoMessage = _this$props.infoMessage,
          tooltipPosition = _this$props.tooltipPosition,
          asyncStatus = _this$props.asyncStatus,
          asyncStatusList = _this$props.asyncStatusList;
      var isInfoDetermined = ((0, _utils.determineAsyncStatus)({
        asyncStatus: asyncStatus,
        asyncStatusList: asyncStatusList
      }) || {}).isSuccessful && !list.length;
      return _react.default.createElement(_component.default, {
        isFormVariant: isFormVariant,
        isHeaderStretchWidth: isHeaderStretchWidth,
        isClick: isClick,
        isDisabled: isDisabled,
        isInfo: isInfoDetermined,
        activeItem: activeItem,
        isCloseOnSelect: isCloseOnSelect,
        isMenuHeaderWidth: isMenuHeaderWidth,
        isMenuHeaderWidthMin: isMenuHeaderWidthMin,
        isInWidget: isInWidget,
        domScrollSelector: domScrollSelector,
        fieldName: fieldName,
        onItemClick: onItemClick,
        asyncStatus: asyncStatus,
        asyncStatusList: asyncStatusList,
        className: className,
        renderHeader: function renderHeader(_ref) {
          var isOpen = _ref.isOpen,
              hasActiveItem = _ref.hasActiveItem,
              onClick = _ref.onClick;
          return _react.default.createElement(_component2.default, {
            isFormVariant: isFormVariant,
            isHeaderStretchWidth: isHeaderStretchWidth,
            isClick: isClick,
            isOpen: isOpen,
            activeItem: activeItem,
            hasActiveItem: hasActiveItem,
            placeholder: placeholder,
            onClick: onClick,
            isDisabled: isDisabled,
            isFloatErrorVariant: isFloatErrorVariant,
            isInfo: isInfoDetermined,
            infoMessage: infoMessage,
            tooltipPosition: tooltipPosition,
            asyncStatus: asyncStatus,
            asyncStatusList: asyncStatusList
          });
        },
        renderMenu: function renderMenu(_ref2) {
          var onClick = _ref2.onClick;
          return _react.default.createElement(_component3.default, {
            isIcon: isIcon,
            list: list,
            itemKey: itemKey,
            activeItem: activeItem,
            activeItems: activeItems,
            activeItemRaw: activeItemRaw,
            onClick: onClick
          });
        }
      });
    }
  }]);

  return VariantSimple;
}(_react.default.Component);

VariantSimple.propTypes = {
  isFormVariant: _propTypes.bool,
  isFloatErrorVariant: _propTypes.bool,
  isClick: _propTypes.bool,
  isDisabled: _propTypes.bool,
  isHeaderStretchWidth: _propTypes.bool,
  isMenuHeaderWidth: _propTypes.bool,
  isMenuHeaderWidthMin: _propTypes.bool,
  isIcon: _propTypes.bool,
  isCloseOnSelect: _propTypes.bool,
  isInWidget: _propTypes.bool,
  infoMessage: _propTypes.string,
  tooltipPosition: _propTypes.string,
  domScrollSelector: _propTypes.string,
  placeholder: _propTypes.string,
  list: _propTypes.array.isRequired,
  itemKey: _propTypes.string,
  activeItem: _propTypes.string,
  activeItems: _propTypes.array,
  activeItemRaw: (0, _propTypes.oneOfType)([_propTypes.string, _propTypes.number]),
  fieldName: _propTypes.string,
  onItemClick: _propTypes.func.isRequired,
  className: _propTypes.string,
  asyncStatus: (0, _propTypes.shape)(_utils.PROP_ASYNC_STATUS),
  asyncStatusList: (0, _propTypes.arrayOf)((0, _propTypes.shape)(_utils.PROP_ASYNC_STATUS))
};
VariantSimple.defaultProps = {
  isFormVariant: false,
  isFloatErrorVariant: false,
  isClick: false,
  isDisabled: false,
  isHeaderStretchWidth: false,
  isMenuHeaderWidth: false,
  isMenuHeaderWidthMin: false,
  isIcon: false,
  isCloseOnSelect: false,
  isInWidget: false,
  infoMessage: undefined,
  tooltipPosition: undefined,
  domScrollSelector: undefined,
  placeholder: undefined,
  itemKey: undefined,
  activeItem: undefined,
  activeItems: [],
  activeItemRaw: undefined,
  fieldName: undefined,
  className: undefined,
  asyncStatus: _utils.SHAPE_ASYNC_STATUS_INITIAL,
  asyncStatusList: []
};
var _default = VariantSimple;
exports.default = _default;