// ** Two main functions for users **
// md-palette: used for defining your theme in terms of Material hues.
// md-color: apply colors to components from the palette. Consumes the output of md-palette

// Implement the rem unit with SCSS so we don't have to actually set a font-size on
// the user's body element.
@function rem($multiplier) {
  $font-size: 10px;
  @return $multiplier * $font-size;
}

// For a given hue in a palette, return the contrast color from the map of contrast palettes.
@function md-contrast($color-map, $hue, $contrast-color-map) {
  @return map-get(map-get($contrast-color-map, $color-map), $hue);
}


// Creates a map of hues to colors for a theme.
// $color-map
// $primary
// $lighter
// $darker
@function md-palette($color-map, $primary, $lighter, $darker, $contrast-color-map) {
  $result: map_merge($color-map, (
    default: map-get($color-map, $primary),
    lighter: map-get($color-map, $lighter),
    darker: map-get($color-map, $darker),

    default-contrast: md-contrast($color-map, $primary, $contrast-color-map),
    lighter-contrast: md-contrast($color-map, $lighter, $contrast-color-map),
    darker-contrast: md-contrast($color-map, $darker, $contrast-color-map)
  ));

  // For each hue in the palette, add a "-contrast" color to the map.
  @each $hue, $color in $color-map {
    $result: map_merge($result, (
      "#{$hue}-contrast": md-contrast($color-map, $hue, $contrast-color-map)
    ))
  }

  @return $result;
}

// Gets a color for a material design component.
// $color-map: a map of {key: color}.
// $hue-key: key used to lookup the color in $colorMap. Defaults to 'default'
//     If $hue-key is a number between 0 and 1, it will be treated as $opacity.
// $opacity: the opacity to apply to the color.
@function md-color($color-map, $hue-key: default, $opacity: 1) {
  // If hueKey is a number between zero and one, then it actually contains an
  // opacity value, so recall this function with the default hue and that given opacity.
  @if type-of($hue-key) == number and $hue-key >= 0 and $hue-key <= 1 {
    @return md-color($color-map, default, $hue-key)
  }

  $color: map-get($color-map, $hue-key);
  $opacity: if(opacity($color) < 1, opacity($color), $opacity);

  @return rgba($color, $opacity);
}


