@use "sass:meta";
@use "sass:map";

@import "../settings/colours-palette";

////
/// @group helpers/colour
////

/// Get colour
///
/// @param {String | Colour} $colour - Name of colour from the colour palette
///   (`$ccs-colours`)
/// @return {Colour} Representation of named colour
///
/// @throw if `$colour` is not a colour from the colour palette
/// @access public

@function ccs-colour($colour, $variant: primary) {
  @if meta.type-of($colour) != "string" {
    $colour: "#{$colour}";
  }

  $colour-variants: map.get($_ccs-palette, $colour);

  // Some colours may not have variants, if that's the case, we can return the colour straight away
  @if meta.type-of($colour-variants) == "color" {
    @return $colour-variants;
  }

  @if meta.type-of($colour-variants) != "map" {
    @error "Colour `#{$colour}` should either be a `map` or `color`, not a `#{meta.type-of($colour-variants)}`";
  }

  $result: map.get($colour-variants, $variant);

  @if not $result {
    @error "Unknown variant `#{$variant}` for colour `#{$colour}` (available variants: #{map.keys($colour-variants)})";
  }

  @return $result;
}

/*# sourceMappingURL=_colour.scss.map */
