@mixin size($width, $height) {
  width: $width;
  height: $height;
}

@mixin square($size) {
  @include size($size, $size);
}

@mixin button-size($padding, $font-size) {
  padding: $padding;
  font-size: $font-size;
  line-height: $font-size;
}

@mixin button-color($color, $background, $border) {
  color: $color;
  background-color: $background;
  border-color: $border;
}

// group middle border
@mixin dark-group-border($bg-color) {
  .#{$btn-prefix-cls}-group:not(.#{$btn-prefix-cls}-group-vertical) &.first-child:not(.last-child) {
    border-right-color: darken($bg-color, 5%);
    &[disabled] {
      border-right-color: $border-color-base;
    }
  }

  .#{$btn-prefix-cls}-group:not(.#{$btn-prefix-cls}-group-vertical) &.last-child:not(.first-child),
  .#{$btn-prefix-cls}-group:not(.#{$btn-prefix-cls}-group-vertical) & + .#{$btn-prefix-cls} {
    border-left-color: darken($bg-color, 5%);
    &[disabled] {
      border-left-color: $border-color-base;
    }
  }

  .#{$btn-prefix-cls}-group-vertical &.first-child:not(.last-child) {
    border-bottom-color: darken($bg-color, 5%);
    &[disabled] {
      border-bottom-color: $border-color-base;
    }
  }

  .#{$btn-prefix-cls}-group-vertical &.last-child:not(.first-child),
  .#{$btn-prefix-cls}-group-vertical & + .#{$btn-prefix-cls} {
    border-top-color: darken($bg-color, 5%);
    &[disabled] {
      border-top-color: $border-color-base;
    }
  }
}

// 深色背景
@mixin dark-bg-btn($bg-color: $primary-color) {
  @include button-color($title-color-dark, $bg-color, $bg-color);

  &:hover {
    @include button-color(lighten($title-color-dark, 20%), lighten($bg-color, 20%), lighten($bg-color, 20%));
  }
  &:active,
  &.active {
    @include button-color(darken($title-color-dark, 5%), darken($bg-color, 5%), darken($bg-color, 5%));
  }

  &.disabled,
  &[disabled],
  fieldset[disabled] & {
    &,
    &:hover,
    &:focus,
    &:active,
    &.active {
      opacity: 0.8;
      @include button-color($title-color-dark, lighten($bg-color, 20%), lighten($bg-color, 20%));
    }
  }

  @include dark-group-border($bg-color);
}

// 白色背景
@mixin white-bg-btn($color: $title-color-light) {
  @include button-color($title-color-light, transparent, $border-color-base);

  &:hover {
    color: lighten($primary-color, 20%);
    border-color: lighten($primary-color, 20%);
  }
  &:active,
  &.active {
    color: darken($primary-color, 5%);
    border-color: darken($primary-color, 5%);
  }
}

@mixin btn-common() {
  display: inline-block;
  margin-bottom: 0;
  text-align: center;
  touch-action: manipulation;
  cursor: pointer;
  background-image: none;
  border: 1px solid transparent;
  white-space: nowrap;
  user-select: none;
  border-radius: $border-radius-base;
  box-sizing: border-box;
  height: 32px;
  @include button-size($btn-padding-base, 14px);
  transition: color $transition-time linear, background-color $transition-time linear, border $transition-time linear;

  > .#{$lib-name}-icon {
    font-size: 14px;
    line-height: 14px;
  }

  &,
  &:active,
  &:focus {
    outline: 0;
  }

  &:not([disabled]):hover {
    text-decoration: none;
  }

  &:not([disabled]):active {
    outline: 0;
  }

  &.disabled,
  &[disabled] {
    cursor: $cursor-disabled;
    > * {
      pointer-events: none;
    }
  }

  &.disabled,
  &[disabled],
  fieldset[disabled] & {
    &,
    &:hover,
    &:focus,
    &:active,
    &.active {
      @include button-color($disabled-text-color-light, transparent, $border-color-base);
    }
  }

  &-large {
    height: 40px;
    @include button-size($btn-padding-large, 16px);
    > .#{$lib-name}-icon {
      font-size: 16px;
      line-height: 16px;
    }
  }

  &-small {
    height: 28px;
    @include button-size($btn-padding-small, 14px);
  }

  &-xsmall {
    height: 26px;
    @include button-size($btn-padding-xsmall, 12px);
    > .#{$lib-name}-icon {
      font-size: 12px;
      line-height: 12px;
    }
  }
}

