import React, { useState } from 'react';
import classNames from 'classnames';
import { faChevronDown } from '@fortawesome/free-solid-svg-icons/faChevronDown';
import { FontAwesomeIcon } from '../font-awesome-icon';
import { useTranslation } from '../hooks/use-translation';
import { DROPDOWN_PLACEMENT_TYPES } from '../dropdown';
import { DropdownMenu } from '../dropdown-menu';
import { Button, ACCENT_TYPES } from '../button';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
  @midnight-gray-supported
  @alpine-light-supported
 */
function SplitButton({
  options,
  label,
  onDropdownSelect,
  className,
  buttonTestId,
  triggerButtonTestId,
  contentTestId = 'contentTestId',
  isDisabled = false,
  placement = DROPDOWN_PLACEMENT_TYPES.BOTTOM_START,
  buttonProps = {},
  triggerButtonProps = {},
  dropdownMenuContentProps = {},
  dropdownProps = {},
  buttonAccentType = ACCENT_TYPES.PRIMARY,
  isMultiLevel = false,
  onClick,
  hideDropdown = false
}) {
  const [isOpen, setIsOpen] = useState(false);
  const {
    t
  } = useTranslation();
  return /*#__PURE__*/_jsxs("div", {
    className: classNames('split-button-container', {
      'is-secondary': buttonAccentType === ACCENT_TYPES.SECONDARY
    }, className),
    children: [/*#__PURE__*/_jsx(Button, {
      testId: buttonTestId,
      id: buttonTestId,
      onClick: onClick,
      isDisabled: isDisabled || buttonProps.isDisabled,
      accentType: buttonAccentType,
      ...buttonProps,
      className: classNames(buttonProps.className, 'split-button-main'),
      children: label
    }), !hideDropdown && /*#__PURE__*/_jsx(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: classNames(triggerButtonProps.className, 'split-button-trigger', isOpen && 'expanded'),
      onClose: () => setIsOpen(false),
      onOpen: () => setIsOpen(true),
      triggerDynamicContentWrapperClassName: "",
      triggerDynamicContent: () => /*#__PURE__*/_jsx(FontAwesomeIcon, {
        icon: faChevronDown
      }),
      onSelect: onDropdownSelect
    })]
  });
}
export default SplitButton;