import { ThemeObject } from '../Theme';

/**
 *
 * @param color - only hex colors
 * @param transparencyForLightTheme 100% — 'FF' 95% — 'F2' 90% — 'E6' 85% — 'D9' 80% — 'CC' 75% — 'BF' 70% — 'B3' 65% — 'A6' 60% — '99' 55% — '8C' 50% — '80' (#80FFFFFF) 45% — '73' 40% — '66' 35% — '59' 30% — '4D' 25% — '40' 20% — '33' 15% — '26' 10% — '1A' 5% — '0D' 0% — '00'
 * @param transparencyForDarkTheme
 * @returns
 */

export const addTransparencyToColor = (
  color: string,
  theme: ThemeObject,
  transparencyForLightTheme: string,
  transparencyForDarkTheme: string
): string => {
  const isLightTheme = theme.type === 'light';
  const hexOpacity = isLightTheme ? transparencyForLightTheme : transparencyForDarkTheme;
  return `${color}${hexOpacity}`;
};

export const getColor = (
  theme: ThemeObject,
  color: keyof ThemeObject['pallet'],
  withOpacity = false,
  customColor?: string
): string => {
  const c = customColor ?? theme.pallet[color];
  return withOpacity ? addTransparencyToColor(c, theme, '16', '4D') : c;
};

export const getBackgroundColor = (
  theme: ThemeObject,
  color: keyof ThemeObject['background'],
  withOpacity = false,
  customColor?: string
): string => {
  const c = customColor ?? theme.background[color];
  return withOpacity ? addTransparencyToColor(c, theme, '16', '4D') : c;
};
