@charset "UTF-8";
@import "common/var";
@import "mixins/button";
@import "mixins/mixins";
@import "mixins/utils";

@include b(button) {
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  background: $--button-default-background-color;
  border: $--border-base;
  border-color: $--button-default-border-color;
  color: $--button-default-font-color;
  -webkit-appearance: none;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  margin: 0;
  transition: .1s;
  font-weight: $--button-font-weight;
  @include utils-user-select(none);

  &__content {
    display: flex;
    align-items: center;
    justify-content: center;

    i {
      font-size: 14px;
    }

    &>span {
      .el-button__left-icon {
        margin-right: 8px;
      }

      .el-button__right-icon {
        margin-left: 8px;
      }
    }

    .el-button__slot {
      display: flex;
      align-items: center;
    }
  }

  &+& {
    margin-left: 8px;
  }

  @include button-size($--button-padding-vertical, $--button-padding-horizontal, $--button-font-size, $--button-border-radius);

  &:hover,
  &:focus {
    background: $--color-white;
    border-color: $--color-primary;
    color: $--color-primary;
    opacity: 0.8;
  }

  &:active {
    color: mix($--color-black, $--color-primary, $--button-active-shade-percent);
    border-color: mix($--color-black, $--color-primary, $--button-active-shade-percent);
    background-color: $--color-primary-light-9;
    outline: none;
  }

  &::-moz-focus-inner {
    border: 0;
  }

  & [class*="el-icon-"],
  & [class*="bi-iconfont-"] {
    &+span {
      margin-left: 8px;
    }
  }

  @include when(plain) {

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

    &:active {
      background: $--color-white;
      border-color: mix($--color-black, $--color-primary, $--button-active-shade-percent);
      color: mix($--color-black, $--color-primary, $--button-active-shade-percent);
      outline: none;
    }
  }

  @include when(active) {
    color: mix($--color-black, $--color-primary, $--button-active-shade-percent);
    border-color: mix($--color-black, $--color-primary, $--button-active-shade-percent);
  }

  @include when(disabled) {

    &,
    &:hover,
    &:focus {
      color: $--button-disabled-font-color;
      cursor: not-allowed;
      background-image: none;
      background-color: $--button-disabled-background-color;
      border-color: $--button-disabled-border-color;
    }

    &.el-button--text {
      background-color: transparent;
    }

    &.is-plain {

      &,
      &:hover,
      &:focus {
        background-color: $--color-white;
        border-color: $--border-color-lighter;
        color: $--button-disabled-font-color;
      }
    }
  }

  @include when(loading) {
    position: relative;
    pointer-events: none;
    @include button-size($--button-medium-padding-vertical - 2, $--button-medium-padding-horizontal - 2, $--button-medium-font-size, $--button-medium-border-radius);

    .el-icon-loading {
      width: 14px;
      height: 14px;
      vertical-align: middle;
      border-radius: 50%;
      -webkit-animation: spin 2s linear infinite;
      animation: spin 2s linear infinite;

      &::before {
        content: '';
      }
    }

    @-webkit-keyframes spin {
      0% {
        -webkit-transform: rotate(0deg);
      }

      100% {
        -webkit-transform: rotate(360deg);
      }
    }

    @keyframes spin {
      0% {
        transform: rotate(0deg);
      }

      100% {
        transform: rotate(360deg);
      }
    }

    &:before {
      pointer-events: none;
      content: '';
      position: absolute;
      left: -1px;
      top: -1px;
      right: -1px;
      bottom: -1px;
      border-radius: inherit;
    }
  }

  @include when(round) {
    border-radius: 20px;
    padding: 10px 16px;
  }

  @include when(circle) {
    border-radius: 50%;
    padding: $--button-padding-vertical;
  }

  @include m(primary) {
    @include button-variant($--button-primary-font-color, $--button-primary-background-color, $--button-primary-border-color);
  }

  @include m(success) {
    @include button-variant($--button-success-font-color, $--button-success-background-color, $--button-success-border-color);
  }

  @include m(warning) {
    @include button-variant($--button-warning-font-color, $--button-warning-background-color, $--button-warning-border-color);
  }

  @include m(danger) {
    @include button-variant($--button-danger-font-color, $--button-danger-background-color, $--button-danger-border-color);
  }

  @include m(info) {
    @include button-variant($--button-info-font-color, $--button-info-background-color, $--button-info-border-color);
  }

  @include m(shadow) {
    background-color: rgba(83, 114, 236, 0.06);
    border-color: transparent;
    color: $--color-primary;

    &:hover,
    &:focus {
      background-color: rgba(109, 135, 239, 0.06);
      border-color: transparent;
      color: #6D87EF;
    }

    &:active,
    &.is-active {
      background-color: rgba(70, 97, 200, 0.06);
      border-color: transparent;
      color: #4661C8;
    }

    &.is-disabled {

      &,
      &:hover,
      &:focus,
      &:active {
        color: $--color-text-secondary;
        background-color: $--disabled-fill-base;
        border-color: $--disabled-fill-base;
      }
    }
  }

  @include m(and) {
    @include button-variant($--color-white, $--button-primary-background-color, $--button-primary-border-color);
    padding: 4px 4px;
    border-radius: 6px;
    font-size: 12px;

    &.is-disabled {

      &,
      &:hover,
      &:focus,
      &:active {
        color: $--color-text-secondary;
        background-color: $--disabled-fill-base;
        border-color: $--disabled-fill-base;
      }
    }
  }

  @include m(or) {
    @include button-variant($--color-white, $--button-or-background-color, $--button-or-border-color);
    padding: 4px 4px;
    border-radius: 6px;
    font-size: 12px;

    &.is-disabled {

      &,
      &:hover,
      &:focus,
      &:active {
        color: $--color-text-secondary;
        background-color: $--disabled-fill-base;
        border-color: $--disabled-fill-base;
      }
    }
  }

  @include m(large) {
    @include button-size($--button-large-padding-vertical, $--button-large-padding-horizontal, $--button-medium-font-size, $--button-medium-border-radius);

    &.is-loading {
      @include button-size($--button-large-padding-vertical - 2, $--button-large-padding-horizontal - 2, $--button-medium-font-size, $--button-medium-border-radius);
    }

    @include when(circle) {
      padding: $--button-large-padding-vertical;
    }
  }

  @include m(medium) {
    @include button-size($--button-medium-padding-vertical, $--button-medium-padding-horizontal, $--button-medium-font-size, $--button-medium-border-radius);

    &.is-loading {
      @include button-size($--button-medium-padding-vertical - 2, $--button-medium-padding-horizontal - 2, $--button-medium-font-size, $--button-medium-border-radius);
    }

    @include when(circle) {
      padding: $--button-medium-padding-vertical;
    }
  }

  @include m(small) {
    @include button-size($--button-small-padding-vertical, $--button-small-padding-horizontal, $--button-small-font-size, $--button-small-border-radius);

    &.is-loading {
      @include button-size($--button-small-padding-vertical - 2, $--button-small-padding-horizontal - 2, $--button-small-font-size, $--button-small-border-radius);
    }

    @include when(circle) {
      padding: $--button-small-padding-vertical;
    }

    & [class*="el-icon-"],
    & [class*="bi-iconfont-"] {
      &+span {
        margin-left: 4px;
      }
    }

    .el-button__content>span {
      .el-button__left-icon {
        margin-right: 4px;
      }

      .el-button__right-icon {
        margin-left: 4px;
      }
    }
  }

  @include m(mini) {
    @include button-size($--button-mini-padding-vertical, $--button-mini-padding-horizontal, $--button-mini-font-size, $--button-mini-border-radius);

    &.is-loading {
      @include button-size($--button-mini-padding-vertical - 2, $--button-mini-padding-horizontal - 2, $--button-mini-font-size, $--button-mini-border-radius);
    }

    @include when(circle) {
      padding: $--button-mini-padding-vertical;
    }

    & [class*="el-icon-"],
    & [class*="bi-iconfont-"] {
      &+span {
        margin-left: 4px;
      }
    }

    .el-button__content>span {
      .el-button__left-icon {
        margin-right: 4px;
      }

      .el-button__right-icon {
        margin-left: 4px;
      }
    }
  }

  @include m(text) {
    border-color: transparent;
    color: $--color-primary;
    background: transparent;
    padding-left: 0;
    padding-right: 0;

    &:hover,
    &:focus {
      color: mix($--color-white, $--color-primary, $--button-hover-tint-percent);
      border-color: transparent;
      background-color: transparent;
    }

    &:active {
      color: mix($--color-black, $--color-primary, $--button-active-shade-percent);
      border-color: transparent;
      background-color: transparent;
    }

    &.is-disabled,
    &.is-disabled:hover,
    &.is-disabled:focus {
      border-color: transparent;
    }
  }
}

