// @flow
import { getPaletteColor } from '../../../mixins/branding';
import type { ThemeProps } from '../../../types';
import type { TagProps } from './tag.proptypes';

const BACKGROUND_COLORS = {
  secondary: 'brand-secondary-bg',
  primary: 'brand-primary-bg',
  success: 'success-bg',
  info: 'info-bg',
  error: 'error-bg',
  greyscale: 'greyscale-light',
};

const FOREGROUND_COLORS = {
  secondary: 'brand-secondary-fg',
  primary: 'brand-primary-fg',
  success: 'success-fg',
  info: 'info-fg',
  error: 'error-fg',
  greyscale: 'greyscale-black',
};

export const getBackground = ({
  theme,
  inverted,
  color,
}: TagProps & ThemeProps) => {
  if (color === undefined) {
    return getPaletteColor(
      inverted ? 'brand-secondary-dark' : BACKGROUND_COLORS.secondary,
    )({ theme });
  }

  return getPaletteColor(
    inverted ? FOREGROUND_COLORS[color] : BACKGROUND_COLORS[color],
  )({
    theme,
  });
};

export const getForegroundColor = ({
  theme,
  inverted,
  color,
}: TagProps & ThemeProps) => {
  if (color === undefined) {
    return getPaletteColor(inverted ? 'white' : FOREGROUND_COLORS.secondary)({
      theme,
    });
  }

  return getPaletteColor(
    inverted ? BACKGROUND_COLORS[color] : FOREGROUND_COLORS[color],
  )({
    theme,
  });
};
