@use 'sass:map';
@use 'sass:color';

@use './../variables/components/button';
@use './../variables/type';
@use './../variables/color' as color-var;
@use 'utilities';
@use './../mixins/color' as color-mx;
@use '../functions/tokens';
@use '../tokens/components';

@mixin reset-button {
  padding: 0;
  overflow: visible;
  border: 0;
  background: none;
  color: tokens.get('button-secondary-enabled-fg', components.$post-button);
  font: inherit;
  -webkit-user-select: none;
          user-select: none;
  appearance: button; // for input

  @include utilities.high-contrast-mode() {
    background-color: ButtonFace !important;

    &:hover {
      background-color: Highlight !important;
    }
  }
}

@mixin button-base {
  // Resets
  display: inline-flex;
  position: relative;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  overflow: hidden;
  transition: button.$btn-transition;
  border-width: tokens.get('button-border-width', components.$post-button);
  border-style: solid;
  border-color: transparent;
  border-radius: tokens.get('button-border-radius-round', components.$post-button);
  background-color: transparent;
  box-shadow: none;
  font-family: inherit;
  font-size: tokens.get('button-font-size', components.$post-button);
  font-weight: tokens.get('button-label-font-weight', components.$post-button);
  text-decoration: none;
  white-space: nowrap; // Long content should never break in buttons
  cursor: pointer;

  &:not(:disabled):hover {
    text-decoration: none;
  }

  &:disabled {
    border-style: tokens.get('button-border-style-disabled', components.$post-button);
    cursor: unset;
  }

  @include utilities.focus-style;

  @include utilities.high-contrast-mode() {
    border-width: 1px !important;
    transition: none;

    &:is(button) {
      background-color: ButtonFace !important;
      border-color: ButtonBorder !important;
    }
  }
}

@mixin button-label-wrap {
  white-space: normal;
  overflow-wrap: anywhere;
  text-wrap: pretty;
  text-align: center;
}

@mixin button-size($size: md) {
  $height: map.get(button.$btn-height-map, $size);

  min-height: $height;
  gap: map.get(button.$btn-gap-x-map, $size);
  padding: 0 map.get(button.$btn-padding-x-map, $size);
  border-radius: calc(#{$height} / 2);

  > post-icon {
    width: map.get(button.$btn-icon-size-map, $size);
    height: map.get(button.$btn-icon-size-map, $size);
    flex-shrink: 0;
  }
}

@mixin button-variant-def($type, $color, $variant: '') {
  border-color: tokens.get('button-#{$color}-#{$type}-stroke', components.$post-button);
  color: tokens.get('button-#{$color}-#{$type}-fg', components.$post-button);

  @if ($variant != 'link') {
    background-color: tokens.get('button-#{$color}-#{$type}-bg', components.$post-button);
  }
}
