@import "mixins/mixins";
@import "common/var";

@include b(switch) {
  display: inline-flex;
  align-items: center;
  position: relative;
  font-size: $--switch-font-size;
  line-height: $--switch-height;
  height: $--switch-height;
  vertical-align: middle;

  @include when(disabled) {
    & .el-switch__core,
    & .el-switch__label {
      cursor: not-allowed;
    }
  }

  @include e(label) {
    transition: .2s;
    height: $--switch-height;
    display: inline-block;
    font-size: $--switch-font-size;
    font-weight: 500;
    cursor: pointer;
    vertical-align: middle;
    color: $--switch-font-color-out-off;

    @include when(active) {
      color: $--switch-font-color-out-on;
    }

    @include m(left) {
      margin-right: $--switch-font-offset-outside;
      i {
        color: $--switch-font-color-label;
      }
    }
    @include m(right) {
      margin-left: $--switch-font-offset-outside;
      color: $--switch-font-color-label;
    }
    & * {
      line-height: 1;
      font-size: $--switch-font-size;
      display: inline-block;
    }
  }

  @include e(input) {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    margin: 0;
  }

  @include e(core) {
    margin: 0;
    display: inline-block;
    position: relative;
    width: $--switch-width;
    height: $--switch-height;
    min-width: $--switch-width;
    // border: 1px solid $--switch-border-color-off;
    outline: none;
    border-radius: $--switch-core-border-radius;
    box-sizing: border-box;
    cursor: pointer;
    transition: border-color .3s, background-color .3s;
    vertical-align: middle;
    user-select: none;
    background-color: $--switch-bg-color-off;

    // 圆球样式
    .el-switch__circle {
      position: absolute;
      top: $--switch-circle-offset;
      left: $--switch-circle-offset;
      border-radius: $--border-radius-circle;
      transition: all .3s;
      width: $--switch-circle-size;
      height: $--switch-circle-size;
      background-color: $--switch-circle-color;
      box-shadow: 0px 2px 4px 0px rgba($--color-shadow, 0.2);
    }
    // 关闭时文字样式
    .el-switch__off {
      line-height: $--switch-height - 2px; 
      position: absolute;
      color: $--switch-font-color;
      right: $--switch-font-offset;
      font-size: $--switch-font-size;
    }
    // 开启式文字样式
    .el-switch__on {
      line-height: $--switch-height - 2px;
      position: absolute;
      color: $--switch-font-color;
      left: $--switch-font-offset;
      font-size: $--switch-font-size;
    }

    @include when(show-text) {
      min-width: 60px;
    }
  }

  @include when(checked) {
    .el-switch__core {
      border-color: $--switch-bg-color-on;
      background-color: $--switch-bg-color-on;
    }
    .el-switch__circle {
      left: 100%;
      margin-left: -$--switch-circle-size - 2px;
      background-color: $--switch-circle-color;
    }
  }

  @include when(disabled) {
    .el-switch__core {
      border-color: $--switch-border-color-disabled;
      background: $--switch-bg-color-disabled;
    }

    .el-switch__circle {
      background-color: $--switch-circle-bg-color-disabled;
    }

    .el-switch__on,
    .el-switch__off{
      color: $--switch-font-color-disabled;
    }

    &.is-checked {
      .el-switch__core {
        background-color: $--switch-on-bg-color-disabled;
      }

      .el-switch__circle {
        background-color: $--switch-on-circle-bg-color-disabled;
      }
    }
  }

  @include m(wide) {
    .el-switch__label {
      &.el-switch__label--left {
        span {
          left: $--switch-font-offset-outside;
        }
      }
      &.el-switch__label--right {
        span {
          right: $--switch-font-offset-outside;
        }
      }
    }
  }

  & .label-fade-enter,
  & .label-fade-leave-active {
    opacity: 0;
  }
}
