/**
 * Copyright (c) HashiCorp, Inc.
 * SPDX-License-Identifier: BUSL-1.1
 */

.button {
  align-items: center;
  background-color: $grey-lightest;
  border: 1px solid $grey-light;
  border-radius: $radius;
  box-shadow: $box-shadow-low;
  cursor: pointer;
  color: $ui-gray-800;
  display: inline-block;
  font-size: $size-8;
  font-weight: $font-weight-semibold;
  height: 2.5rem;
  line-height: 1.6;
  min-width: 6rem;
  padding: $size-10 $size-8;
  position: relative;
  text-align: center;
  text-decoration: none;
  transition: background-color $speed, border-color $speed, box-shadow $speed, color $speed;
  user-select: none;
  vertical-align: middle;
  white-space: nowrap;

  @keyframes spinAround {
    from {
      transform: rotate(0deg);
    }
    to {
      transform: rotate(359deg);
    }
  }

  &:active,
  &.is-active,
  &:focus {
    border-color: darken($grey-light, 10%);
    box-shadow: $button-box-shadow-standard;
    color: darken($grey-dark, 10%);
  }

  &:focus:not(:active) {
    box-shadow: 0 0 0 0.125em rgba(21, 99, 255, 0.25);
  }

  &:disabled {
    background-color: $white;
    border-color: $ui-gray-050;
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.5;
  }

  // Button types: is-compact, is-danger, is-danger-outlined, is-flat, is-ghost, is-icon, is-loading, is-link, is-outline, is-primary, is-transparent.

  &.is-compact {
    height: 2rem;
    padding: $size-11 $size-8;
  }

  &.is-danger {
    background-color: $red-500;
    border-color: darken($red-500, 2%);
    color: $white;
    text-shadow: 0 1px 1px rgba($black, 0.25);

    &:hover:not([disabled]) {
      background-color: darken($red-500, 5%);
      border-color: darken($red-500, 5%);
      box-shadow: $box-shadow-middle;
    }

    &:active,
    &.is-active {
      background-color: darken($red-500, 10%);
      border-color: darken($red-500, 10%);
      box-shadow: $box-shadow-middle;
    }

    &:focus {
      border-color: darken($red-500, 10%);
      box-shadow: $button-box-shadow-standard;
    }
  }

  &.is-danger-outlined {
    border: 1px solid $red-500;
    color: $red-500;
  }

  &.is-warning-outlined {
    background-color: $yellow-010;
    border: 1px solid $yellow-700;
    color: $yellow-700;
  }

  &.is-flat {
    min-width: auto;
    border: none;
    box-shadow: none;
  }

  &.is-ghost {
    background-color: transparent;
    border-color: transparent;
    box-shadow: none;
    color: $blue;
    text-decoration: none;

    &:hover {
      color: $blue-500;
      background-color: $grey-lightest;
    }
  }

  &.is-icon {
    padding: 0.25rem $size-3;
  }

  &.is-loading {
    color: transparent !important;
    pointer-events: none;
    &::after {
      animation: spinAround 500ms infinite linear;
      border: 2px solid $ui-gray-300;
      border-radius: 290486px;
      border-right-color: transparent;
      border-top-color: transparent;
      content: '';
      display: block;
      height: 1em;
      width: 1em;
      left: calc(50% - (1em / 2));
      top: calc(50% - (1em / 2));
      position: absolute !important;
    }
  }

  &.is-link {
    background-color: transparent;
    border-color: transparent;
    color: $blue;
    text-decoration: none;
    font-weight: $font-weight-semibold;
    box-shadow: none;
    min-width: 4rem;
  }

  &.is-primary {
    background-color: $blue;
    border-color: darken($blue, 2%);
    color: $white;
    font-weight: $font-weight-bold;
    text-shadow: 0 1px 1px rgba($black, 0.25);

    &:disabled {
      background-color: $ui-gray-700;
      border-color: transparent;
      box-shadow: none;
    }

    &:hover:not([disabled]) {
      background-color: darken($blue, 5%);
      border-color: darken($blue, 5%);
      box-shadow: $box-shadow-middle;
    }

    &:active,
    &.is-active {
      background-color: darken($blue, 10%);
      border-color: darken($blue, 10%);
      box-shadow: $box-shadow-middle;
    }

    &:focus {
      border-color: darken($blue, 10%);
      box-shadow: $button-box-shadow-standard;
    }

    &.is-loading::after {
      border-color: transparent transparent $white $white;
    }

    &.is-underlined {
      &:active,
      &.is-active {
        background-color: transparent;
        border-bottom: 2px solid darken($blue, 10%);
        border-radius: unset;
        color: darken($blue, 10%);
      }
    }
    // is-primary.is-outlined the only is-outlined buttons are primary.
    &.is-outlined {
      background-color: transparent;
      border-color: $blue;
      color: $blue;

      &:hover,
      &:focus {
        background-color: transparent;
        border-color: darken($blue, 10%);
        color: $blue;
      }

      &:active,
      &.is-active {
        background-color: transparent;
        border-color: darken($blue, 10%);
        color: darken($blue, 10%);
      }
    }

    &.is-outlined [disabled] {
      background-color: transparent;
      border-color: $ui-gray-700;
      box-shadow: none;
      color: $ui-gray-700;
    }
  }

  &.is-transparent {
    color: currentColor;
    background: none;
    border: none;
    box-shadow: none;
    min-width: auto;
    padding: 0;
  }
  // End of button types

  &.tool-tip-trigger {
    color: $grey-dark;
    min-width: auto;
    padding: 0;
  }

  &.has-icon-left,
  &.has-icon-right {
    .hs-icon {
      height: 16px;
      min-width: auto;
      width: 16px;
    }
  }

  &.has-icon-left {
    .hs-icon {
      &,
      &:first-child:last-child {
        position: relative;
        left: -$size-10;
      }
    }
  }

  &.has-icon-right {
    .hs-icon {
      &,
      &:first-child:last-child {
        margin-left: $spacing-xxs;
        margin-right: -$spacing-xxs;
      }
    }
  }
}

.button.icon {
  box-sizing: border-box;
  padding: 0 $size-11;
  height: 24px;
  width: 24px;
  &,
  & .icon {
    min-width: 0;
  }
}

.button.auto-width,
.button .icon.auto-width {
  width: auto;
  min-width: auto;
  margin: 0 !important;
}

.button.next-feature-step {
  background: $white;
  border: 1px solid $grey-light;
  border-radius: $radius;
  box-shadow: none;
  color: $blue;
  display: flex;
  height: auto;
  line-height: 1.2;
  justify-content: space-between;
  text-align: left;
  white-space: normal;
  padding: $size-8;
  width: 100%;
}

a.button.disabled {
  color: $white;
  background-color: $grey-dark;
  opacity: 0.5;
  border-color: transparent;
  box-shadow: none;
  cursor: default;
}
.icon-button {
  background: transparent;
  padding: 0;
  margin: 0;
  border: none;
  cursor: pointer;
}
.text-button {
  padding: unset;
  border: none;
  background-color: inherit;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  cursor: pointer;

  &:disabled {
    color: $grey-light;
    cursor: not-allowed;
  }
}
