/*
 * Copyright (c) 2019-present Sonatype, Inc.
 * This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License 2.0 which accompanies this
 * distribution and is available at https://www.eclipse.org/legal/epl-2.0/.
 */
@use 'sass:math';
@use '../../scss-shared/nx-text-helpers';

@mixin counter-colors {
  @each $category in critical, severe, moderate, low, none, unspecified {
    &--#{$category} {
      background-color: var(--nx-color-threat-#{$category});
      color: var(--nx-color-threat-#{$category}-text);
    }
  }
}

.nx-small-threat-counter {
  $height: 25px;
  position: relative;
  border-radius: math.div($height, 2);
  font-size: var(--nx-font-size-s);
  font-weight: bold;
  height: $height;
  line-height: $height;
  padding-left: var(--nx-spacing-2x);
  padding-right: var(--nx-spacing-2x);
  text-align: center;

  &__category {
    //invisible but still read by the screenreader
    @include nx-text-helpers.visually-hidden;
  }

  @include counter-colors;

  // Used to set the width of the counter based on its max text content
  &__sizer {
    display: block;
    height: 0;
    overflow: hidden;
    visibility: hidden;
  }

  &--zero {
    background-color: var(--nx-color-small-threat-counter-zero-background);
    color: var(--nx-color-small-threat-counter-zero-text);
  }
}

.nx-small-threat-counter-container {
  display: inline-flex;
  gap: var(--nx-spacing-2x);
  margin-left: var(--nx-spacing-2x);
  margin-right: var(--nx-spacing-2x);

  &--no-max {
    display: inline-grid;
    grid-auto-columns: 1fr;
    grid-auto-flow: column;

    .nx-small-threat-counter {
      box-sizing: border-box;
      display: inline-block;
      text-align: center;
      width: 100%;

      // using the counter-colors mixin will override the zero styling in this use case
      @include counter-colors;
    }
  }
}
