function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(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) 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';
import { KIND, SIZE, SHAPE } from './constants';
export var BaseButton = styled('button', function (_ref) {
  var $theme = _ref.$theme,
      $size = _ref.$size,
      $colors = _ref.$colors,
      $kind = _ref.$kind,
      $shape = _ref.$shape,
      $isLoading = _ref.$isLoading,
      $isSelected = _ref.$isSelected,
      $disabled = _ref.$disabled,
      $isFocusVisible = _ref.$isFocusVisible;
  return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
    display: 'inline-flex',
    // need to maintain button width while showing loading spinner
    flexDirection: $isLoading ? 'column' : 'row',
    alignItems: 'center',
    justifyContent: 'center',
    borderLeftWidth: 0,
    borderTopWidth: 0,
    borderRightWidth: 0,
    borderBottomWidth: 0,
    borderLeftStyle: 'none',
    borderTopStyle: 'none',
    borderRightStyle: 'none',
    borderBottomStyle: 'none',
    outline: 'none',
    boxShadow: $isFocusVisible ? "inset 0 0 0 3px ".concat($theme.colors.borderAccent) : 'none',
    textDecoration: 'none',
    WebkitAppearance: 'none',
    transitionProperty: 'background',
    transitionDuration: $theme.animation.timing200,
    transitionTimingFunction: $theme.animation.linearCurve,
    cursor: 'pointer',
    ':disabled': _objectSpread({
      cursor: 'not-allowed'
    }, getDisabledStyles({
      $theme: $theme,
      $kind: $kind,
      $disabled: $disabled,
      $isSelected: $isSelected
    })),
    marginLeft: 0,
    marginTop: 0,
    marginRight: 0,
    marginBottom: 0
  }, getFontStyles({
    $theme: $theme,
    $size: $size
  })), getBorderRadiiStyles({
    $theme: $theme,
    $size: $size,
    $shape: $shape
  })), getPaddingStyles({
    $theme: $theme,
    $size: $size,
    $shape: $shape
  })), getColorStyles({
    $theme: $theme,
    $colors: $colors,
    $kind: $kind,
    $isLoading: $isLoading,
    $isSelected: $isSelected,
    $disabled: $disabled
  })), getShapeStyles({
    $shape: $shape,
    $size: $size
  }));
});
BaseButton.displayName = "BaseButton";
BaseButton.displayName = 'BaseButton';
export var EndEnhancer = styled('div', function (_ref2) {
  var $theme = _ref2.$theme;
  var marginDirection = $theme.direction === 'rtl' ? 'marginRight' : 'marginLeft';
  return _defineProperty({
    display: 'flex'
  }, marginDirection, $theme.sizing.scale300);
});
EndEnhancer.displayName = "EndEnhancer";
EndEnhancer.displayName = 'EndEnhancer';
export var StartEnhancer = styled('div', function (_ref4) {
  var $theme = _ref4.$theme;
  var marginDirection = $theme.direction === 'rtl' ? 'marginLeft' : 'marginRight';
  return _defineProperty({
    display: 'flex'
  }, marginDirection, $theme.sizing.scale300);
});
StartEnhancer.displayName = "StartEnhancer";
StartEnhancer.displayName = 'StartEnhancer';
export var LoadingSpinnerContainer = styled('div', function (_ref6) {
  var $theme = _ref6.$theme,
      $size = _ref6.$size;
  // we don't have a theming value for this
  var margins = '3px';

  if ($size === SIZE.mini || $size === SIZE.compact) {
    margins = $theme.sizing.scale0;
  }

  if ($size === SIZE.large) {
    margins = $theme.sizing.scale100;
  }

  return {
    lineHeight: 0,
    position: 'static',
    marginBottom: margins,
    marginTop: margins
  };
});
LoadingSpinnerContainer.displayName = "LoadingSpinnerContainer";
LoadingSpinnerContainer.displayName = 'LoadingSpinnerContainer';
export var LoadingSpinner = styled('span', function (_ref7) {
  var $theme = _ref7.$theme,
      $kind = _ref7.$kind,
      $disabled = _ref7.$disabled,
      $size = _ref7.$size;

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

  var dimension = $theme.sizing.scale550;

  if ($size === SIZE.mini || $size === SIZE.compact) {
    dimension = $theme.sizing.scale500;
  }

  if ($size === SIZE.large) {
    dimension = $theme.sizing.scale600;
  }

  return {
    height: dimension,
    width: dimension,
    borderTopLeftRadius: '50%',
    borderTopRightRadius: '50%',
    borderBottomRightRadius: '50%',
    borderBottomLeftRadius: '50%',
    borderLeftStyle: 'solid',
    borderTopStyle: 'solid',
    borderRightStyle: 'solid',
    borderBottomStyle: 'solid',
    borderLeftWidth: $theme.sizing.scale0,
    borderTopWidth: $theme.sizing.scale0,
    borderRightWidth: $theme.sizing.scale0,
    borderBottomWidth: $theme.sizing.scale0,
    borderTopColor: foreground,
    borderLeftColor: background,
    borderBottomColor: background,
    borderRightColor: background,
    boxSizing: 'border-box',
    display: 'inline-block',
    animationDuration: $theme.animation.timing700,
    animationTimingFunction: 'linear',
    animationIterationCount: 'infinite',
    animationName: {
      to: {
        transform: 'rotate(360deg)'
      },
      from: {
        transform: 'rotate(0deg)'
      }
    }
  };
});
LoadingSpinner.displayName = "LoadingSpinner";
LoadingSpinner.displayName = 'LoadingSpinner'; // @ts-ignore

