'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var index = require('../../../../../../utils/index.js');
var Select_tokens = require('../../../../Select.tokens.js');
var Button_styles = require('./Button.styles.js');
var sizeToIconSize = require('../../../../utils/sizeToIconSize.js');
var getItemId = require('../../../../utils/getItemId.js');
var getButtonLabel = require('../../../../utils/getButtonLabel.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

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

exports.Button = Button;
