@use 'sass:map';
@use '../../../mx-core/src/base/colors';
@use '../../../mx-core/src/base/_opacity.scss' as op;

@mixin mx-text-badge-theme($theme) {
  $is-dark: map.get($theme, is-dark);
  $current-theme: colors.$mx-light;

  @if $is-dark == true {
    $current-theme: colors.$mx-dark;
  }

  $colorMap: (
    tertiary: (
      default: 'tertiary',
      on: 'onTertiary',
      container: 'tertiaryContainer',
      onContainer: 'onTertiaryContainer'
    ),
    secondary: (
      default: 'secondary',
      on: 'onSecondary',
      container: 'secondaryContainer',
      onContainer: 'onSecondaryContainer'
    ),
    error: (
      default: 'error',
      on: 'onError',
      container: 'errorContainer',
      onContainer: 'onErrorContainer'
    ),
    warning: (
      default: 'warning',
      on: 'onWarning',
      container: 'warningContainer',
      onContainer: 'onWarningContainer'
    ),
    info: (
      default: 'info',
      on: 'onInfo',
      container: 'infoContainer',
      onContainer: 'onInfoContainer'
    ),
    success: (
      default: 'success',
      on: 'onSuccess',
      container: 'successContainer',
      onContainer: 'onSuccessContainer'
    )
  );
  $typeList: 'filled', 'outlined', 'fresh';

  @each $color-name, $color in $colorMap {
    .mx-text-badge--color-#{$color-name} {
      @each $type in $typeList {
        &.mx-text-badge--#{$type} {
          @if $type == 'filled' {
            background-color: map.get($current-theme, map.get($color, default));
            color: map.get($current-theme, map.get($color, on));
          } @else if $type == 'outlined' {
            border-color: map.get($current-theme, map.get($color, default));
            background-color: map.get($current-theme, map.get($color, container));
            color: map.get($current-theme, map.get($color, onContainer));
          } @else if $type == 'fresh' {
            background-color: map.get($current-theme, map.get($color, container));
            color: map.get($current-theme, map.get($color, default));
          }
        }
      }
    }
  }

  .mx-text-badge--color-neutral {
    &.mx-text-badge--filled {
      background-color: map.get($current-theme, inverseSurface);
      color: map.get($current-theme, inverseOnSurface);
    }
    &.mx-text-badge--outlined {
      border-color: map.get($current-theme, outline);
      background-color: rgba(map.get($current-theme, inverseSurface), op.$opacity-12);
      color: map.get($current-theme, onSurface);
    }
    &.mx-text-badge--fresh {
      background-color: rgba(map.get($current-theme, inverseSurface), op.$opacity-12);
      color: map.get($current-theme, onSurfaceVariant);
    }
  }
}
