@import '../../common/style/press/hairline-more/surround.scss';
@import '../../common/style/press/var.scss';

.press-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 0;
  text-align: center;
  vertical-align: middle;
  -webkit-appearance: none;
  -webkit-text-size-adjust: 100%;
  height: var(--button-default-height, $button-default-height);
  line-height: var(--button-line-height, $button-line-height);
  font-size: var(--button-default-font-size, $button-default-font-size);
  transition: opacity $animation-duration-fast;
  border-radius: var(--button-border-radius, $button-border-radius);
  cursor: pointer;

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

  // reset weapp default border
  &::after {
    border-width: 0;
  }

  // 【修改点】unclickable状态下不用有active样式
  &--active:not(&--unclickable)::before {
    opacity: .15;
  }

  // 【修改点】unclickable状态下不用有active样式
  &:active:not(&--unclickable)::before {
    opacity: .15;
  }

  // 【修改点】unclickable状态下不隐藏after
  // &--unclickable::after {
  //   display: none;
  // }

  &--default {
    color: var(--button-default-color, $button-default-color);
    background: var(
      --button-default-background-color,
      $button-default-background-color
    );
    border: var(--button-border-width, $button-border-width) solid
      var(--button-default-border-color, $button-default-border-color);
  }

  &--primary {
    color: var(--button-primary-color, $button-primary-color);
    background: var(
      --button-primary-background-color,
      $button-primary-background-color
    );
    border: var(--button-border-width, $button-border-width) solid
      var(--button-primary-border-color, $button-primary-border-color);
  }

  &--info {
    color: var(--button-info-color, $button-info-color);
    background: var(
      --button-info-background-color,
      $button-info-background-color
    );
    border: var(--button-border-width, $button-border-width) solid
      var(--button-info-border-color, $button-info-border-color);
  }

  &--danger {
    color: var(--button-danger-color, $button-danger-color);
    background: var(
      --button-danger-background-color,
      $button-danger-background-color
    );
    border: var(--button-border-width, $button-border-width) solid
      var(--button-danger-border-color, $button-danger-border-color);
  }

  &--warning {
    color: var(--button-warning-color, $button-warning-color);
    background: var(
      --button-warning-background-color,
      $button-warning-background-color
    );
    border: var(--button-border-width, $button-border-width) solid
      var(--button-warning-border-color, $button-warning-border-color);
  }

  &--plain {
    background: var(
      --button-plain-background-color,
      $button-plain-background-color
    );

    &.press-button--primary {
      color: var(
        --button-primary-background-color,
        $button-primary-background-color
      );
    }

    &.press-button--info {
      color: var(--button-info-background-color, $button-info-background-color);
    }

    &.press-button--danger {
      color: var(
        --button-danger-background-color,
        $button-danger-background-color
      );
    }

    &.press-button--warning {
      color: var(
        --button-warning-background-color,
        $button-warning-background-color
      );
    }
  }

  &--large {
    width: 100%;
    height: var(--button-large-height, $button-large-height);
  }

  &--normal {
    padding: 0 6px;
    font-size: var(--button-normal-font-size, $button-normal-font-size);
  }

  &--small {
    min-width: var(--button-small-min-width, $button-small-min-width);
    height: var(--button-small-height, $button-small-height);
    padding: 0 var(--padding-xs, $padding-xs);
    font-size: var(--button-small-font-size, $button-small-font-size);
  }

  // mini图标默认宽度50px，文字不能超过4个
  &--mini {
    display: inline-block;
    min-width: var(--button-mini-min-width, $button-mini-min-width);
    height: var(--button-mini-height, $button-mini-height);
    font-size: var(--button-mini-font-size, $button-mini-font-size);

    & + .press-button--mini {
      margin-left: 5px;
    }
  }

  &--block {
    display: flex;
    width: 100%;
  }

  &--round {
    border-radius: var(
      --button-round-border-radius,
      $button-round-border-radius
    );
  }

  &--square {
    border-radius: 0;
  }

  &--disabled {
    opacity: var(--button-disabled-opacity, $button-disabled-opacity);
    cursor: not-allowed;
  }

  &__text {
    display: inline;

    // 修复文字太多换行问题
    white-space: nowrap;
    // 修复文字被背景图片遮挡问题
    position: relative;
    z-index: 1;
  }

  &__loading-text,
  &__icon + &__text:not(:empty) {
    margin-left: $padding-base;
  }

  &__icon {
    min-width: 1em;
    line-height: inherit !important;
    vertical-align: top;
  }

  &--hairline {
    padding-top: 1px; // add 1px padding for text vertical align middle
    border-width: 0;

    &::after {
      border-color: inherit;
      border-width: 1px;
      border-radius: calc(
        var(--button-border-radius, $button-border-radius) * 2
      );
    }

    &.press-button--round::after {
      border-radius: var(
        --button-round-border-radius,
        $button-round-border-radius
      );
    }

    &.press-button--square::after {
      border-radius: 0;
    }

    &.press-hairline--surround::after {
      border-width: 1px;
    }
  }
}


