// @flow
import { css } from 'styled-components';
import type { ThemeProps } from '../../../types';
import type { StackeeProps } from '../../../mixins/stackee';
import { getPaletteColor } from '../../../mixins/branding';
import { getSpacingRules } from '../../../mixins/spacing';
import { getStackeeRules } from '../../../mixins/stackee';
import {
  getFontFamily,
  getFontWeight,
  getFontSize,
} from '../../../mixins/typography';
import {
  FOCUS_VISIBLE_SELECTOR,
  transitionInstant,
  getBaseFocusState,
  focusedBoxShadow,
  focusedBorderShadow,
  focusedBorderColor,
  activeBackgroundColor,
  hoverBackgroundColor,
} from '../../../mixins/focus';

const getBorderRadius = ({ theme }: ThemeProps) => theme.buttonBorderRadius;

const getMinWidth = ({ shrink }: StackeeProps) =>
  shrink == null ? '160px' : undefined;

export const commonStyles = css`
  && {
    display: inline-block;
    height: 48px;
    border-width: 0;
    padding: 0 20px;
    background: transparent;
    color: ${getPaletteColor('greyscale-dark')};
    min-width: ${getMinWidth};
    text-decoration: none;
    font-size: ${getFontSize};
    font-family: ${getFontFamily};
    font-weight: ${getFontWeight};
    border-radius: ${getBorderRadius};
    ${getBaseFocusState({ activeTransition: false })}
  }
  ${FOCUS_VISIBLE_SELECTOR} {
    transition: ${transitionInstant};
    box-shadow: ${focusedBoxShadow},
      ${focusedBorderShadow} ${focusedBorderColor};
  }

  &[disabled] {
    &:hover {
      cursor: default;
      background-color: transparent;
    }
    color: ${getPaletteColor('greyscale-medium')};
  }
`;

export const buttonStyles = css`
  line-height: 100%;
  &&& {
    ${getSpacingRules}
  }
  ${getStackeeRules};

  &:enabled:hover {
    background-color: ${hoverBackgroundColor};
  }

  &:enabled:active {
    background-color: ${activeBackgroundColor};
  }
`;

export const linkStyles = css`
  line-height: 48px;
  text-align: center;
  text-decoration: none;
  &&& {
    ${getSpacingRules}
  }
  ${getStackeeRules};

  &:hover {
    background-color: ${hoverBackgroundColor};
  }
  &:active {
    background-color: ${activeBackgroundColor};
  }
`;
