@use './tokens.scss';

@mixin simulated-inset-border(
  $width: tokens.$bm-sem-border-width-focus,
  $color: tokens.$bm-sem-color-border-focus
) {
  box-shadow: 0 0 0 $width $color inset;
}

@mixin simulated-inset-outline(
  $width: tokens.$bm-sem-border-width-focus,
  $style: solid,
  $color: tokens.$bm-sem-color-border-focus,
  $offset: tokens.$bm-sem-size-focus-offset
) {
  outline-offset: $offset;
  outline: $width $style $color;
}

@mixin visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@mixin svg-icon($icon, $size: cover) {
  -webkit-mask-image: $icon;

  -webkit-mask-size: $size;

  -webkit-mask-position: center;
  -webkit-mask-repeat: no-repeat;

  mask-image: $icon;

  mask-size: $size;

  mask-position: center;
  mask-repeat: no-repeat;
}

// Cross-Browser Scrollbar Normalization Mixin
// Usage: @include normalize-scrollbar();
// Advanced usage: @include normalize-scrollbar(12px, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.6));

@mixin normalize-scrollbar(
  $width: 0.375rem,
  $thumb-color: tokens.$bm-sem-color-icon-secondary-inverse,
  //rgba(0, 0, 0, 0.2),
  $thumb-hover-color: rgba(0, 0, 0, 0.4),
  $track-color: transparent,
  $border-radius: tokens.$bm-sem-space-25,
  $gutter: stable
) {
  @supports selector(::-webkit-scrollbar) {
    /* Webkit customization for the complete solution */
    &::-webkit-scrollbar {
      width: $width;
    }

    &::-webkit-scrollbar-track {
      background: $track-color;
    }

    &::-webkit-scrollbar-thumb {
      background: $thumb-color;
      border-radius: 4px;
      transition: background 0.2s ease;
    }

    &::-webkit-scrollbar-thumb:hover {
      background: $thumb-hover-color;
    }

    &:hover {
      --safari-fix: ; /* This custom property forces Safari to re-render the scrollbars on hover */
    }
  }

  /* Modern approach for supporting browsers */
  scrollbar-gutter: $gutter;

  @supports (scrollbar-color: $thumb-color $track-color) {
    /* Firefox standardized properties */
    scrollbar-width: thin;
    scrollbar-color: $thumb-color $track-color;
  }
}