@mixin btn-group-common($btnClassName) {
  position: relative;
  display: inline-block;

  > .#{$btnClassName} {
    position: relative;
    float: left;
    &:hover,
    &:active,
    &.active {
      z-index: 2;
    }
  }

  &-circle .#{$btnClassName} {
    border-radius: $btn-circle-size;
  }

  &-large {
    & > .#{$btnClassName} {
      height: 40px;
      @include button-size($btn-padding-large, 16px);
      > .#{$lib-name}-icon {
        font-size: 16px;
        line-height: 16px;
      }
    }
  }

  &-small {
    & > .#{$btnClassName} {
      height: 28px;
      @include button-size($btn-padding-small, 14px);
    }
  }

  &-xsmall {
    & > .#{$btnClassName} {
      height: 26px;
      @include button-size($btn-padding-xsmall, 12px);
      > .#{$lib-name}-icon {
        font-size: 12px;
        line-height: 12px;
      }
    }
  }
}

// Group
@mixin btn-group($btnClassName) {
  @include btn-group-common($btnClassName);

  .#{$btnClassName} + .#{$btnClassName},
  .#{$btnClassName} + &,
  & + .#{$btnClassName},
  & + & {
    margin-left: -1px;
  }

  .#{$btnClassName}:not(.first-child):not(.last-child) {
    border-radius: 0;
  }

  &:not(&-vertical) > .#{$btnClassName}.first-child {
    margin-left: 0;
    &:not(.last-child) {
      border-bottom-right-radius: 0;
      border-top-right-radius: 0;
    }
  }

  &:not(&-vertical) > .#{$btnClassName}.last-child:not(.first-child) {
    border-bottom-left-radius: 0;
    border-top-left-radius: 0;
  }

  & > & {
    float: left;
  }

  // group in group
  & > &:not(:first-child):not(:last-child) > .#{$btnClassName} {
    border-radius: 0;
  }

  &:not(&-vertical) > &:first-child:not(:last-child) > .#{$btnClassName}.last-child {
    border-bottom-right-radius: 0;
    border-top-right-radius: 0;
    padding-right: 8px;
  }

  &:not(&-vertical) > &:last-child:not(:first-child) > .#{$btnClassName}.first-child {
    border-bottom-left-radius: 0;
    border-top-left-radius: 0;
    padding-left: 8px;
  }
}

@mixin btn-group-vertical($btnClassName: #{$lib-name}-btn) {
  > .#{$btnClassName} {
    display: block;
    width: 100%;
    max-width: 100%;
    float: none;
  }

  .#{$btnClassName} + .#{$btnClassName},
  .#{$btnClassName} + &,
  & + .#{$btnClassName},
  & + & {
    margin-top: -1px;
    margin-left: 0;
  }

  > .#{$btnClassName}.first-child {
    margin-top: 0;
    &:not(.last-child) {
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;
    }
  }

  > .#{$btnClassName}.last-child:not(.first-child) {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }

  // group in group
  & > &:first-child:not(:last-child) > .#{$btnClassName}.last-child {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding-bottom: 8px;
  }

  & > &:last-child:not(:first-child) > .#{$btnClassName}.first-child {
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
    padding-top: 8px;
  }
}

/* based on fa-spin */
@-webkit-keyframes #{$animation-prefix}-spin {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }

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

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

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

.x-fa-spin {
  animation: #{$animation-prefix}-spin 1s infinite linear;
  -webkit-filter: blur(0);
}
