var _excluded = ["variant", "size", "iconPlacement", "delayLoadingSpinnerAnimation", "children", "onClick"];
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); }
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; }
import React from 'react';
import styled from 'styled-components';
import Button from '../BaseButton';
var isSecondary = function isSecondary(variant) {
  return variant === 'secondary';
};
var isNegative = function isNegative(variant) {
  return variant === 'negative';
};
var isTertiary = function isTertiary(variant) {
  return variant === 'tertiary';
};
var getButtonColor = function getButtonColor(variant, theme) {
  switch (variant) {
    case 'negative':
      return theme.color.pillButtonBackgroundNegative;
    case 'tertiary':
      return theme.color.pillButtonTertiary;
    default:
      return theme.color.link;
  }
};
var StyledPillButton = styled(Button).withConfig({
  displayName: "PillButton__StyledPillButton",
  componentId: "sc-1k1bsl3-0"
})(["border-radius:", ";border-color:transparent;", ";", ";", ";"], function (_ref) {
  var theme = _ref.theme;
  return theme.borderRadius(100);
}, function (p) {
  return (isSecondary(p.variant) || isNegative(p.variant)) && "background-color: ".concat(p.theme.color.background);
}, function (p) {
  return isTertiary(p.variant) && "background-color: ".concat(p.theme.color.pillButtonBackgroundTertiary);
}, function (p) {
  return (isSecondary(p.variant) || isNegative(p.variant) || isTertiary(p.variant)) && !p.disabled && "\n    color: ".concat(getButtonColor(p.variant, p.theme), ";\n    &:hover {\n      color:\n      ").concat(isNegative(p.variant) ? p.theme.color.pillButtonBackgroundNegativeHover : p.theme.color.pillButtonHoverSecondary, ";\n      ").concat(isTertiary(p.variant) ? "background-color: ".concat(p.theme.color.pillButtonBackgroundTertiary) : "background-color: ".concat(p.theme.color.background), ";\n    }\n    &:active {\n      color:\n      ").concat(isNegative(p.variant) ? p.theme.color.pillButtonBackgroundNegativeActive : p.theme.color.pillButtonActiveSecondary, ";\n       ").concat(isTertiary(p.variant) ? "background-color: ".concat(p.theme.color.pillButtonBackgroundTertiary) : "background-color: ".concat(p.theme.color.background), ";\n      }\n  ");
});
export var PillButton = React.forwardRef(function (props, ref) {
  var _props$variant = props.variant,
    variant = _props$variant === void 0 ? 'primary' : _props$variant,
    _props$size = props.size,
    size = _props$size === void 0 ? 's' : _props$size,
    _props$iconPlacement = props.iconPlacement,
    iconPlacement = _props$iconPlacement === void 0 ? 'left' : _props$iconPlacement,
    _props$delayLoadingSp = props.delayLoadingSpinnerAnimation,
    delayLoadingSpinnerAnimation = _props$delayLoadingSp === void 0 ? true : _props$delayLoadingSp,
    children = props.children,
    onClick = props.onClick,
    rest = _objectWithoutProperties(props, _excluded);
  var trackClick = function trackClick(e) {
    if (onClick) onClick(e);
  };
  return React.createElement(StyledPillButton, _extends({}, rest, {
    ref: ref,
    size: size,
    type: "button",
    onClick: trackClick,
    iconPlacement: iconPlacement,
    variant: variant,
    delayLoadingSpinnerAnimation: delayLoadingSpinnerAnimation
  }), children);
});
PillButton.displayName = 'Button.Pill';