// -----------------------------------------------------------------------------
// This file contains all styles related to the button component.
// -----------------------------------------------------------------------------

// @import "../../scss-variable/components/button";

@mixin btn-loading {
  pointer-events: none;

  &:before {
    content: "";
    display: inline-block;
    height: $btn-loading-height;
    width: $btn-loading-width;
    border-radius: $btn-loading-border-radius;
    line-height: $btn-loading-line-height;
    vertical-align: $btn-loading-vertical-align;
    border: $btn-loading-border;
    border-top-color: $btn-loading-border-top-color;
    margin-right: $btn-loading-icon-text-gap;
    animation: loading $btn-loading-animation-duration $btn-loading-animation-iteration-count $btn-loading-animation-timing-function;
  }

  &:after {
    pointer-events: none;
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    border-radius: inherit;
    background-color: $btn-loading-after-bg;
  }
}

// 有边框白底按钮
@mixin btn-lightprimary($color, $colorLight, $colorDark) {
  background: $color;
  color: $btn-lightprimary-color;
  border: $btn-lightprimary-border-width $btn-lightprimary-border-style $btn-lightprimary-border-color;

  &:hover {
    background: $colorLight;
    border: $btn-lightprimary-hover-border-width $btn-lightprimary-hover-border-style $btn-lightprimary-hover-border-color;
    color: $btn-lightprimary-hover-color;
  }

  &:active,
  &.#{$namespace}active {
    background: $colorDark;
    border: $btn-lightprimary-active-border-width $btn-lightprimary-active-border-style $btn-lightprimary-active-border-color;
    color: $btn-lightprimary-active-color;
  }

  &.#{$namespace}btn-loading {
    @include btn-loading;
  }

  &[disabled],
  &:disabled,
  &.#{$namespace}disabled {
    color: $btn-lightprimary-disabled-color;
    background: $btn-lightprimary-disabled-background-color;
    border: $btn-lightprimary-disabled-border-width $btn-lightprimary-disabled-border-style $btn-lightprimary-disabled-border-color;

    &.#{$namespace}btn-suspend {
      box-shadow: $btn-shadow-box-shadow;
    }
  }

  &.#{$namespace}btn-text {
    background: transparent;
    color: $color;

    &:hover {
      color: $colorLight;
    }

    &:active,
    &.#{$namespace}active {
      color: $colorDark;
    }

    &[disabled],
    &:disabled,
    &.#{$namespace}disabled {
      color: $btn-text-disabled-color;
    }
  }
}

// 无边框纯色按钮
@mixin btn-primary($color, $colorLight, $colorDark, $colorShadow) {
  background: $color;
  color: $btn-primary-color;
  border: none;

  &:hover {
    background: $colorLight;
  }

  &:active,
  &.#{$namespace}active {
    background: $colorDark;
  }

  &.#{$namespace}btn-loading {
    @include btn-loading;
  }

  &[disabled],
  &:disabled,
  &.#{$namespace}disabled {
    color: $btn-primary-disabled-color;
    background: $btn-primary-disabled-background-color;

    &.#{$namespace}btn-suspend {
      box-shadow: $btn-shadow-box-shadow;
    }
  }

  &.#{$namespace}btn-text {
    background: transparent;
    color: $color;

    &:hover {
      color: $colorLight;
    }

    &:active,
    &.#{$namespace}active {
      color: $colorDark;
    }

    &[disabled],
    &:disabled,
    &.#{$namespace}disabled {
      color: $btn-text-disabled-color;
    }
  }

  &.#{$namespace}btn-suspend {
    box-shadow: $btn-shadow-box-shadow-size $colorShadow;
  }

  &.#{$namespace}btn-xs {
    line-height: $btn-xs-size;
  }

  &.#{$namespace}btn-sm {
    line-height: $btn-sm-size;
  }

  &.#{$namespace}btn-lg {
    line-height: $btn-lg-size;
  }
}

.#{$namespace}btn-wrapper {
  display: inline-block;
  border: none;
}

.#{$namespace}btn-lightprimary-wrapper {
  display: inline-block;
  background: #ffffff;
  border: none;

  &:not(:first-child) {
    margin-left: -1px;
  }

  &:disabled {
    margin-left: 0;
  }
}

