@use "sass:list";
@use "sass:map";
@use "@pepabo-inhouse/flavor/tokens";
@use "../helpers";
@use "../../error-message";

$background-color-tokens: map.get(
  map.get(tokens.$tokens, color),
  background
);

/// 汎用的に使えるbackground colorを取得します。
///
/// @group color
/// @example
///   functions.get-background-color($name: light, $type: well)
///   // ”f7f8fa”
@function get-background-color($name: light, $type: base) {
  $base-tokens: map.get($background-color-tokens, base);
  $brand-colors: brand, accent;

  $available-names:
    list.join(
      helpers.get-brightnesses(),
      $brand-colors,
      $separator: comma
    );
  $available-types: base, well;

  @if list.index($available-names, $name) == null {
    @error error-message.any-one-of(
      $value: $name,
      $available-values: $available-names
    );
  }

  @if list.index($available-types, $type) == null {
    @error error-message.any-one-of(
      $value: $type,
      $available-values: $available-types
    );
  }

  $name-tokens: map.get($base-tokens, $name);

  @if $name == light {
    @return map.get($name-tokens, $type);
  } @else {
    @if $type == well {
      @error error-message.exclusive(
        $value1: $name,
        $value2: $type
      );
    } @else {
      @return map.get($name-tokens, $type);
    }
  }
}

/// モーダルなオーバーレイなどで使うscrimのbackground colorを取得します。
///
/// @group color
/// @example
///   functions.get-scrim-background-color()
///   // ”rgba(0, 0, 0, 0.32)”
@function get-scrim-background-color() {
  @return map.get($background-color-tokens, scrim);
}
