@import './shadows';
@import './state';

@mixin BtnColor(
  $background-color: $button-base-background-color,
  $border-color: $button-base-border-color,
  $color: $button-base-text-color
) {
  // Color Variants
  background-color: $background-color;
  border-color: $border-color;
  color: $color;

  // Add some contextual shadowing
  // @include shadow(1);

  // Maintain the same colors for both :hover and :active states
  // Also maintain the colors when parent is open
  @include hover {
    background-color: mix($background-color, $color, 94%);
    border-color: mix($border-color, $color, 94%);
  }

  &:active,
  &.active {
    background-color: mix($background-color, $color, 90%);
    border-color: mix($border-color, $color, 90%);

    @if $background-color == transparent {
      @include focus-shadow($color);
    } @else if $background-color == $white {
      @include focus-shadow($color);
    } @else {
      @include focus-shadow($background-color);
    }
  }

  // We don't want the normal outline, we have a custom one.
  @include focus {
    @if $background-color == transparent {
      @include focus-shadow($color);
    } @else if $background-color == $white {
      @include focus-shadow($color);
    } @else {
      @include focus-shadow($background-color);
    }
    outline: 0;
  }

  &:disabled,
  &[disabled],
  &.disabled {
    cursor: not-allowed;
    opacity: 0.5;

    background-color: $background-color;
    border-color: $border-color;
    color: $color;
  }

  // Make sure the color and text-decoration stays consistent across everything.
  &,
  &:hover,
  &.hover,
  &:active,
  &.active,
  &:disabled,
  &[disabled],
  &.disabled,
  &:focus,
  &.focus {
    text-decoration: none;
    color: $color;
  }
}

@mixin Btn {
  // Type
  font-family: $button-font-family;
  font-size: $button-font-size;
  padding: $button-padding;
  white-space: nowrap;
  line-height: 1;

  font-weight: $button-font-weight;
  text-transform: uppercase;
  letter-spacing: 0.75px;
  display: inline-block;
  text-align: center;
  user-select: none;
  cursor: pointer;

  // Borders
  border-radius: $button-border-radius;
  border: $border;

  // Transitions & Hardware Acceleration
  transition-property: box-shadow, transform, background-color;
  will-change: box-shadow, transform, background-color;
  transition: 125ms;

  // Browser Engine Defaults
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-font-smoothing: antialiased;
  appearance: none;

  // Push the button down
  &:focus,
  &.focus,
  &:active,
  &.active {
    @include focus-shadow;
  }

  @include BtnColor;

  @each $state, $color in $states {
    @include state($state) {
      @include BtnColor($color, $color, _text-set($color));
    }
    &Text#{$state} {
      @include BtnColor(transparent, transparent, $color);
    }
  }
}

@mixin BtnSmall {
  font-weight: $font-weight-semibold;
  font-size: $font-size-xs;
  padding: 0.375rem 0.5rem;
}

@mixin BtnLarge {
  font-weight: $font-weight-bold;
  font-size: $font-size-base;
  padding: 0.75rem 1rem;
}
