/// # Accessing Colors
/// @group colors


// Color
// -----
/// The primary function for
/// accessing colors in your palette,
/// or making adjustments on the fly.
///
/// This is more than a wrapper for `map-get($colors, $x)`.
/// It also handles internal color-references, recursion,
/// and functional color-adjustments.
/// It has access to the global `$colors` map by default,
/// but you can also pass in arbitrary color-palette maps as well.
///
/// @group colors
///
/// @parameter {string | list} $color -
///   The name of a color in your palette,
///   or a color description in the
///   [map configuration format](config.html).
///
/// @parameter {map} $palette [$colors] -
///   Optional map containing the source color-palette.
///   Defaults to the global `$colors` map.
///
/// @return {color} -
///   A calculated css-ready color,
///   based on your global color palette and adjustments.
///
/// @example scss
///   $colors: (
///     'background': #eee,
///     'text': #222,
///   );
///
///   html {
///     background: color('background');
///     color: color('text');
///   }
@function color(
  $color,
  $palette: $colors
) {
  // Parse arguments
  $color: map-get($palette, $color) or $color;
  $base: nth($color, 1);
  $adjust: if(length($color) > 1, nth($color, 2), ());

  // Recursive check
  $color: if(map-has-key($palette, $base), color($base, $palette), $base);

  // Adjustments
  @each $function, $value in $adjust {
    $function: _ac-color-get-function($function);
    $color: call($function, $color, $value...);
  }

  @return $color;
}
