// @flow
import type { ThemeProps } from '../../../types';
import { getPaletteColor } from '../../../mixins/branding';
import type { ProgressBarProps } from './progress-bar.proptypes';

export const getBackgroundColor = ({ theme }: ThemeProps) =>
  getPaletteColor('greyscale-light')({ theme });

export const getBarColor = ({
  theme,
  error = false,
}: {|
  ...ThemeProps,
  ...ProgressBarProps,
|}) => {
  if (error) {
    return getPaletteColor('error-fg')({ theme });
  }

  return getPaletteColor('brand-secondary-dark')({ theme });
};

export const getBarWidth = ({
  totalSteps,
  currentStep,
  quickProgress = false,
}: ProgressBarProps) => {
  let percentage = totalSteps ? (100 * currentStep) / totalSteps : 0;

  if (quickProgress) {
    const v = currentStep / totalSteps;
    percentage = (1 - (1 - v) * (1 - v)) * 100;
  }

  return `${percentage}%`;
};
