import React, { useRef } from 'react';
import { StyledSwitchOption } from './partials/StyledSwitchOption';
import { SwitchInput } from './partials/SwitchInput';
export var SwitchOption = function SwitchOption(_ref) {
  var label = _ref.label,
    value = _ref.value,
    isDisabled = _ref.isDisabled,
    name = _ref.name,
    id = _ref.id,
    isActive = _ref.isActive,
    onChange = _ref.onChange;
  var localRef = useRef(null);
  var handleKeyDown = function handleKeyDown(e) {
    var selectKeys = ['Enter', 'Spacebar', ' '];
    if (selectKeys.includes(e.key)) {
      var _localRef$current;
      e.preventDefault();
      (_localRef$current = localRef.current) === null || _localRef$current === void 0 ? void 0 : _localRef$current.click();
    }
  };
  return /*#__PURE__*/React.createElement(StyledSwitchOption, {
    htmlFor: "".concat(id, "-").concat(label),
    $isActive: isActive,
    $isDisabled: isDisabled,
    "aria-current": isActive,
    onKeyDown: handleKeyDown,
    tabIndex: 0
  }, label, /*#__PURE__*/React.createElement(SwitchInput, {
    ref: localRef,
    type: "radio",
    id: "".concat(id, "-").concat(label),
    name: name || id,
    value: value,
    onChange: onChange,
    disabled: isDisabled
  }));
};
SwitchOption.displayName = 'SwitchOption';