@import "palette";

// Creates a map of hues to colors for a theme. This is used to define a theme palette
@function sam-palette(
  $base-palette,
  $default: 500,
  $lighter: 100,
  $darker: 700
) {
  $result: map_merge(
    $base-palette,
    (
      default: map-get($base-palette, $default),
      lighter: map-get($base-palette, $lighter),
      darker: map-get($base-palette, $darker),
    )
  );

  @return $result;
}

// Gets a color from a theme palette (the output of sam-palette).
// The hue can be one of the standard values (500, A400, etc.), or one of the three preconfigured
// hues (default, lighter, darker)".
//
// @param $color-map The theme palette (output of sam-palette).
// @param $hue The hue from the palette to use. If this is a value between 0 and 1, it will
//     be treated as opacity.
// @param $opacity The alpha channel value for the color.
@function sam-color($palette, $hue: default, $opacity: null) {
  // 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) == number and $hue >= 0 and $hue <= 1 {
    @return sam-color($palette, default, $hue);
  }

  $color: map-get($palette, $hue);
  $opacity: if($opacity == null, opacity($color), $opacity);

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

// Creates a container object for a light theme to be given to individual component theme mixins.
@function sam-theme($primary, $accent, $warn: sam-palette($uswds-red)) {
  @return (
    primary: $primary,
    accent: $accent,
    warn: $warn,
    foreground: $sam-theme-foreground,
    background: $sam-theme-background
  );
}