function getLoadingSpinnerColors(_ref8) {
  var $theme = _ref8.$theme,
      $kind = _ref8.$kind,
      $disabled = _ref8.$disabled;

  if ($disabled) {
    return {
      foreground: $theme.colors.buttonDisabledSpinnerForeground,
      background: $theme.colors.buttonDisabledSpinnerBackground
    };
  }

  switch ($kind) {
    case KIND.secondary:
      {
        return {
          foreground: $theme.colors.buttonSecondarySpinnerForeground,
          background: $theme.colors.buttonSecondarySpinnerBackground
        };
      }

    case KIND.tertiary:
      {
        return {
          foreground: $theme.colors.buttonTertiarySpinnerForeground,
          background: $theme.colors.buttonTertiarySpinnerBackground
        };
      }

    case KIND.primary:
    default:
      {
        return {
          foreground: $theme.colors.buttonPrimarySpinnerForeground,
          background: $theme.colors.buttonPrimarySpinnerBackground
        };
      }
  }
} // @ts-ignore


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

  if ($shape === SHAPE.pill) {
    if ($size === SIZE.compact) {
      value = '30px';
    } else if ($size === SIZE.large) {
      value = '42px';
    } else {
      value = '38px';
    }
  } else if ($shape === SHAPE.circle || $shape === SHAPE.round) {
    value = '50%';
  } else if ($size === SIZE.mini) {
    value = $theme.borders.buttonBorderRadiusMini;
  }

  return {
    borderTopRightRadius: value,
    borderBottomRightRadius: value,
    borderTopLeftRadius: value,
    borderBottomLeftRadius: value
  };
} // @ts-ignore


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

  switch ($size) {
    case SIZE.mini:
      return $theme.typography.font150;

    case SIZE.compact:
      return $theme.typography.font250;

    case SIZE.large:
      return $theme.typography.font450;

    default:
      return $theme.typography.font350;
  }
} // @ts-ignore


function getDisabledStyles(_ref11) {
  var $theme = _ref11.$theme,
      $kind = _ref11.$kind,
      $isSelected = _ref11.$isSelected,
      $disabled = _ref11.$disabled;

  if ($disabled && $isSelected) {
    if ($kind === KIND.primary || $kind === KIND.secondary) {
      return {
        color: $theme.colors.buttonDisabledActiveText,
        backgroundColor: $theme.colors.buttonDisabledActiveFill
      };
    } else if ($kind === KIND.tertiary) {
      return {
        backgroundColor: $theme.colors.buttonTertiaryDisabledActiveFill,
        color: $theme.colors.buttonTertiaryDisabledActiveText
      };
    }
  }

  return {
    backgroundColor: $kind === KIND.tertiary ? 'transparent' : $theme.colors.buttonDisabledFill,
    color: $theme.colors.buttonDisabledText
  };
} // @ts-ignore


