@use 'mixins/mixins' as *;
@use 'mixins/var' as *;
@use 'common/var' as *;

@include b(badge) {
  @include set-component-var('badge', $badge);

  position: relative;
  vertical-align: middle;
  display: inline-block;
  width: fit-content;

  @include e(content) {
    background-color: getCssVar('badge', 'bg-color');
    border-radius: getCssVar('badge', 'radius');
    color: getColor('white');

    display: inline-flex;
    justify-content: center;
    align-items: center;

    font-size: getCssVar('badge', 'font-size');
    height: getCssVar('badge', 'size');
    padding: 0 getCssVar('badge', 'padding');
    white-space: nowrap;
    border: 1px solid getColor('bg-color');

    @include when(fixed) {
      position: absolute;
      top: 0;
      right: calc(1px + #{getCssVar('badge', 'size')} / 2);
      transform: translateY(-50%) translateX(100%);
      z-index: getCssVar('index', 'normal');

      @include when(dot) {
        right: 5px;
      }
    }

    @include when(dot) {
      height: 8px;
      width: 8px;
      padding: 0;
      right: 0;
      border-radius: 50%;
    }

    @include when(process) {
      &::before {
        content: ' ';
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        border-radius: inherit;
        animation: badge-wave-spread 2s getCssVar('badge', 'ripple-bezier') 1s
          infinite;
      }
    }

    @each $type in (primary, success, warn, info, danger) {
      @include m($type) {
        background-color: getColor($type);
        @include set-var-value(badge-ripple-color, getColor($type));
      }
    }
  }
}

@keyframes badge-wave-spread {
  from {
    box-shadow: 0 0 0.5px 0px getCssVar('badge-ripple-color');
    opacity: 0.6;
  }
  to {
    // don't use exact 5px since chrome will display the animation with glitches
    box-shadow: 0 0 0.5px 4.5px getCssVar('badge-ripple-color');
    opacity: 0;
  }
}
