function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import { styled } from '../styles/index.js';
import { KIND, SIZE, SHAPE } from './constants.js';

function getBorderRadii(_ref) {
  var $shape = _ref.$shape,
      $theme = _ref.$theme;
  var value = '0px';

  if ($shape === SHAPE.round) {
    value = '50%';
  } else if ($theme.borders.useRoundedCorners) {
    value = $theme.borders.radius200;
  }

  return {
    borderTopRightRadius: value,
    borderBottomRightRadius: value,
    borderTopLeftRadius: value,
    borderBottomLeftRadius: value
  };
}

export var BaseButton = styled('button', function (_ref2) {
  var $theme = _ref2.$theme,
      $size = _ref2.$size,
      $kind = _ref2.$kind,
      $shape = _ref2.$shape,
      $isLoading = _ref2.$isLoading,
      $isSelected = _ref2.$isSelected;
  return _objectSpread({
    position: 'relative'
  }, $size === SIZE.compact ? $theme.typography.font250 : $theme.typography.font450, {
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    border: 'none'
  }, getBorderRadii({
    $shape: $shape,
    $theme: $theme
  }), {
    textDecoration: 'none',
    outline: 'none',
    WebkitAppearance: 'none',
    transitionProperty: 'background',
    transitionDuration: $theme.animation.timing100,
    transitionTimingFunction: $theme.animation.easeOutCurve,
    cursor: 'pointer',
    ':disabled': {
      cursor: 'not-allowed',
      backgroundColor: $theme.colors.buttonDisabledFill,
      color: $theme.colors.buttonDisabledText
    }
  }, getStyleForShape({
    $theme: $theme,
    $shape: $shape,
    $size: $size
  }), getStyleForKind({
    $theme: $theme,
    $kind: $kind,
    $isLoading: $isLoading,
    $isSelected: $isSelected
  }));
});
BaseButton.displayName = "BaseButton";
export var EndEnhancer = styled('div', function (_ref3) {
  var $theme = _ref3.$theme;
  return {
    display: 'flex',
    marginLeft: $theme.sizing.scale500
  };
});
EndEnhancer.displayName = "EndEnhancer";
export var StartEnhancer = styled('div', function (_ref4) {
  var $theme = _ref4.$theme;
  return {
    display: 'flex',
    marginRight: $theme.sizing.scale500
  };
});
StartEnhancer.displayName = "StartEnhancer";
export var LoadingSpinnerContainer = styled('div', {
  // To center within parent
  position: 'absolute',
  left: '50%',
  top: '50%',
  transform: 'translate(-50%, -50%)'
});
LoadingSpinnerContainer.displayName = "LoadingSpinnerContainer";
export var LoadingSpinner = styled('div', function (_ref5) {
  var $theme = _ref5.$theme,
      $kind = _ref5.$kind,
      $disabled = _ref5.$disabled;

  var _getLoadingSpinnerCol = getLoadingSpinnerColors({
    $theme: $theme,
    $kind: $kind,
    $disabled: $disabled
  }),
      foreground = _getLoadingSpinnerCol.foreground,
      background = _getLoadingSpinnerCol.background;

  return {
    height: $theme.sizing.scale600,
    width: $theme.sizing.scale600,
    borderRadius: '50%',
    borderStyle: 'solid',
    borderWidth: $theme.sizing.scale0,
    borderTopColor: foreground,
    borderLeftColor: background,
    borderBottomColor: background,
    borderRightColor: background,
    animationDuration: $theme.animation.timing700,
    animationTimingFunction: 'linear',
    animationIterationCount: 'infinite',
    animationName: {
      to: {
        transform: 'rotate(360deg)'
      },
      from: {
        transform: 'rotate(0deg)'
      }
    }
  };
});
LoadingSpinner.displayName = "LoadingSpinner";
export function getLoadingSpinnerColors(_ref6) {
  var $theme = _ref6.$theme,
      $kind = _ref6.$kind,
      $disabled = _ref6.$disabled;
  return {
    foreground: $disabled ? $theme.colors.mono600 : $kind === KIND.primary ? $theme.colors.white : $theme.colors.primary,
    background: $disabled ? 'rgba(179, 179, 179, 0.32)' : $kind === KIND.primary ? 'rgba(255, 255, 255, 0.32)' : 'rgba(39, 110, 241, 0.32)'
  };
}
export function getStyleForShape(_ref7) {
  var $theme = _ref7.$theme,
      $shape = _ref7.$shape,
      $size = _ref7.$size;

  switch ($shape) {
    case SHAPE.round:
    case SHAPE.square:
      return {
        paddingTop: $size === SIZE.compact ? $theme.sizing.scale400 : $theme.sizing.scale500,
        paddingBottom: $size === SIZE.compact ? $theme.sizing.scale400 : $theme.sizing.scale500,
        paddingLeft: $size === SIZE.compact ? $theme.sizing.scale400 : $theme.sizing.scale500,
        paddingRight: $size === SIZE.compact ? $theme.sizing.scale400 : $theme.sizing.scale500
      };

    default:
      return {
        paddingTop: $size === SIZE.compact ? $theme.sizing.scale200 : $theme.sizing.scale300,
        paddingBottom: $size === SIZE.compact ? $theme.sizing.scale200 : $theme.sizing.scale300,
        paddingLeft: $theme.sizing.scale600,
        paddingRight: $theme.sizing.scale600
      };
  }
}
export function getStyleForKind(_ref8) {
  var $theme = _ref8.$theme,
      $isLoading = _ref8.$isLoading,
      $isSelected = _ref8.$isSelected,
      $kind = _ref8.$kind;

  switch ($kind) {
    case KIND.primary:
      return {
        color: $theme.colors.buttonPrimaryText,
        backgroundColor: $isSelected ? $theme.colors.buttonPrimaryHover : $theme.colors.buttonPrimaryFill,
        ':hover:enabled': {
          backgroundColor: $isLoading ? $theme.colors.buttonPrimaryActive : $theme.colors.buttonPrimaryHover
        },
        ':focus:enabled': {
          backgroundColor: $isLoading ? $theme.colors.buttonPrimaryActive : $theme.colors.buttonPrimaryHover
        },
        ':active:enabled': {
          backgroundColor: $theme.colors.buttonPrimaryActive
        }
      };

    case KIND.secondary:
      return {
        color: $theme.colors.buttonSecondaryText,
        backgroundColor: $isSelected ? $theme.colors.buttonSecondaryHover : $theme.colors.buttonSecondaryFill,
        ':hover:enabled': {
          backgroundColor: $isLoading ? $theme.colors.buttonSecondaryActive : $theme.colors.buttonSecondaryHover
        },
        ':focus:enabled': {
          backgroundColor: $isLoading ? $theme.colors.buttonSecondaryActive : $theme.colors.buttonSecondaryHover
        },
        ':active:enabled': {
          backgroundColor: $theme.colors.buttonSecondaryActive
        }
      };

    case KIND.tertiary:
      if ($isSelected) {
        return {
          color: $theme.colors.buttonTertiarySelectedText,
          backgroundColor: $theme.colors.buttonTertiarySelectedFill
        };
      } else {
        return {
          color: $theme.colors.buttonTertiaryText,
          backgroundColor: $theme.colors.buttonTertiaryFill,
          ':hover:enabled': {
            backgroundColor: $isLoading ? $theme.colors.buttonTertiaryActive : $theme.colors.buttonTertiaryHover
          },
          ':focus:enabled': {
            backgroundColor: $isLoading ? $theme.colors.buttonTertiaryActive : $theme.colors.buttonTertiaryHover
          },
          ':active:enabled': {
            backgroundColor: $theme.colors.buttonTertiaryActive
          }
        };
      }

    case KIND.minimal:
      return {
        color: $theme.colors.buttonMinimalText,
        backgroundColor: $isSelected ? $theme.colors.buttonMinimalHover : $theme.colors.buttonMinimalFill,
        ':hover:enabled': {
          backgroundColor: $isLoading ? $theme.colors.buttonMinimalActive : $theme.colors.buttonMinimalHover
        },
        ':focus:enabled': {
          backgroundColor: $isLoading ? $theme.colors.buttonMinimalActive : $theme.colors.buttonMinimalHover
        },
        ':active:enabled': {
          backgroundColor: $theme.colors.buttonMinimalActive
        }
      };

    default:
      return {};
  }
}