@use 'sass:map';
@use 'sass:meta';

// ---------------------------------------------------------------- registry --
/// Tone registry.
/// @type Map
$badge-tone-map: (
  'primary': (
    token: 'accent',
    on: 'accent',
  ),
  'secondary': (
    token: 'text-muted',
    on: 'neutral-light',
  ),
  'success': (
    token: 'success',
    on: 'success',
  ),
  'danger': (
    token: 'error',
    on: 'error',
  ),
  'warning': (
    token: 'warn',
    on: 'warn',
  ),
  'info': (
    token: 'info',
    on: 'info',
  ),
  'light': (
    token: 'neutral-light',
    on: 'neutral-light',
  ),
  'dark': (
    token: 'neutral-dark',
    on: 'neutral-dark',
  ),
  'white': (
    token: 'neutral-light',
    on: 'neutral-light',
  ),
  'black': (
    token: 'neutral-dark',
    on: 'neutral-dark',
  ),
);

@each $name, $config in $badge-tone-map {
  @if meta.type-of($config) != 'map' {
    @error 'Badge tone `#{$name}` must be a map with `token` and `on`, got `#{meta.type-of($config)}`.';
  }

  @each $key in ('token', 'on') {
    @if not map.has-key($config, $key) {
      @error 'Badge tone `#{$name}` is missing the `#{$key}` key.';
    }
  }
}

// -------------------------------------------------------------------- base --
.badge {
  --bs-badge-font-size: 0.6875rem;
  --bs-badge-font-weight: 500;

  letter-spacing: 0.02em;
  border: 1px solid transparent;
}

// ------------------------------------------------------------------- tones --
@each $name, $config in $badge-tone-map {
  @include tone-badge($name, map.get($config, 'token'), map.get($config, 'on'));
}

// --------------------------------------------------------- surface pairing --
@each $name, $config in $badge-tone-map {
  .bg-#{$name},
  .text-bg-#{$name} {
    @include tone-ink(map.get($config, 'on'));
  }
}

.text-bg-white {
  background-color: var(--ui-neutral-light) !important;
}

.text-bg-black {
  background-color: var(--ui-neutral-dark) !important;
}
