"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DropdownItemRadioButton = void 0;
var _react = _interopRequireWildcard(require("react"));
var _types = require("./types");
var _hooks = require("../hooks");
var _radioButton = require("../radio-button");
var _utils = require("../hooks/use-tree-navigation/utils");
var _dropdownItemTooltip = _interopRequireDefault(require("./dropdown-item-tooltip"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (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 (const 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); }
const DropdownItemRadioButton = ({
  groupIdentifier,
  option,
  onChange,
  onCloseDropdown = () => {}
}) => {
  const {
    treeItemAttrs,
    ref: setRefCallback,
    node,
    isFirstFocusable,
    setFocused
  } = (0, _hooks.useTreeNodeNavigation)({
    id: option.privateKey || option.key,
    getKeyActionFn: _utils.getKeyActionFnMenu,
    onCustomButtonKeyDown: () => onCloseDropdown(),
    onToggleSelected: () => {
      onChange(option);
    },
    ignoreKeys: null
  });
  (0, _react.useEffect)(() => {
    if (isFirstFocusable) {
      setFocused(node.id);
    }
  }, [setFocused, isFirstFocusable]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdownItemTooltip.default, {
    option: option,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
      className: "drop-item radio-button",
      role: "none",
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_radioButton.RadioButton, {
        ref: setRefCallback,
        option: option,
        onSelect: () => onChange(option),
        checked: option.activeItemId === option.id,
        groupIdentifier: groupIdentifier,
        radioButtonRole: _types.MENU_ROLE.MENUITEMRADIO,
        onKeyDown: treeItemAttrs.onKeyDown
      }, option.key)
    })
  });
};
exports.DropdownItemRadioButton = DropdownItemRadioButton;