@import './../common/abstracts/_mixin';
@import './../common/abstracts/variable';

.wot-theme-dark {
  @include b(button) {
    @include when(info) {
      color: $-dark-color3;
      background: $-dark-background4;
    }

    @include when(plain) {
      background: transparent;

      @include when(info) {
        color: $-dark-color;

        &::after {
          border-color: $-dark-background5;
        }
      }
    }

    @include when(text) {
      @include when(disabled) {
        color: $-dark-color-gray;
        background: transparent;
      }
    }

    @include when(icon) {
      color: $-dark-color;

      @include when(disabled) {
        color: $-dark-color-gray;
        background: transparent;
      }
    }
  }
}

@include b(button) {
  position: relative;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: normal;
  color: $-button-normal-color;
  -webkit-appearance: none;
  user-select: none;
  background: transparent;
  border: none;
  outline: none;
  transition: opacity 0.2s;

  &::before {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    content: ' ';
    background: $-color-black;
    border: inherit;
    border-color: $-color-black;
    border-radius: inherit;
    opacity: 0;
    transform: translate(-50%, -50%);
  }

  &::after {
    border: none;
  }

  @include m(active) {
    &:active::before {
      opacity: 0.15;
    }
  }

  @include when(disabled) {
    opacity: $-button-disabled-opacity;
  }

  @include e(loading) {
    margin-right: 5px;
    animation: wd-rotate 0.8s linear infinite;
    animation-duration: 2s;
  }

  @include e(loading-svg) {
    width: 100%;
    height: 100%;
    background-repeat: no-repeat;
    background-size: cover;
  }

  @include when(loading) {}

  @include when(primary) {
    color: $-button-primary-color;
    background: $-button-primary-bg-color;
  }

  @include when(success) {
    color: $-button-success-color;
    background: $-button-success-bg-color;
  }

  @include when(info) {
    color: $-button-info-color;
    background: $-button-info-bg-color;
  }

  @include when(warning) {
    color: $-button-warning-color;
    background: $-button-warning-bg-color;
  }

  @include when(error) {
    color: $-button-error-color;
    background: $-button-error-bg-color;
  }

  @include when(small) {
    height: $-button-small-height;
    padding: $-button-small-padding;
    font-size: $-button-small-fs;
    font-weight: normal;
    border-radius: $-button-small-radius;

    .wd-button__loading {
      width: $-button-small-loading;
      height: $-button-small-loading;
    }
  }

  @include when(medium) {
    height: $-button-medium-height;
    padding: $-button-medium-padding;
    font-size: $-button-medium-fs;
    border-radius: $-button-medium-radius;

    @include when(primary) {
      box-shadow: $-button-medium-box-shadow-size $-button-primary-box-shadow-color;
    }

    @include when(success) {
      box-shadow: $-button-medium-box-shadow-size $-button-success-box-shadow-color;
    }

    @include when(warning) {
      box-shadow: $-button-medium-box-shadow-size $-button-warning-box-shadow-color;
    }

    @include when(error) {
      box-shadow: $-button-medium-box-shadow-size $-button-error-box-shadow-color;
    }

    @include when(plain) {
      box-shadow: none;
    }

    @include when(round) {
      min-width: 120px;

      @include when(icon) {
        min-width: 0;
        border-radius: 50%;
      }

      @include when(text) {
        min-width: 0;
        border-radius: 0;
      }
    }

    .wd-button__loading {
      width: $-button-medium-loading;
      height: $-button-medium-loading;
    }
  }

  @include when(large) {
    height: $-button-large-height;
    padding: $-button-large-padding;
    font-size: $-button-large-fs;
    border-radius: $-button-large-radius;

    &::after {
      border-radius: $-button-large-radius;
    }

    &:not(.is-plain) {
      @include when(primary) {
        box-shadow: $-button-large-box-shadow-size $-button-primary-box-shadow-color;
      }

      @include when(success) {
        box-shadow: $-button-large-box-shadow-size $-button-success-box-shadow-color;
      }

      @include when(warning) {
        box-shadow: $-button-large-box-shadow-size $-button-warning-box-shadow-color;
      }

      @include when(error) {
        box-shadow: $-button-large-box-shadow-size $-button-error-box-shadow-color;
      }
    }

    .wd-button__loading {
      width: $-button-large-loading;
      height: $-button-large-loading;
    }
  }

  @include when(round) {
    overflow: hidden;
    border-radius: 999px;
  }

  @include when(text) {
    min-width: 0;
    padding: 4px 0;
    color: $-button-primary-bg-color;

    &::after {
      display: none;
    }

    &.wd-button--active {
      opacity: $-button-text-hover-opacity;

      &:active::before {
        display: none;
      }
    }

    @include when(disabled) {
      color: $-button-normal-disabled-color;
      background: transparent;
    }
  }

  @include when(plain) {
    background: $-button-plain-bg-color;

    @include when(primary) {
      color: $-button-primary-bg-color;
      border: 1px solid $-button-primary-bg-color;
    }

    @include when(success) {
      color: $-button-success-bg-color;
      border: 1px solid $-button-success-bg-color;
    }

    @include when(info) {
      color: $-button-info-plain-normal-color;
      border: 1px solid $-button-info-plain-border-color;
    }

    @include when(warning) {
      color: $-button-warning-bg-color;
      border: 1px solid $-button-warning-bg-color;
    }

    @include when(error) {
      color: $-button-error-bg-color;
      border: 1px solid $-button-error-bg-color;
    }
  }

  @include when(hairline) {
    &.is-plain {
      border-width: 0;
      border-radius: 0;
      @include halfPixelBorderSurround();

      &::after {
        border-color: inherit;
      }
    }
  }

  @include when(block) {
    display: flex;
  }

  @include when(icon) {
    width: $-button-icon-size;
    height: $-button-icon-size;
    padding: 0;
    color: $-button-icon-color;
    border-radius: 50%;

    &::after {
      display: none;
    }

    :deep(.wd-button__icon) {
      margin-right: 0;
    }

    @include when(disabled) {
      color: $-button-icon-disabled-color;
      background: transparent;
    }
  }

  @include edeep(icon) {
    display: block;
    margin-right: 6px;
    font-size: $-button-icon-fs;
    vertical-align: middle;
  }

  @include e(text) {
    white-space: nowrap;
    user-select: none;
  }
}

// 微信2.8.0以上版本加了较高层级的默认样式，需要重置掉
.wd-button {
  width: auto;
  min-height: auto;
}

@keyframes wd-rotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}