import get from 'lodash/get';

import { ColorToken, ColorTokenRef, PropsWithTheme } from './types';

/**
 * Returns color that can be used inside styled-component.
 *
 * ```tsx
 * import styled from 'styled-components/macro';
 * import { color } from '../theme';
 *
 * const StyledDiv = styled.div`
 *   background-color: ${color("gray/50")};
 * `;
 * ```
 */
export function color(name: ColorTokenRef) {
  return (props: PropsWithTheme): ColorToken => get(props.theme, name.split('/'));
}
