// Button variants
//
// Easily pump out default styles, as well as :hover, :focus, :active,
// and disabled options for all buttons

@mixin button-variant($background, $border, $hover-background: darken($background, 7.5%), $hover-border: darken($border, 10%), $active-background: darken($background, 10%), $active-border: darken($border, 12.5%)) {

  // store submitted background
  $submitted-bg: $background;
  $color: $background;

  // override light button
  @if($submitted-bg == $light) {
    $background: transparent;
    $color: transparent;
    $border: $white;
    $hover-background: $white;
    $hover-border: $white;
    $active-background: rgba($white,.65);
    $active-border: $white;
  }

  // override dark button
  @if($submitted-bg == $dark) {
    $background: transparent;
    $color: $light;
    $border: $dark;
    $hover-background: $dark;
    $hover-border: $dark;
    $active-background: rgba($dark,.65);
    $active-border: $dark;
  }

  // override danger button
  @if($submitted-bg == $danger) {
    $background: $red-dark;
    $color: $red-dark;
    $border: $red-dark;
    $hover-background: $red;
    $hover-border: $red;
    $active-background: $red-darker;
    $active-border: $red-darker;
  }

  @if($submitted-bg == $info) or  // override info button
    ($submitted-bg == $warning) or // override warning button
    ($submitted-bg == $success) or // override success button
    ($submitted-bg == $primary) // override primary button
  {
    $background: $blue-darker;
    $color: $blue-darker;
    $border: $blue-darker;
    $hover-background: $blue-dark;
    $hover-border: $blue-dark;
    $active-background: $blue-darker;
    $active-border: $blue-darker;
  }


  color: color-yiq($color);
  @include gradient-bg($background);
  border-color: $border;
  @include box-shadow($btn-box-shadow);

  @include hover {
    @if($submitted-bg == $light) {
      color: $black;
      background: $hover-background;
      border-color: $white !important;
    } @else {
      color: color-yiq($hover-background);
      @include gradient-bg($hover-background);
      border-color: $hover-border;
    }

  }

  &:focus,
  &.focus {
    color: color-yiq($hover-background);
    @include gradient-bg($hover-background);
    border-color: $hover-border;
    @if $enable-shadows {
      @include box-shadow($btn-box-shadow, 0 0 0 $btn-focus-width rgba(mix(color-yiq($background), $border, 15%), .5));
    } @else {
      // Avoid using mixin so we can pass custom focus shadow properly
      box-shadow: 0 0 0 $btn-focus-width rgba(mix(color-yiq($background), $border, 15%), .5);
    }
  }

  // Disabled comes first so active can properly restyle
  &.disabled,
  &:disabled {
    @if($submitted-bg == $light) {
      opacity: 0.5;
    } @else {
      background-color: $btn-disabled-color;
      border-color: $btn-disabled-color;
    }
    // Remove CSS gradients if they're enabled
    @if $enable-gradients {
      background-image: none;
    }

  }

  &:not([disabled]):not(.disabled):active,
  &:not([disabled]):not(.disabled).active,
  .show > &.dropdown-toggle {
    color: color-yiq($white); // color-yiq($active-background);
    background-color: transparent; // $active-background;
    @if $enable-gradients {
      background-image: none; // Remove the gradient for the pressed/active state
    }
    border-color: $active-border;

    &:focus {
      @if $enable-shadows and $btn-active-box-shadow != none {
        @include box-shadow($btn-active-box-shadow, 0 0 0 $btn-focus-width rgba(mix(color-yiq($background), $border, 15%), .5));
      } @else {
        // Avoid using mixin so we can pass custom focus shadow properly
        box-shadow: 0 0 0 $btn-focus-width rgba(mix(color-yiq($background), $border, 15%), .5);
      }
    }
  }

  &:not([disabled]):not(.disabled):active,
  &:not([disabled]):not(.disabled).active {
    color: color-yiq($active-background); //color: $white;
    background: $active-background;
  }
}

@mixin button-outline-variant($color, $color-hover: #fff) {
  // store submitted background
  $submitted-color: $color;
  $bg-hover: $blue-dark;
  $active-bg: $blue-darker;
  $color: $blue-darker;
  $border-color: $blue-darker;

  // override danger button
  @if($submitted-color == $danger) {
    $color: $red-dark;
    $bg-hover: $red;
    $active-bg: $red-darker;
    $border-color: $red-dark;
  }

  color: $color;
  background-color: transparent;
  background-image: none;
  border-color: $border-color;

  @include hover() {
    color: $color-hover;
    background-color: $bg-hover; // $color;
    border-color: $bg-hover; // $color;
  }

  &:focus,
  &.focus {
    box-shadow: 0 0 0 $input-btn-focus-width rgba($color, .5);
  }

  &.disabled,
  &:disabled {
    color: $btn-disabled-color;
    background-color: transparent;
    border-color: $btn-disabled-color;
  }

  &:not([disabled]):not(.disabled):active,
  &:not([disabled]):not(.disabled).active,
  .show > &.dropdown-toggle {
    color: color-yiq($white); // $color-hover;
    background-color: transparent; // $color;
    border-color: $color;

    &:focus {
      @if $enable-shadows and $btn-active-box-shadow != none {
        @include box-shadow($btn-active-box-shadow, 0 0 0 $btn-focus-width rgba($color, .5));
      } @else {
        // Avoid using mixin so we can pass custom focus shadow properly
        box-shadow: 0 0 0 $btn-focus-width rgba($color, .5);
      }
    }
  }

  &:not([disabled]):not(.disabled):active,
  &:not([disabled]):not(.disabled).active {
    color: $white;
    background: $active-bg;
  }
}

// Button sizes
@mixin button-size($padding-y, $padding-x, $font-size, $line-height, $border-radius) {
  padding: $padding-y $padding-x;
  @include font-size($font-size);
  line-height: $line-height;
  // Manually declare to provide an override to the browser default
  @include border-radius($border-radius, 0);
}
