@use '../tokens/components';
@use '../tokens/elements';
@use '../functions/tokens';
@use '../mixins/color-scheme';

tokens.$default-map: components.$post-tag;

.tag:not(:where(pre .tag)) {
  display: inline-flex;
  align-items: center;
  border: tokens.get('tag-border-width') tokens.get('tag-border-style')
    tokens.get('tag-neutral-color-border');
  gap: tokens.get('tag-large-gap-inline');
  padding-inline: tokens.get('tag-large-padding-inline');
  height: tokens.get('tag-large-height');
  background-color: transparent;
  border-radius: tokens.get('tag-border-radius');
  font-size: tokens.get('tag-large-font-size');
  white-space: nowrap;
  color: tokens.get('tag-neutral-color-fg');
  font-weight: tokens.get('body-font-weight', elements.$post-body);
  vertical-align: top;

  img,
  svg {
    display: inline-block;
    vertical-align: text-bottom;
  }

  post-icon,
  img,
  svg,
  &:not(.tag-sm, :has(post-icon))::before {
    width: tokens.get('tag-large-icon-size');
    height: tokens.get('tag-large-icon-size');
  }

  &.tag-sm {
    gap: tokens.get('tag-small-gap-inline');
    padding-inline: tokens.get('tag-small-padding-inline');
    height: tokens.get('tag-small-height');
    font-size: tokens.get('tag-small-font-size');

    post-icon,
    img,
    svg,
    &:not(:has(post-icon))::before {
      width: tokens.get('tag-small-icon-size');
      height: tokens.get('tag-small-icon-size');
    }
  }

  @each $name in 'success', 'warning', 'error', 'info' {
    &.tag-#{$name} {
      @include color-scheme.set(light);
      background-color: tokens.get('tag-#{$name}-color-bg');
      color: tokens.get('tag-#{$name}-color-fg');
      border-color: tokens.get('tag-#{$name}-color-border');

      post-icon {
        color: tokens.get('tag-#{$name}-color-icon');
      }

      &:not(:has(post-icon))::before {
        content: '';
        background-image: var(--post-signal-icon-#{$name});
      }
    }
  }
}