.#{$namespace}btn {
  appearance: none;
  background: $btn-background-color;
  border: $btn-border-width $btn-border-style $btn-border-color;
  border-radius: $btn-border-radius;
  color: $btn-color;
  cursor: pointer;
  display: inline-block;
  font-size: $btn-default-font-size;
  height: $btn-default-size;
  line-height: $btn-line-height;
  outline: none;
  padding: $btn-default-padding;
  text-align: center;
  text-decoration: none;
  user-select: none;
  vertical-align: middle;
  white-space: nowrap;
  position: relative;

  &:hover {
    color: $btn-hover-color;
    border-color: $btn-hover-border-color;
  }

  &:active,
  &.#{$namespace}active {
    color: $btn-active-color;
    border-color: $btn-active-border-color;
  }

  &[disabled],
  &:disabled,
  &.#{$namespace}disabled {
    opacity: $btn-disabled-opacity;
    cursor: not-allowed;
    color: $btn-disabled-color;
    background-color: $btn-disabled-bg-color;
    border: $btn-disabled-border-width $btn-disabled-border-style $btn-disabled-border-color;
  }

  &.#{$namespace}btn-loading {
    @include btn-loading;
  }

  // Button Text
  &.#{$namespace}btn-text {
    background: transparent;
    color: $btn-text-color;
    border-color: transparent;

    &:hover {
      color: $btn-text-hover-color;
    }

    &:active {
      color: $btn-text-active-color;
    }

    &[disabled],
    &:disabled,
    &.#{$namespace}disabled {
      color: $btn-text-disabled-color;
    }
  }

  &.#{$namespace}btn-suspend {
    border: none !important;
    box-shadow: $btn-shadow-box-shadow;

    &[disabled],
    &:disabled,
    &.#{$namespace}disabled {
      background-color: $btn-shadow-disabled-background-color;
    }
  }

  &.#{$namespace}btn-circle {
    border-radius: $btn-default-border-radius;
  }

  &.#{$namespace}btn-xs-circle {
    border-radius: $btn-xs-border-radius;
  }

  &.#{$namespace}btn-sm-circle {
    border-radius: $btn-sm-border-radius;
  }

  &.#{$namespace}btn-md-circle {
    border-radius: $btn-md-border-radius;
  }

  &.#{$namespace}btn-lg-circle {
    border-radius: $btn-lg-border-radius;
  }

  // Button primary
  &.#{$namespace}btn-primary {
    @include btn-primary($btn-primary-background-color,
      $btn-primary-hover-background-color,
      $btn-primary-active-background-color,
      $btn-primary-shadow-box-shadow-color );
  }

  &.#{$namespace}btn-lightprimary {
    @include btn-lightprimary($btn-lightprimary-background-color,
      $btn-lightprimary-hover-background-color,
      $btn-lightprimary-active-background-color );
  }

  // Button Colors
  &.#{$namespace}btn-success {
    @include btn-primary($btn-success-background-color,
      $btn-success-hover-background-color,
      $btn-success-active-background-color,
      $btn-success-suspend-box-shadow-color );
  }

  &.#{$namespace}btn-error {
    @include btn-primary($btn-error-background-color,
      $btn-error-hover-background-color,
      $btn-error-active-background-color,
      $btn-error-suspend-box-shadow-color );
  }

  &.#{$namespace}btn-warning {
    @include btn-primary($btn-warning-background-color,
      $btn-warning-hover-background-color,
      $btn-warning-active-background-color,
      $btn-warning-suspend-box-shadow-color );
  }

  // Button Sizes
  &.#{$namespace}btn-xs {
    font-size: $btn-xs-font-size;
    height: $btn-xs-height;
    line-height: $btn-xs-line-height;
    padding: $btn-xs-padding;
  }

  &.#{$namespace}btn-sm {
    font-size: $btn-sm-font-size;
    height: $btn-sm-height;
    line-height: $btn-sm-line-height;
    padding: $btn-sm-padding;
  }

  &.#{$namespace}btn-md {
    font-size: $btn-md-font-size;
    height: $btn-md-height;
    line-height: $btn-md-line-height;
    padding: $btn-md-padding;
  }

  &.#{$namespace}btn-lg {
    font-size: $btn-lg-font-size;
    height: $btn-lg-height;
    line-height: $btn-lg-line-height;
    padding: $btn-lg-padding;
  }

  // Button Block
  &.#{$namespace}btn-block {
    display: block;
    width: 100%;
  }

  // Button icon
  &.#{$namespace}btn-icon {
    width: $btn-icon-width;
    padding-left: 0;
    padding-right: 0;

    &.#{$namespace}btn-loading::before {
      margin-right: 0;
    }

    &.#{$namespace}btn-xs {
      width: $btn-icon-xs-width;
    }

    &.#{$namespace}btn-sm {
      width: $btn-icon-sm-width;
    }

    &.#{$namespace}btn-lg {
      width: $btn-icon-lg-width;
    }

    .#{$namespace}icon {
      margin-right: 0;
    }
  }

  // Button Clear
  &.#{$namespace}btn-clear {
    background: transparent;
    border: 0;
    color: currentColor;
    height: $btn-clear-height;
    line-height: $btn-clear-line-height;
    margin-left: $btn-clear-margin-left;
    margin-right: $btn-clear-margin-right;
    opacity: 1;
    padding: $btn-clear-padding;
    text-decoration: none;
    width: $btn-clear-width;

    &:hover {
      opacity: 0.95;
      box-shadow: none;
    }

    &::before {
      content: "\2715";
    }
  }

  .#{$namespace}btn-left-icon {
    margin-right: $btn-icon-margin-right;
  }
}

