//
// Base styles
//

.btn {
  font-family: $btn-font-family;
  text-transform: uppercase;
  vertical-align: bottom;
  border: 0;
  box-shadow: $btn-box-shadow;
  font-weight: $btn-font-weight;
  @include button-size-mdb(
    $btn-padding-top,
    $btn-padding-right,
    $btn-padding-bottom,
    $btn-padding-left,
    $btn-font-size,
    $btn-line-height
  );

  &:hover {
    box-shadow: $btn-hover-box-shadow;
  }

  &:focus,
  &.focus {
    box-shadow: $btn-focus-box-shadow;
  }

  &:active,
  &.active {
    box-shadow: $btn-hover-box-shadow;

    &:focus {
      box-shadow: $btn-hover-box-shadow;
    }
  }

  &:disabled,
  &.disabled,
  fieldset:disabled & {
    box-shadow: $btn-box-shadow;
    border: 0;
  }

  .btn-check:focus + &,
  &:focus {
    outline: 0;
    box-shadow: $btn-focus-box-shadow;
  }
}

//
// Button block
//

.btn-block {
  display: block;
  width: 100%;

  // Vertically space out multiple block buttons
  + .btn-block {
    margin-top: $btn-block-spacing-y;
  }
}

//
// Outline option
//

[class*='btn-outline-'] {
  border-width: $btn-border-width;
  border-style: solid;
  box-shadow: none;
  @include button-outline-size-mdb(
    $btn-outline-padding-top,
    $btn-outline-padding-right,
    $btn-outline-padding-bottom,
    $btn-outline-padding-left
  );

  &:hover {
    box-shadow: none;
    text-decoration: none;
  }

  &:focus,
  &.focus {
    box-shadow: none;
    text-decoration: none;
  }

  &:active,
  &.active {
    box-shadow: none;

    &:focus {
      box-shadow: none;
    }
  }

  &:disabled,
  &.disabled,
  fieldset:disabled & {
    box-shadow: none;
  }

  &.btn-lg {
    @include button-outline-size-mdb(
      $btn-outline-padding-top-lg,
      $btn-outline-padding-right-lg,
      $btn-outline-padding-bottom-lg,
      $btn-outline-padding-left-lg
    );
  }

  &.btn-sm {
    @include button-outline-size-mdb(
      $btn-outline-padding-top-sm,
      $btn-outline-padding-right-sm,
      $btn-outline-padding-bottom-sm,
      $btn-outline-padding-left-sm
    );
  }
}

//
// Alternate buttons
//

@each $color, $value in $buttons {
  .btn-#{$color} {
    background-color: map-get($value, background-color);
    color: map-get($value, text-color);
    box-shadow: $btn-contextual-box-shadow map-get($value, shadow-color);

    &:hover,
    &:focus,
    &.focus {
      background-color: darken(map-get($value, background-color), 5%);
      color: map-get($value, text-color);
      box-shadow: $btn-contextual-box-shadow-state-first-part
          rgba(map-get($value, shadow-color), 0.3),
        $btn-contextual-box-shadow-state-second-part rgba(map-get($value, shadow-color), 0.2);
    }

    &:active,
    &.active {
      box-shadow: $btn-contextual-box-shadow-state-first-part
          rgba(map-get($value, shadow-color), 0.3),
        $btn-contextual-box-shadow-state-second-part rgba(map-get($value, shadow-color), 0.2);

      &:focus {
        box-shadow: $btn-contextual-box-shadow-state-first-part
            rgba(map-get($value, shadow-color), 0.3),
          $btn-contextual-box-shadow-state-second-part rgba(map-get($value, shadow-color), 0.2);
      }
    }

    .btn-check:checked + &,
    .btn-check:active + &,
    &:active,
    &.active,
    .show > &.dropdown-toggle {
      background-color: darken(map-get($value, background-color), 10%);
      color: map-get($value, text-color);

      &:focus {
        box-shadow: $btn-contextual-box-shadow-state-first-part
            rgba(map-get($value, shadow-color), 0.3),
          $btn-contextual-box-shadow-state-second-part rgba(map-get($value, shadow-color), 0.2);
      }
    }

    &:disabled,
    &.disabled {
      background-color: map-get($value, background-color);
      color: map-get($value, text-color);
      box-shadow: $btn-contextual-box-shadow map-get($value, shadow-color);
    }

    .btn-check:focus + &,
    &:focus {
      box-shadow: $btn-contextual-box-shadow-state-first-part
          rgba(map-get($value, shadow-color), 0.3),
        $btn-contextual-box-shadow-state-second-part rgba(map-get($value, shadow-color), 0.2);
    }
  }
}

.btn-secondary {
  box-shadow: none;

  &:hover,
  &:focus,
  &.focus {
    background-color: $btn-secondary-hover-focus-bgc;
    box-shadow: none;
  }

  &:active,
  &.active {
    box-shadow: none;

    &:focus {
      box-shadow: none;
    }
  }

  .btn-check:checked + &,
  .btn-check:active + &,
  &:active,
  &.active,
  .show > &.dropdown-toggle {
    background-color: $btn-secondary-active-bgc;

    &:focus {
      box-shadow: none;
    }
  }

  &:disabled,
  &.disabled {
    box-shadow: none;
  }

  .btn-check:focus + &,
  &:focus {
    box-shadow: none;
  }
}

//
// Alternate buttons outline
//

