"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _checkbox = require("../checkbox");
var _types = require("./types");
var _hooks = require("../hooks");
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 }; }
const DropdownItemCheckbox = ({
  option,
  onChange,
  onCloseDropdown = () => {}
}) => {
  const {
    disabled,
    id,
    isChecked = false,
    title,
    testId,
    tooltipPlacement,
    tooltipText,
    subtext
  } = option;
  const {
    treeItemAttrs,
    ref: setRefCallback
  } = (0, _hooks.useTreeNodeNavigation)({
    id: option.privateKey || option.key,
    isSelected: isChecked,
    getKeyActionFn: _utils.getKeyActionFnMenu,
    onCustomButtonKeyDown: () => onCloseDropdown(),
    onToggleSelected: onChange,
    ignoreKeys: null
  });
  return (
    /*#__PURE__*/
    // div around Checkbox is needed to comply with the dropdown-item layout.
    // this way we can keep css simple and avoid overrides.
    (0, _jsxRuntime.jsx)(_dropdownItemTooltip.default, {
      option: option,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "checkbox-item",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_checkbox.Checkbox, {
          ref: setRefCallback,
          isTruncatable: true,
          id: id,
          testId: testId,
          isChecked: isChecked,
          onChange: onChange,
          labelText: title,
          subtext: subtext ? String(subtext) : undefined,
          isDisabled: disabled,
          tooltipPlacement: tooltipPlacement,
          onKeyDown: treeItemAttrs.onKeyDown,
          role: _types.MENU_ROLE.MENUITEMCHECKBOX,
          hasParentTooltip: !!tooltipText
        })
      })
    })
  );
};
var _default = exports.default = DropdownItemCheckbox;