"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; 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); }

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

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _segmentedControl = require("../segmented-control.proptypes");

var _segmentedControlItem = require("./segmented-control-item.css-rules");

var _focus = require("../../../../mixins/focus");

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var SegmentedControlButton = _styledComponents["default"].button.withConfig({
  displayName: "SegmentedControlButton",
  componentId: "sc-1frlm0k-0"
})(["&&{background-color:", ";color:", ";font-family:", ";font-weight:", ";font-size:", ";padding:0 15px;border:1px solid ", ";flex:1;line-height:40px;min-height:40px;", "}", "{box-shadow:", ",", " ", ";}&:first-child{border-top-left-radius:6px;border-bottom-left-radius:6px;}&:last-child{border-top-right-radius:6px;border-bottom-right-radius:6px;}&:hover{background-color:", ";transition:", ";}&:active{background:", ";transition:", ";}&:nth-child(n + 2){border-left:none;}"], _segmentedControlItem.getBackgroundColor, _segmentedControlItem.getColor, _segmentedControlItem.getLabelFontFamily, _segmentedControlItem.getLabelFontWeight, _segmentedControlItem.getLabelFontSize, _segmentedControlItem.getBorderColor, (0, _focus.getBaseFocusState)({
  hoverTransition: false,
  activeTransition: false,
  baseTransition: false
}), _focus.FOCUS_VISIBLE_SELECTOR, _focus.focusedBoxShadow, _focus.focusedBorderShadow, _focus.focusedBorderColor, _segmentedControlItem.getButtonHoverColor, _focus.transitionInstant, _segmentedControlItem.getButtonActiveColor, _focus.transitionInstant);

var SegmentedControlItem = function SegmentedControlItem(_ref) {
  var value = _ref.value,
      children = _ref.children;
  var segmentedControlValues = (0, _react.useContext)(_segmentedControl.SegmentedControlContext);
  var clickHandler = segmentedControlValues.onItemClick;
  var itemClickHandler = (0, _react.useCallback)(function () {
    return clickHandler(value);
  }, [value, clickHandler]);
  return /*#__PURE__*/_react["default"].createElement(SegmentedControlButton, {
    selected: segmentedControlValues.selectedValue === value,
    onClick: itemClickHandler,
    value: value
  }, children);
};

exports.SegmentedControlItem = SegmentedControlItem;
SegmentedControlItem.displayName = 'SegmentedControlItem';