// Need to define the raw colors somewhere!
// stylelint-disable color-no-hex, function-max-empty-lines, value-list-max-empty-lines
$color-palette-data: (
  white: (
    base: #ffffff
  ),

  black: (
    base: #000000
  ),

  sky: (
    lighter: #f9fafb,
    light: #f4f6f8,
    base: #dfe3e8,
    dark: #c4cdd5
  ),

  ink: (
    lightest: #919eab,
    lighter: #637381,
    light: #454f5b,
    base: #212b36
  ),

  blue: (
    lighter: #ebf5fa,
    light: #b4e1fa,
    base: #007ace,
    dark: #084e8a,
    darker: #001429,
    text: #3e4e57
  ),

  green: (
    lighter: #e3f1df,
    light: #bbe5b3,
    base: #50b83c,
    dark: #108043,
    darker: #173630,
    text: #414f3e
  ),

  yellow: (
    lighter: #fcf1cd,
    light: #ffea8a,
    base: #eec200,
    dark: #9c6f19,
    darker: #573b00,
    text: #595130
  ),

  orange: (
    lighter: #fcebdb,
    light: #ffc58b,
    base: #f49342,
    dark: #c05717,
    darker: #4a1504,
    text: #594430
  ),

  red: (
    lighter: #fbeae5,
    light: #fead9a,
    base: #de3618,
    dark: #bf0711,
    darker: #330101,
    text: #583c35
  ),

  purple: (
    lighter: #f6f0fd,
    light: #e3d0ff,
    base: #9c6ade,
    dark: #50248f,
    darker: #230051,
    text: #50495a
  ),

  teal: (
    lighter: #e0f5f5,
    light: #b7ecec,
    base: #47c1bf,
    dark: #00848e,
    darker: #003135,
    text: #405352
  ),

  indigo: (
    lighter: #f4f5fa,
    light: #b3bcf5,
    base: #5c6ac4,
    dark: #202e78,
    darker: #000639,
    text: #3e4155
  )
);


/// Returns the color value for a given color name and group.
///
/// @param {String} $hue - The color's hue.
/// @param {String} $value - The darkness/lightness of the color. Defaults to base.
/// @param {Color} $for-background - The background color on which this color will
/// appear. Applies a multiply filter to ensure appropriate contrast.
/// @return {Color} The color value.

@function color($hue, $value: base, $for-background: null) {
  $fetched-color: map-get(map-get($color-palette-data, $hue), $value);

  @if map-has-key($color-palette-data, $fetched-color) {
    $fetched-color: map-get(map-get($color-palette-data, $fetched-color), $value);
  }

  @if $for-background != null {
    $fetched-color: color-multiply($fetched-color, $for-background);
  }

  @if type-of($fetched-color) == color {
    @return $fetched-color;
  } @else {
    @error 'Color `#{$hue} - #{$value}` not found. Available colors: #{available-names($color-palette-data)}';
  }
}


/// Darkens the foreground color by the background color. This is the same as the
/// “multiply” filter in graphics apps.
///
/// @param {Color} $foreground - The color to darken.
/// @param {Color} $background - The background to base darkening on.
/// @return {Color} The modified color.

@function color-multiply($foreground, $background: null) {
  @if $background == null {
    $background: #ffffff;
  }

  @return $foreground * $background / 255;
}

// stylelint-enable color-no-hex, function-max-empty-lines, value-list-max-empty-lines
