"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ChooseV2 = void 0;
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _ButtonGroup = require("../ButtonGroup");
var _Choose = require("../Choose");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var StyledChoose = (0, _styledComponents.default)(_Choose.Choose).withConfig({
  displayName: "ChooseV2__StyledChoose",
  componentId: "sc-142e30o-0"
})(["", ""], function (props) {
  return !props.active && (0, _styledComponents.css)(["background-color:transparent !important;"]);
});
var ChooseV2 = exports.ChooseV2 = function ChooseV2(_ref) {
  var _ref$required = _ref.required,
    required = _ref$required === void 0 ? false : _ref$required,
    _ref$multiple = _ref.multiple,
    multiple = _ref$multiple === void 0 ? false : _ref$multiple,
    _ref$invalid = _ref.invalid,
    invalid = _ref$invalid === void 0 ? false : _ref$invalid,
    options = _ref.options,
    selected = _ref.selected,
    onChange = _ref.onChange;
  var handleSelect = function handleSelect(id) {
    if (multiple) {
      var newSelected = selected.includes(id) ? selected.filter(function (s) {
        return s !== id;
      }) : [...selected, id];
      if (required && newSelected.length === 0) {
        return;
      }
      onChange(newSelected);
    } else {
      if (required && selected.includes(id)) {
        return;
      }
      var _newSelected = selected.includes(id) ? [] : [id];
      onChange(_newSelected);
    }
  };
  return /*#__PURE__*/_react.default.createElement(_ButtonGroup.ButtonGroup, {
    invalid: invalid
  }, options.map(function (option) {
    return /*#__PURE__*/_react.default.createElement(StyledChoose, {
      key: option.id,
      active: selected.includes(option.id),
      disabled: option.disabled,
      onClick: function onClick() {
        return handleSelect(option.id);
      }
    }, option.name);
  }));
};
//# sourceMappingURL=ChooseV2.js.map