function getPaddingStyles(_ref12) {
  var $theme = _ref12.$theme,
      $size = _ref12.$size,
      $shape = _ref12.$shape;
  var iconShape = $shape === SHAPE.square || $shape === SHAPE.circle || $shape === SHAPE.round;

  switch ($size) {
    case SIZE.mini:
      return {
        paddingTop: $theme.sizing.scale200,
        paddingBottom: $theme.sizing.scale200,
        paddingLeft: iconShape ? $theme.sizing.scale200 : $theme.sizing.scale300,
        paddingRight: iconShape ? $theme.sizing.scale200 : $theme.sizing.scale300
      };

    case SIZE.compact:
      return {
        paddingTop: $theme.sizing.scale400,
        paddingBottom: $theme.sizing.scale400,
        paddingLeft: iconShape ? $theme.sizing.scale400 : $theme.sizing.scale500,
        paddingRight: iconShape ? $theme.sizing.scale400 : $theme.sizing.scale500
      };

    case SIZE.large:
      return {
        paddingTop: $theme.sizing.scale600,
        paddingBottom: $theme.sizing.scale600,
        paddingLeft: iconShape ? $theme.sizing.scale600 : $theme.sizing.scale700,
        paddingRight: iconShape ? $theme.sizing.scale600 : $theme.sizing.scale700
      };

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

function getColorStyles(_ref13) {
  var $theme = _ref13.$theme,
      $colors = _ref13.$colors,
      $isLoading = _ref13.$isLoading,
      $isSelected = _ref13.$isSelected,
      $kind = _ref13.$kind,
      $disabled = _ref13.$disabled;

  if ($colors) {
    return {
      color: $colors.color,
      backgroundColor: $colors.backgroundColor,
      ':hover': {
        boxShadow: 'inset 999px 999px 0px rgba(0, 0, 0, 0.04)'
      },
      ':active': {
        boxShadow: 'inset 999px 999px 0px rgba(0, 0, 0, 0.08)'
      }
    };
  }

  if ($disabled) {
    return Object.freeze({});
  }

  switch ($kind) {
    case KIND.primary:
      if ($isSelected) {
        return {
          color: $theme.colors.buttonPrimarySelectedText,
          backgroundColor: $theme.colors.buttonPrimarySelectedFill
        };
      }

      return {
        color: $theme.colors.buttonPrimaryText,
        backgroundColor: $theme.colors.buttonPrimaryFill,
        ':hover': {
          backgroundColor: $isLoading ? $theme.colors.buttonPrimaryActive : $theme.colors.buttonPrimaryHover
        },
        ':active': {
          backgroundColor: $theme.colors.buttonPrimaryActive
        }
      };

    case KIND.secondary:
      if ($isSelected) {
        return {
          color: $theme.colors.buttonPrimaryText,
          backgroundColor: $theme.colors.buttonPrimaryFill
        };
      }

      return {
        color: $theme.colors.buttonSecondaryText,
        backgroundColor: $theme.colors.buttonSecondaryFill,
        ':hover': {
          backgroundColor: $isLoading ? $theme.colors.buttonSecondaryActive : $theme.colors.buttonSecondaryHover
        },
        ':active': {
          backgroundColor: $theme.colors.buttonSecondaryActive
        }
      };

    case KIND.tertiary:
      if ($isSelected) {
        return {
          color: $theme.colors.buttonTertiarySelectedText,
          backgroundColor: $theme.colors.buttonTertiarySelectedFill
        };
      }

      return {
        color: $theme.colors.buttonTertiaryText,
        backgroundColor: $theme.colors.buttonTertiaryFill,
        ':hover': {
          backgroundColor: $isLoading ? $theme.colors.buttonTertiaryActive : $theme.colors.buttonTertiaryHover
        },
        ':active': {
          backgroundColor: $theme.colors.buttonTertiaryActive
        }
      };

    default:
      return Object.freeze({});
  }
} // @ts-ignore


function getShapeStyles(_ref14) {
  var $shape = _ref14.$shape,
      $size = _ref14.$size;

  if ($shape === SHAPE.circle || $shape === SHAPE.square) {
    var height, width;

    switch ($size) {
      case SIZE.mini:
        height = '28px';
        width = '28px';
        break;

      case SIZE.compact:
        height = '36px';
        width = '36px';
        break;

      case SIZE.large:
        height = '56px';
        width = '56px';
        break;

      case SIZE.default:
      default:
        height = '48px';
        width = '48px';
        break;
    }

    return {
      height: height,
      width: width,
      paddingTop: 0,
      paddingBottom: 0,
      paddingLeft: 0,
      paddingRight: 0
    };
  } else {
    return {};
  }
}