import React__default, { forwardRef } from 'react';
import { cx } from '../../../../../../utils/index.js';
import { classes } from '../../../../Select.tokens.js';
import { ButtonWrapper, StyledButton, IconArrowWrapper, StyledArrow, Label } from './Button.styles.js';
import { sizeToIconSize } from '../../../../utils/sizeToIconSize.js';
import { getItemId } from '../../../../utils/getItemId.js';
import { getButtonLabel } from '../../../../utils/getButtonLabel.js';

var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var opened = _ref.opened,
    value = _ref.value,
    valueToItemMap = _ref.valueToItemMap,
    onKeyDown = _ref.onKeyDown,
    label = _ref.label,
    size = _ref.size,
    disabled = _ref.disabled,
    renderValue = _ref.renderValue,
    treeId = _ref.treeId,
    activeDescendantItemValue = _ref.activeDescendantItemValue,
    multiselect = _ref.multiselect,
    isTargetAmount = _ref.isTargetAmount;
  var withArrowInverse = opened ? classes.arrowInverse : undefined;
  return /*#__PURE__*/React__default.createElement(ButtonWrapper, null, /*#__PURE__*/React__default.createElement(StyledButton, {
    ref: ref,
    stretching: "filled",
    onKeyDown: onKeyDown,
    className: opened ? classes.selectWithoutBoxShadow : undefined,
    disabled: disabled,
    contentRight: /*#__PURE__*/React__default.createElement(IconArrowWrapper, null, /*#__PURE__*/React__default.createElement(StyledArrow, {
      size: sizeToIconSize(size),
      color: "inherit",
      className: cx(classes.selectTargetArrow, withArrowInverse)
    })),
    role: "combobox",
    "aria-autocomplete": "list",
    "aria-controls": "".concat(treeId, "_tree_level_1"),
    "aria-expanded": opened,
    "aria-activedescendant": activeDescendantItemValue ? getItemId(treeId, activeDescendantItemValue) : '',
    "aria-label": label
  }, /*#__PURE__*/React__default.createElement(Label, null, getButtonLabel({
    value: value,
    valueToItemMap: valueToItemMap,
    label: label,
    renderValue: renderValue,
    multiselect: multiselect,
    isTargetAmount: isTargetAmount
  }))));
});

export { Button };
