// scss-lint:disable QualifyingElement

//
// Base styles
//

.btn {
  display: inline-flex;
  justify-content: center;
  // align-items: center;
  font-weight: $btn-font-weight;
  text-align: center;
  text-transform: none;
  letter-spacing: normal;
  white-space: nowrap;
  vertical-align: middle;
  user-select: none;
  cursor: pointer;
  color: $gray-900;
  fill: $gray-600;
  border: 1px solid $gray-400;
  z-index: 1;
  @include gradient-y($white, $gray-100);
  @include button-size($btn-height, $input-btn-padding-y, $input-btn-padding-x, $btn-font-size, $input-btn-line-height, $btn-border-radius);
  @include transition($btn-transition);

  // Share hover and focus styles
  @include hover-focus {
    text-decoration: none;
  }

  &:hover, &:visited:hover {
    @include gradient-y($gray-100, $gray-200);
    border-color: $gray-400;
    color: $gray-900;
  }

  &:focus,
  &.focus {
    outline: 0;
    border-color: $indigo;
    box-shadow: $btn-focus-box-shadow;
    color: $gray-900;
    // z-index: 2;
  }

  &:active,
  &.active {
    background-image: none;
    box-shadow: $btn-focus-box-shadow, $btn-active-box-shadow;

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

  // Disabled comes first so active can properly restyle
  &.disabled,
  &:disabled {
    cursor: not-allowed;
    color: $gray-500;
    fill: $gray-500;
    background-color: $gray-200;
    background-image: none;
    box-shadow: none;

    &:hover,
    &:focus,
    &.focus,
    &:active,
    &.active {
      outline: 0;
      background-image: none;
      border-color: $gray-400;
      color: $gray-500;
      box-shadow: none;
    }
  }

  > .polaris-icon__svg {
    display: inline-block;
    height: 2rem;
    width: 2rem;
    margin: auto;
    margin-left: -0.4rem;
    margin-right: 0.4rem;

    &.icon-right {
      margin-left: 0.4rem;
      margin-right: -0.4rem;
    }
  }
}

.btn.btn--icon {
  padding: 0.7rem 0.7rem;
  
  > .polaris-icon__svg {
    margin-left: 0;
    margin-right: 0;
  }
}

.btn-outline {
  @include button-outline-variant($gray-900, $gray-600);
}

// Future-proof disabling of clicks on `<a>` elements
a.btn.disabled,
fieldset[disabled] a.btn {
  pointer-events: none;
}


//
// Alternate buttons
//

@each $color, $value in $theme-colors {
  .btn-#{$color} {
    @include button-variant($value, darken($value, 10%));
  }
}

@each $color, $value in $theme-colors {
  .btn-outline-#{$color} {
    @include button-outline-variant($value);
  }
}


//
// Link buttons
//

// Make a button look and behave like a link
.btn-link, .btn-link-gray, .btn-link-sort {
  font-weight: $font-weight-normal;
  padding-right: 0.8rem;
  padding-left: 0.8rem;
  color: $link-color;
  fill: $link-color;
  border-radius: 0;
  background: transparent;
  text-decoration: none;

  &,
  &:active,
  &.active,
  &.disabled,
  &:disabled {
    background-color: transparent;
    box-shadow: none;
  }
  &,
  &:focus,
  &:active {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
  }
  @include hover {
    border-color: transparent;
    background: none;
    color: $link-hover-color;
    fill: $link-hover-color;
  }
  @include hover-focus {
    color: $link-hover-color;
    text-decoration: $link-hover-decoration;
    background-color: transparent;
  }
  &.disabled,
  &:disabled {
    color: $btn-link-disabled-color;
    fill: $gray-400;

    @include hover-focus {
      text-decoration: none;
    }
  }
}

.btn-link-gray {
  color: $gray-600;
  fill: $gray-600;

  &:hover {
    color: $gray-700;
  }
}

.btn-link-sort {
  padding-right: 0;
  padding-left: 0;
  color: $gray-900;
  fill: $gray-900;
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 2.4rem;

  @include media-breakpoint-up(sm) {
    font-size: 1.5rem;
  }

  &:hover {
    color: $indigo;
  }
}

.btn-link-inline {
  padding-top: 0;
  padding-bottom: 0;
}


//
// Button Sizes
//

.btn-lg {
  @include button-size($btn-height-lg, $input-btn-padding-y-lg, $input-btn-padding-x-lg, $font-size-lg, $line-height-lg, $btn-border-radius);
}

.btn-sm {
  @include button-size($btn-height-sm, $input-btn-padding-y-sm, $input-btn-padding-x-sm, $font-size-sm, $line-height-sm, $btn-border-radius-sm);
}


//
// Block button
//

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

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

// Specificity overrides
input[type="submit"],
input[type="reset"],
input[type="button"] {
  &.btn-block {
    width: 100%;
  }
}