.el-button--primary {
  &.is-loading {
    background-color: #4661C8;

    .el-icon-loading {
      border: 2px solid #ffffff;
      border-top: 2px solid #114DB4;
      border-left: 2px solid #114DB4;
    }
  }
}

.el-button--default {
  &.is-loading {
    .el-icon-loading {
      border: 2px solid #DCDEE2;
      border-top: 2px solid #155BD4;
      border-left: 2px solid #155BD4;
    }

    &:before {
      background-color: rgba(255, 255, 255, .35);
    }
  }
}

.el-button--dashed {
  border-style: dashed;
  border-color: $--color-primary;
  color: $--color-primary;
}

.el-button--solid {
  border-color: $--color-primary;
  color: $--color-primary;
}

@include b(button-group) {
  @include utils-clearfix;
  display: inline-block;
  vertical-align: middle;

  &>.el-button {
    float: left;
    position: relative;

    &+.el-button {
      margin-left: 0;
    }

    &.is-disabled {
      z-index: 1;
    }

    &:first-child {
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
    }

    &:last-child {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
    }

    &:first-child:last-child {
      border-top-right-radius: $--button-border-radius;
      border-bottom-right-radius: $--button-border-radius;
      border-top-left-radius: $--button-border-radius;
      border-bottom-left-radius: $--button-border-radius;

      &.is-round {
        border-radius: 20px;
      }

      &.is-circle {
        border-radius: 50%;
      }
    }

    &:not(:first-child):not(:last-child) {
      border-radius: 0;
    }

    &:not(:last-child) {
      margin-right: -1px;
    }

    &:not(.is-disabled) {

      &:hover,
      &:focus,
      &:active {
        z-index: 1;
      }
    }

    @include when(active) {
      z-index: 1;
    }
  }

  &>.el-dropdown {
    &>.el-button {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
      border-left-color: rgba($--color-white, 0.5);
    }
  }

  @each $type in (primary, success, warning, danger, info) {
    .el-button--#{$type} {
      &:first-child {
        border-right-color: rgba($--color-white, 0.5);
      }

      &:last-child {
        border-left-color: rgba($--color-white, 0.5);
      }

      &:not(:first-child):not(:last-child) {
        border-left-color: rgba($--color-white, 0.5);
        border-right-color: rgba($--color-white, 0.5);
      }
    }
  }
}