"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Trigger = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _ = require("..");
var _2 = require("../../..");
var _NormalizedElements = _interopRequireDefault(require("../../../common/NormalizedElements"));
var _excluded = ["children", "size", "hasError"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var StyledChevronDown8 = (0, _styledComponents.default)(_2.Icon.ChevronDown8).withConfig({
  displayName: "Trigger__StyledChevronDown8",
  componentId: "sc-1v04f2n-0"
})(["margin-left:auto;"]);
var CleanNormalizedButton = _react.default.forwardRef(function (props, ref) {
  return _react.default.createElement(_NormalizedElements.default.Button, _extends({
    ref: ref
  }, props));
});
var StyledButton = (0, _styledComponents.default)(CleanNormalizedButton).withConfig({
  displayName: "Trigger__StyledButton",
  componentId: "sc-1v04f2n-1"
})(["cursor:pointer;color:", ";box-sizing:border-box;padding:", "px ", "px;border:1px solid ", ";border-radius:", "px;height:", "px;width:100%;display:flex;align-items:center;background:", ";&:hover{border-color:", ";}&:focus-within,&:focus{border-color:", ";}&[disabled]{color:", ";background:", ";border-color:", ";cursor:not-allowed;", "{color:", ";}}"], function (_ref) {
  var theme = _ref.theme,
    $hasValue = _ref.$hasValue;
  return $hasValue ? theme.colorTokens.neutral.text_default : theme.colorTokens.neutral.text_weak;
}, function (_ref2) {
  var theme = _ref2.theme;
  return theme.spacing.unit(2.5);
}, function (_ref3) {
  var theme = _ref3.theme;
  return theme.spacing.unit(2);
}, function (_ref4) {
  var theme = _ref4.theme,
    $hasError = _ref4.$hasError;
  return $hasError ? theme.colorTokens.error.border_default : theme.colorTokens.neutral.border_default;
}, function (_ref5) {
  var theme = _ref5.theme;
  return theme.spacing.unit(1);
}, function (_ref6) {
  var theme = _ref6.theme,
    $size = _ref6.$size;
  return $size === 's' ? theme.spacing.unit(8) : theme.spacing.unit(10);
}, function (_ref7) {
  var theme = _ref7.theme;
  return theme.colorTokens.neutral.background_default;
}, function (_ref8) {
  var theme = _ref8.theme;
  return theme.colorTokens.neutral.border_hover;
}, function (_ref9) {
  var theme = _ref9.theme;
  return theme.colorTokens.action.border_default;
}, function (_ref10) {
  var theme = _ref10.theme;
  return theme.colorTokens.neutral.text_disabled;
}, function (_ref11) {
  var theme = _ref11.theme;
  return theme.colorTokens.neutral.background_disabled;
}, function (_ref12) {
  var theme = _ref12.theme;
  return theme.colorTokens.neutral.border_disabled;
}, StyledChevronDown8, function (_ref13) {
  var theme = _ref13.theme;
  return theme.colorTokens.neutral.icon_disabled;
});
var Trigger = exports.Trigger = (0, _react.forwardRef)(function (props, ref) {
  var children = props.children,
    size = props.size,
    hasError = props.hasError,
    rest = _objectWithoutProperties(props, _excluded);
  var _useSelect = (0, _.useSelect)(),
    getButtonProps = _useSelect.getButtonProps,
    value = _useSelect.value;
  return _react.default.createElement(StyledButton, _extends({
    $size: size,
    $hasError: hasError,
    $hasValue: !!value
  }, getButtonProps(), {
    ref: ref
  }, rest), children);
});