// COLORS


// ! Requires a `$colors` map
// .example_class {
//   color: color(color, shade);
// }
@function color($color, $shade: 'base') {

  @if not ( map-has-key($colors, $color) ) {
    @error "color: \"#{$color}\", does not exist in $colors map";
  }

  @if not ( map-has-key(map-get($colors, $color), $shade) ) {
    @error "color: \"#{$color}\", shade: \"#{$shade}\", does not exist in $colors map";
  }

  @return map-get(map-get($colors, $color), $shade);

}

// Lightness Difference
// calculates the percentage difference of a color
// from it's strongest sahde (50% lightness)
// Either it's a dark or light shade
@function lightness-difference($lightness) {

  @if $lightness > 50% {

    @return 1 - (($lightness - 50%) / 50%);

  } @else {

    @return 1 - (((100% - $lightness) - 50%) / 50%);

  }

}

// Calpha
// Extracts the maximum pigment out of a colors
// turns lightness or darkness into alpha
// lightness: 60% | 1 - 20% lightness different | alpha: 0.8
@function calpha($color) {

  $hue: hue($color);
  $saturation: saturation($color);
  $lightness: lightness($color);
  $alpha: lightness-difference($lightness);

  @return hsla($hue, $saturation, 50%, $alpha);

}



@mixin color($color, $shade: 'base') {

  color: color($color, $shade);

}

@mixin background-color($color, $shade: 'base') {

  background-color: color($color, $shade);

}
