"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _faChevronDown = require("@fortawesome/free-solid-svg-icons/faChevronDown");
var _fontAwesomeIcon = require("../font-awesome-icon");
var _useTranslation = require("../hooks/use-translation");
var _dropdown = require("../dropdown");
var _dropdownMenu = require("../dropdown-menu");
var _button = require("../button");
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); }
/**
  @midnight-gray-supported
  @alpine-light-supported
 */
function SplitButton({
  options,
  label,
  onDropdownSelect,
  className,
  buttonTestId,
  triggerButtonTestId,
  contentTestId = 'contentTestId',
  isDisabled = false,
  placement = _dropdown.DROPDOWN_PLACEMENT_TYPES.BOTTOM_START,
  buttonProps = {},
  triggerButtonProps = {},
  dropdownMenuContentProps = {},
  dropdownProps = {},
  buttonAccentType = _button.ACCENT_TYPES.PRIMARY,
  isMultiLevel = false,
  onClick,
  hideDropdown = false
}) {
  const [isOpen, setIsOpen] = (0, _react.useState)(false);
  const {
    t
  } = (0, _useTranslation.useTranslation)();
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: (0, _classnames.default)('split-button-container', {
      'is-secondary': buttonAccentType === _button.ACCENT_TYPES.SECONDARY
    }, className),
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
      testId: buttonTestId,
      id: buttonTestId,
      onClick: onClick,
      isDisabled: isDisabled || buttonProps.isDisabled,
      accentType: buttonAccentType,
      ...buttonProps,
      className: (0, _classnames.default)(buttonProps.className, 'split-button-main'),
      children: label
    }), !hideDropdown && /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdownMenu.DropdownMenu, {
      isMultiLevel: isMultiLevel,
      options: options,
      placement: placement,
      contentTestId: contentTestId,
      dropdownProps: dropdownProps,
      dropdownMenuContentProps: dropdownMenuContentProps,
      footerOption: dropdownMenuContentProps.footerOption,
      triggerHideChevron: true,
      triggerTestId: triggerButtonTestId,
      isDisabled: isDisabled || triggerButtonProps.isDisabled,
      triggerAriaLabelText: t('Addition actions'),
      triggerAccentType: buttonAccentType,
      triggerClassName: (0, _classnames.default)(triggerButtonProps.className, 'split-button-trigger', isOpen && 'expanded'),
      onClose: () => setIsOpen(false),
      onOpen: () => setIsOpen(true),
      triggerDynamicContentWrapperClassName: "",
      triggerDynamicContent: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
        icon: _faChevronDown.faChevronDown
      }),
      onSelect: onDropdownSelect
    })]
  });
}
var _default = exports.default = SplitButton;