@mixin btn-default {
  border-radius: 3px;
  font-size: $gl-font-size;
  font-weight: 400;
  padding: $gl-vert-padding $gl-btn-padding;

  &:focus,
  &:active {
    background-color: $btn-active-gray;
    box-shadow: $gl-btn-active-background;
  }
}

@mixin btn-middle {
  @include btn-default;
}

@mixin btn-outline($background, $text, $border, $hover-background, $hover-text, $hover-border, $active-background, $active-border) {
  background-color: $background;
  color: $text;
  border-color: $border;

  &:hover,
  &:focus {
    background-color: $hover-background;
    border-color: $hover-border;
    color: $hover-text;
  }

  &:active {
    background-color: $active-background;
    border-color: $active-border;
    color: $hover-text;
  }
}

@mixin btn-color($light, $border-light, $normal, $border-normal, $dark, $border-dark, $color) {
  background-color: $light;
  border-color: $border-light;
  color: $color;

  &:hover,
  &:focus {
    background-color: $normal;
    border-color: $border-normal;
    color: $color;
  }

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

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

  svg {

    path {
      fill: $color;
    }

    use {
      stroke: $color;
    }
  }
}

@mixin btn-green {
  @include btn-color($green-500, $green-600, $green-600, $green-700, $green-700, $green-800, $white-light);
}

@mixin btn-blue {
  @include btn-color($blue-500, $blue-600, $blue-600, $blue-700, $blue-700, $blue-800, $white-light);
}

@mixin btn-orange {
  @include btn-color($orange-500, $orange-600, $orange-600, $orange-700, $orange-700, $orange-800, $white-light);
}

@mixin btn-red {
  @include btn-color($red-500, $red-600, $red-600, $red-700, $red-700, $red-800, $white-light);
}

@mixin btn-gray {
  @include btn-color($gray-light, $border-gray-normal, $gray-normal, $border-gray-normal, $gray-dark, $border-gray-dark, $gl-text-color);
}

@mixin btn-white {
  @include btn-color($white-light, $border-color, $white-normal, $border-white-normal, $white-dark, $border-gray-dark, $gl-text-color);
}

@mixin btn-with-margin {
  margin-left: $btn-side-margin;
  float: left;

  &.inline {
    float: none;
  }

  &.btn-sm {
    margin-left: $btn-sm-side-margin;
  }

  &.btn-xs {
    margin-left: $btn-xs-side-margin;
  }
}

.btn {
  @include btn-default;
  @include btn-white;

  color: $gl-text-color;

  &:focus:active {
    outline: 0;
  }

  &.btn-small,
  &.btn-sm {
    padding: 4px 10px;
    font-size: 13px;
    line-height: 18px;
  }

  &.btn-xs {
    padding: 2px 5px;
  }

  &.btn-success,
  &.btn-new,
  &.btn-create,
  &.btn-save {
    @include btn-green;
  }

  &.btn-inverted {
    &.btn-success,
    &.btn-new,
    &.btn-create,
    &.btn-save {
      @include btn-outline($white-light, $green-600, $green-500, $green-500, $white-light, $green-600, $green-600, $green-700);
    }

    &.btn-remove {
      @include btn-outline($white-light, $red-500, $red-500, $red-500, $white-light, $red-600, $red-600, $red-700);
    }
  }

  &.btn-gray {
    @include btn-gray;
  }

  &.btn-info,
  &.btn-primary,
  &.btn-register {
    @include btn-blue;
  }

  &.btn-warning {
    @include btn-orange;
  }

  &.btn-close {
    @include btn-outline($white-light, $orange-600, $orange-500, $orange-500, $white-light, $orange-600, $orange-600, $orange-700);
  }

  &.btn-spam {
    @include btn-outline($white-light, $red-500, $red-500, $red-500, $white-light, $red-600, $red-600, $red-700);
  }

  &.btn-danger,
  &.btn-remove,
  &.btn-red {
    @include btn-red;
  }

  &.btn-cancel {
    float: right;
  }

  &.btn-reopen {
    /* should be same as parent class for now */
  }

  &.btn-grouped {
    @include btn-with-margin;
  }

  &.disabled {
    pointer-events: auto !important;
  }

  &[disabled] {
    pointer-events: none !important;
  }

  .fa-caret-down,
  .fa-chevron-down {
    margin-left: 5px;
  }

  &.dropdown-toggle {
    .fa-caret-down {
      margin-left: 3px;
    }
  }

  svg {
    height: 15px;
    width: 15px;
    position: relative;
    top: 2px;
  }

  svg,
  .fa {
    &:not(:last-child) {
      margin-right: 5px;
    }
  }
}

.btn-terminal {
  svg {
    height: 14px;
    width: 18px;
  }
}

.btn-lg {
  padding: 12px 20px;
}

.btn-transparent {
  color: $gl-text-color-secondary;
  background-color: transparent;
  border: 0;

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

.btn-block {
  width: 100%;
  margin: 0;
  margin-bottom: 15px;

  &.btn {
    padding: 6px 0;
  }
}

.btn-group {
  &.btn-grouped {
    @include btn-with-margin;
  }
}

.btn-clipboard {
  border: none;
  padding: 0 5px;
}

.input-group-btn {
  .btn {
    @include btn-middle;

    &:hover {
      outline: none;
    }

    &:active {
      outline: none;
    }

    &.btn-clipboard {
      padding-left: 15px;
      padding-right: 15px;
    }
  }

  .active {
    box-shadow: $gl-btn-active-background;

    border: 1px solid $border-gray-dark !important;
    background-color: $btn-active-gray-light !important;
  }
}

.btn-loading {
  &:not(.disabled) .fa {
    display: none;
  }

  .fa {
    margin-right: 5px;
  }
}

.btn-text-field {
  width: 100%;
  text-align: left;
  padding: 6px 16px;
  border-color: $border-color;
  color: $gray-darkest;
  background-color: $gray-light;

  &:hover,
  &:active,
  &:focus {
    cursor: text;
    box-shadow: none;
    border-color: lighten($dropdown-input-focus-border, 20%);
    color: $gray-darkest;
    background-color: $gray-light;
  }
}

.btn-build {
  margin-left: 10px;

  i {
    color: $gl-text-color-secondary;
  }
}

.clone-dropdown-btn a {
  color: $dropdown-link-color;

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

.btn-static {
  background-color: $gray-light !important;
  border: 1px solid $border-gray-normal;
  cursor: default;

  &:active {
    -moz-box-shadow: inset 0 0 0 $white-light;
    -webkit-box-shadow: inset 0 0 0 $white-light;
    box-shadow: inset 0 0 0 $white-light;
  }
}

.btn-inverted {
  &-secondary {
    @include btn-outline($white-light, $blue-500, $blue-500, $blue-500, $white-light, $blue-600, $blue-600, $blue-700);
  }
}

@media (max-width: $screen-xs-max) {
  .btn-wide-on-xs {
    width: 100%;
  }
}

.btn-blank {
  padding: 0;
  background: transparent;
  border: 0;

  &:focus {
    outline: 0;
  }
}