@each $color, $value in $buttons-outline {
  .btn-outline-#{$color} {
    color: map-get($value, text-color);
    border-color: map-get($value, border-color);

    &:hover {
      color: map-get($value, text-color);
      background-color: rgba(map-get($value, background-color), 0.02);
    }

    &:focus,
    &.focus {
      color: map-get($value, text-color);
      background-color: transparent;
    }

    &:active,
    &.active,
    &.dropdown-toggle.show {
      color: map-get($value, text-color);
      background-color: transparent;

      &:focus {
        box-shadow: none;
      }
    }

    &:disabled,
    &.disabled {
      color: map-get($value, text-color);
    }

    .btn-check:checked + &,
    .btn-check:active + & {
      color: map-get($value, text-color);
      border-color: map-get($value, border-color);
      background-color: rgba(map-get($value, background-color), 0.02);
    }
  }
}

//
// Button Sizes
//

.btn-lg {
  @include button-size-mdb(
    $btn-padding-top-lg,
    $btn-padding-right-lg,
    $btn-padding-bottom-lg,
    $btn-padding-left-lg,
    $btn-font-size-lg,
    $btn-line-height-lg
  );
}

.btn-sm {
  @include button-size-mdb(
    $btn-padding-top-sm,
    $btn-padding-right-sm,
    $btn-padding-bottom-sm,
    $btn-padding-left-sm,
    $btn-font-size-sm,
    $btn-line-height-sm
  );
}

// Link buttons
//
// Make a button look and behave like a link

.btn-link {
  box-shadow: none;
  text-decoration: none;
  color: $link-color;

  &:hover {
    box-shadow: none;
    text-decoration: none;
    background-color: $btn-link-bgc;
    color: $link-hover-color;
  }

  &:focus,
  &.focus {
    box-shadow: none;
    text-decoration: none;
    background-color: $btn-link-bgc;
    color: $link-hover-color;
  }

  &:active,
  &.active {
    box-shadow: none;
    background-color: $btn-link-bgc;
    color: $link-hover-color;

    &:focus {
      box-shadow: none;
      background-color: $btn-link-bgc;
      color: $link-hover-color;
    }
  }

  &:disabled,
  &.disabled,
  fieldset:disabled & {
    box-shadow: none;
    color: $link-color;
  }
}

//
// Rounded option
//

.btn-rounded {
  border-radius: $btn-rounded-border-radius;
}

//
// Floating option
//

.btn-floating,
[class*='btn-outline-'].btn-floating {
  border-radius: $btn-floating-border-radius;
  padding: 0;
  position: relative;
}

.btn-floating {
  width: $btn-floating-width;
  height: $btn-floating-height;

  .fas,
  .far,
  .fab {
    width: $btn-floating-icon-width;
    line-height: $btn-floating-icon-line-height;
  }

  &.btn-lg {
    width: $btn-floating-width-lg;
    height: $btn-floating-height-lg;

    .fas,
    .far,
    .fab {
      width: $btn-floating-icon-width-lg;
      line-height: $btn-floating-icon-line-height-lg;
    }
  }

  &.btn-sm {
    width: $btn-floating-width-sm;
    height: $btn-floating-height-sm;

    .fas,
    .far,
    .fab {
      width: $btn-floating-icon-width-sm;
      line-height: $btn-floating-icon-line-height-sm;
    }
  }
}

[class*='btn-outline-'].btn-floating {
  .fas,
  .far,
  .fab {
    width: $btn-outline-floating-icon-width;
    line-height: $btn-outline-floating-icon-line-height;
  }

  &.btn-lg {
    .fas,
    .far,
    .fab {
      width: $btn-outline-floating-icon-width-lg;
      line-height: $btn-outline-floating-icon-line-height-lg;
    }
  }

  &.btn-sm {
    .fas,
    .far,
    .fab {
      width: $btn-outline-floating-icon-width-sm;
      line-height: $btn-outline-floating-icon-line-height-sm;
    }
  }
}

//
// Fixed option
//

.fixed-action-btn {
  position: fixed;
  right: $fixed-action-btn-right;
  bottom: $fixed-action-btn-bottom;
  z-index: $zindex-fixed-action-button;
  display: flex;
  flex-flow: column-reverse nowrap;
  align-items: center;
  padding: $fixed-action-btn-padding-top 20px 20px 20px;
  margin-bottom: 0;
  height: auto;
  overflow: hidden;

  & > .btn-floating {
    position: relative;
    transform: scale(1.2);
    z-index: 10;
  }

  ul {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    padding: 0;
    margin: 0;
    margin-bottom: 0;
    text-align: center;
    opacity: 0;
    transition: transform 0.4s, opacity 0.4s;
    z-index: -1;

    li {
      z-index: 0;
      display: flex;
      margin-right: auto;
      margin-bottom: $fixed-action-btn-li-margin-bottom;
      margin-left: auto;

      &:first-of-type {
        margin-top: $fixed-action-btn-li-margin-bottom * 0.5;
      }
    }

    a {
      &.btn {
        opacity: 0;
        transition: opacity 0.4s ease-in;

        &.shown {
          opacity: 1;
        }
      }
    }
  }

  &.active ul {
    opacity: 1;
  }
}

.btn-tertiary {
  box-shadow: none;
  text-decoration: none;
  color: $link-color;
  padding-left: 0px;
  padding-right: 0px;

  &:hover,
  &:focus,
  &.focus {
    box-shadow: none;
    text-decoration: none;
    background-color: transparent;
    color: $link-hover-color;
  }

  &:active,
  &.active {
    box-shadow: none;
    background-color: transparent;
    color: $link-hover-color;

    &:focus {
      box-shadow: none;
      background-color: transparent;
    }
  }

  &:disabled,
  &.disabled,
  fieldset:disabled & {
    box-shadow: none;
    color: $link-color;
  }
}