// Button groups
.#{$namespace}btn-group {
  display: inline-flex;
  flex-wrap: wrap;

  // ButtonGroup>Tooltip>button
  .#{$namespace}tooltip {
    padding: 0;

    &:first-child:not(:last-child) {
      button {
        border-bottom-right-radius: $btn-group-first-btn-border-bottom-right-radius;
        border-top-right-radius: $btn-group-first-btn-border-top-right-radius;
        border-top-left-radius: $btn-group-border-radius;
        border-bottom-left-radius: $btn-group-border-radius;

        &:hover {
          margin-right: $btn-group-first-btn-disabled-hover-margin-right;
        }
      }

      .#{$namespace}btn-primary,
      .#{$namespace}btn-success,
      .#{$namespace}btn-suspend,
      .#{$namespace}btn-warning,
      .#{$namespace}btn-lightprimary,
      .#{$namespace}btn-error {
        border-right: $btn-group-first-btn-error-border-right;
      }
    }

    &:not(:first-child):not(:last-child) {
      button {
        border-radius: $btn-group-center-btn-border-radius;
        margin-left: $btn-group-center-btn-margin-left;

        &:hover {
          margin-right: $btn-group-center-btn-disabled-hover-margin-right;
        }
      }

      .#{$namespace}btn-primary,
      .#{$namespace}btn-success,
      .#{$namespace}btn-suspend,
      .#{$namespace}btn-warning,
      .#{$namespace}btn-error {
        margin-left: $btn-group-center-btn-error-margin-left;
      }
    }

    &:last-child:not(:first-child) {
      button {
        border-bottom-left-radius: $btn-group-last-btn-border-bottom-left-radius;
        border-top-left-radius: $btn-group-last-btn-border-top-left-radius;
        border-top-right-radius: $btn-group-border-radius;
        border-bottom-right-radius: $btn-group-border-radius;
        margin-left: $btn-group-last-btn-margin-left;
      }
    }

    .#{$namespace}btn-primary,
    .#{$namespace}btn-success,
    .#{$namespace}btn-suspend,
    .#{$namespace}btn-warning,
    .#{$namespace}btn-lightprimary,
    .#{$namespace}btn-error {
      margin-left: $btn-group-last-btn-error-margin-left;
    }
  }

  .#{$namespace}btn {
    z-index: 1;

    &:disabled {
      pointer-events: none;
      z-index: 0;
    }

    &.#{$namespace}btn-lightprimary:disabled {
      margin-left: $btn-group-lightprimary-disabled-margin-left;
    }

    &:first-child:not(:last-child) {
      border-bottom-right-radius: $btn-group-first-btn-border-bottom-right-radius;
      border-top-right-radius: $btn-group-first-btn-border-top-right-radius;
      border-top-left-radius: $btn-group-border-radius;
      border-bottom-left-radius: $btn-group-border-radius;

      &:disabled:hover {
        margin-right: $btn-group-first-btn-disabled-hover-margin-right;
      }

      &.#{$namespace}btn-primary,
      &.#{$namespace}btn-success,
      &.#{$namespace}btn-suspend,
      &.#{$namespace}btn-warning,
      &.#{$namespace}btn-lightprimary,
      &.#{$namespace}btn-error {
        border-right: $btn-group-first-btn-error-border-right;
      }
    }

    &:not(:first-child):not(:last-child) {
      border-radius: $btn-group-center-btn-border-radius;
      margin-left: $btn-group-center-btn-margin-left;

      &:disabled:hover {
        margin-right: $btn-group-center-btn-disabled-hover-margin-right;
      }

      &.#{$namespace}btn-primary,
      &.#{$namespace}btn-success,
      &.#{$namespace}btn-suspend,
      &.#{$namespace}btn-warning,
      &.#{$namespace}btn-error {
        margin-left: $btn-group-center-btn-error-margin-left;
      }
    }

    &:last-child:not(:first-child) {
      border-bottom-left-radius: $btn-group-last-btn-border-bottom-left-radius;
      border-top-left-radius: $btn-group-last-btn-border-top-left-radius;
      border-top-right-radius: $btn-group-border-radius;
      border-bottom-right-radius: $btn-group-border-radius;
      margin-left: $btn-group-last-btn-margin-left;

      &.#{$namespace}btn-primary,
      &.#{$namespace}btn-success,
      &.#{$namespace}btn-suspend,
      &.#{$namespace}btn-warning,
      &.#{$namespace}btn-lightprimary,
      &.#{$namespace}btn-error {
        margin-left: $btn-group-last-btn-error-margin-left;
      }
    }

    &:not(:disabled):hover+.#{$namespace}btn {
      border-left-color: $btn-group-hover-border-color;
    }

    &:hover {
      border-color: $btn-group-hover-border-color;
      z-index: 2;
    }
  }
}