"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.LoadingSpinner = exports.LoadingSpinnerContainer = exports.StartEnhancer = exports.EndEnhancer = exports.BaseButton = void 0;

var _index = require("../styles/index.js");

var _constants = require("./constants.js");

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; }

var BaseButton = (0, _index.styled)('button', function (_ref) {
  var $theme = _ref.$theme,
      $size = _ref.$size,
      $kind = _ref.$kind,
      $shape = _ref.$shape,
      $isLoading = _ref.$isLoading,
      $isSelected = _ref.$isSelected,
      $disabled = _ref.$disabled;
  return _objectSpread({
    position: 'relative',
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    border: 'none',
    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
    },
    marginLeft: 0,
    marginTop: 0,
    marginRight: 0,
    marginBottom: 0
  }, getFontStyles({
    $theme: $theme,
    $size: $size
  }), getBorderRadiiStyles({
    $theme: $theme,
    $shape: $shape
  }), getPaddingStyles({
    $theme: $theme,
    $size: $size,
    $shape: $shape
  }), getKindStyles({
    $theme: $theme,
    $kind: $kind,
    $isLoading: $isLoading,
    $isSelected: $isSelected,
    $disabled: $disabled
  }));
});
exports.BaseButton = BaseButton;
BaseButton.displayName = "BaseButton";
var EndEnhancer = (0, _index.styled)('div', function (_ref2) {
  var $theme = _ref2.$theme;
  return {
    display: 'flex',
    marginLeft: $theme.sizing.scale500
  };
});
exports.EndEnhancer = EndEnhancer;
EndEnhancer.displayName = "EndEnhancer";
var StartEnhancer = (0, _index.styled)('div', function (_ref3) {
  var $theme = _ref3.$theme;
  return {
    display: 'flex',
    marginRight: $theme.sizing.scale500
  };
});
exports.StartEnhancer = StartEnhancer;
StartEnhancer.displayName = "StartEnhancer";
var LoadingSpinnerContainer = (0, _index.styled)('div', {
  // To center within parent
  position: 'absolute',
  left: '50%',
  top: '50%',
  transform: 'translate(-50%, -50%)'
});
exports.LoadingSpinnerContainer = LoadingSpinnerContainer;
LoadingSpinnerContainer.displayName = "LoadingSpinnerContainer";
var LoadingSpinner = (0, _index.styled)('div', function (_ref4) {
  var $theme = _ref4.$theme,
      $kind = _ref4.$kind,
      $disabled = _ref4.$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,
    borderTopLeftRadius: '50%',
    borderTopRightRadius: '50%',
    borderBottomRightRadius: '50%',
    borderBottomLeftRadius: '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)'
      }
    }
  };
});
exports.LoadingSpinner = LoadingSpinner;
LoadingSpinner.displayName = "LoadingSpinner";

function getLoadingSpinnerColors(_ref5) {
  var $theme = _ref5.$theme,
      $kind = _ref5.$kind,
      $disabled = _ref5.$disabled;
  return {
    foreground: $disabled ? $theme.colors.mono600 : $kind === _constants.KIND.primary ? $theme.colors.white : $theme.colors.primary,
    background: $disabled ? 'rgba(179, 179, 179, 0.32)' : $kind === _constants.KIND.primary ? 'rgba(255, 255, 255, 0.32)' : 'rgba(39, 110, 241, 0.32)'
  };
}

function getBorderRadiiStyles(_ref6) {
  var $theme = _ref6.$theme,
      $shape = _ref6.$shape;
  var value = $theme.borders.buttonBorderRadius;

  if ($shape === _constants.SHAPE.round) {
    value = '50%';
  }

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

function getFontStyles(_ref7) {
  var $theme = _ref7.$theme,
      $size = _ref7.$size;

  switch ($size) {
    case _constants.SIZE.compact:
      return $theme.typography.font450;

    case _constants.SIZE.large:
      return $theme.typography.font500;

    default:
      return $theme.typography.font470;
  }
}

function getPaddingStyles(_ref8) {
  var $theme = _ref8.$theme,
      $size = _ref8.$size,
      $shape = _ref8.$shape;
  var defaultShape = $shape === _constants.SHAPE.default;

  switch ($size) {
    case _constants.SIZE.compact:
      return {
        paddingTop: $theme.sizing.scale200,
        paddingBottom: $theme.sizing.scale200,
        paddingLeft: defaultShape ? $theme.sizing.scale500 : $theme.sizing.scale200,
        paddingRight: defaultShape ? $theme.sizing.scale500 : $theme.sizing.scale200
      };

    case _constants.SIZE.large:
      return {
        paddingTop: $theme.sizing.scale550,
        paddingBottom: $theme.sizing.scale550,
        paddingLeft: defaultShape ? $theme.sizing.scale700 : $theme.sizing.scale550,
        paddingRight: defaultShape ? $theme.sizing.scale700 : $theme.sizing.scale550
      };

    default:
      return {
        paddingTop: $theme.sizing.scale500,
        paddingBottom: $theme.sizing.scale500,
        paddingLeft: defaultShape ? $theme.sizing.scale600 : $theme.sizing.scale500,
        paddingRight: defaultShape ? $theme.sizing.scale600 : $theme.sizing.scale500
      };
  }
}

function getKindStyles(_ref9) {
  var $theme = _ref9.$theme,
      $isLoading = _ref9.$isLoading,
      $isSelected = _ref9.$isSelected,
      $kind = _ref9.$kind,
      $disabled = _ref9.$disabled;

  if ($disabled) {
    return {};
  }

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

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

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

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

    default:
      return {};
  }
}