"use strict";

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

var _styles = require("../styles");

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

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, _styles.styled)('button', function (_ref) {
  var $theme = _ref.$theme,
      $size = _ref.$size,
      $kind = _ref.$kind,
      $shape = _ref.$shape,
      $isLoading = _ref.$isLoading;
  return _objectSpread({
    position: 'relative'
  }, $size === _constants.SIZE.compact ? $theme.typography.font250 : $theme.typography.font350, {
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    border: 'none',
    borderRadius: $shape === _constants.SHAPE.round ? '50%' : $theme.borders.useRoundedCorners ? $theme.borders.radius200 : '0px',
    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
  }));
});
exports.BaseButton = BaseButton;
var EndEnhancer = (0, _styles.styled)('div', function (_ref2) {
  var $theme = _ref2.$theme;
  return {
    display: 'flex',
    marginLeft: $theme.sizing.scale500
  };
});
exports.EndEnhancer = EndEnhancer;
var StartEnhancer = (0, _styles.styled)('div', function (_ref3) {
  var $theme = _ref3.$theme;
  return {
    display: 'flex',
    marginRight: $theme.sizing.scale500
  };
});
exports.StartEnhancer = StartEnhancer;
var LoadingSpinnerContainer = (0, _styles.styled)('div', {
  // To center within parent
  position: 'absolute',
  left: '50%',
  top: '50%',
  transform: 'translate(-50%, -50%)'
});
exports.LoadingSpinnerContainer = LoadingSpinnerContainer;
var LoadingSpinner = (0, _styles.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,
    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)'
      }
    }
  };
});
exports.LoadingSpinner = 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 getStyleForShape(_ref6) {
  var $theme = _ref6.$theme,
      $shape = _ref6.$shape,
      $size = _ref6.$size;

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

    default:
      return {
        paddingTop: $size === _constants.SIZE.compact ? $theme.sizing.scale200 : $theme.sizing.scale300,
        paddingBottom: $size === _constants.SIZE.compact ? $theme.sizing.scale200 : $theme.sizing.scale300,
        paddingLeft: $theme.sizing.scale600,
        paddingRight: $theme.sizing.scale600
      };
  }
}

function getStyleForKind(_ref7) {
  var $theme = _ref7.$theme,
      $kind = _ref7.$kind,
      $isLoading = _ref7.$isLoading;

  switch ($kind) {
    case _constants.KIND.primary:
      return {
        color: $theme.colors.buttonPrimaryText,
        backgroundColor: $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 _constants.KIND.secondary:
      return {
        color: $theme.colors.buttonSecondaryText,
        backgroundColor: $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 _constants.KIND.tertiary:
      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 _constants.KIND.minimal:
      return {
        color: $theme.colors.buttonMinimalText,
        backgroundColor: $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 {};
  }
}