@mixin bgMixin(
  $beforeWidth: $button-e-sport-bg-before-md-width,
  $beforeHeight: $button-e-sport-bg-before-md-height,
  $beforeBg: $button-e-sport-bg-before-md-img,
  $beforeBottom: 0,
  $afterWidth: $button-e-sport-bg-after-md-width,
  $afterHeight: $button-e-sport-bg-after-md-height,
  $afterBg: $button-e-sport-bg-after-md-img,
  $afterTop: $button-e-sport-bg-after-md-top
) {
  &::before {
    position: absolute;
    bottom: $beforeBottom;
    left: 0;
    content: '';
    width: $beforeWidth;
    height: $beforeHeight;
    background: url($beforeBg) no-repeat center;
    background-size: contain;
    pointer-events: none;

    transform: unset; // 去掉press-btn自带before的影响
    top: unset;
    right: unset;
    opacity: 1;
  }

  &::after {
    position: absolute;
    top: $afterTop;
    right: 0;
    content: '';
    width: $afterWidth;
    height: $afterHeight;
    background: url($afterBg) no-repeat center;
    background-size: contain;
    pointer-events: none;

    transform: unset; // 去掉press-btn自带before的影响
    left: unset;
    bottom: unset;
    opacity: 1;
  }
}

@mixin primaryMixin() {
  font-size: $font-size-lg;
  color: $color-white;
  border-radius: $border-radius-md;
  background-image: $color-primary-btn;
  border: 0; // 没有 border
  &:not(.press-button--unclickable):active {
    background: $color-blue;
  }
}

.press-button {
  &--e-sport-primary {
    width: 1.76rem;
    height: .72rem;
    @include primaryMixin();
  }

  &--e-sport-secondary {
    width: 2rem;
    height: .72rem;
    font-size: $font-size-lg;
    color: $color-black;
    border-radius: $border-radius-md;
    background: #eef0f6;
    border: 0; // 没有 border
    &:not(.press-button--unclickable):active {
      background: $color-gray-3;
    }

    &::before {
      background-color: transparent;
      border: 0;
    }
  }

  &--e-sport-border {
    width: 2rem;
    height: .72rem;
    font-size: $font-size-lg;
    color: $color-primary;
    border-width: $border-width-base;
    border-style: solid;
    border-color: $color-primary;
    border-radius: $border-radius-md;
    background: transparent;

    &:not(.press-button--unclickable):active {
      background: $color-bg;
      border-color: $color-blue;
      color: $color-blue;
    }

    &::before {
      background-color: transparent;
      border: 0;
    }
  }

  &--e-sport-bg {
    width: 2.72rem;
    height: .72rem;
    @include bgMixin();

    &-lg {
      width: 5.34rem;
      height: .88rem;

      &::before {
        width: $button-e-sport-bg-before-lg-width;
        height: $button-e-sport-bg-before-lg-height;
        background-image: url($button-e-sport-bg-before-lg-img);
        background-color: transparent;
        border: 0;
      }

      &::after {
        top: $button-e-sport-bg-after-lg-top;
        width: $button-e-sport-bg-after-lg-width;
        height: $button-e-sport-bg-after-lg-height;
        background-image: url($button-e-sport-bg-after-lg-img);
      }
    }

    &-xl {
      width: 6rem;
      height: .88rem;

      &::before {
        width: $button-e-sport-bg-before-xl-width;
        height: $button-e-sport-bg-before-xl-height;
        background-image: url($button-e-sport-bg-before-xl-img);
        background-color: transparent;
        border: 0;
      }

      &::after {
        top: $button-e-sport-bg-after-xl-top;
        width: $button-e-sport-bg-after-xl-width;
        height: $button-e-sport-bg-after-xl-height;
        background-image: url($button-e-sport-bg-after-xl-img);
        background-color: transparent;
        border: 0;
      }
    }
  }

  &--e-sport-disabled {
    opacity: var(--button-disabled-opacity, $button-disabled-opacity);
    cursor: not-allowed;
  }
}