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

@include b(switch) {
  display: inline-flex;
  align-items: center;
  position: relative;
  font-size: 0;
  font-weight: $--font-weight-medium;
  line-height: $--switch-height;
  height: $--switch-height;
  vertical-align: middle;
  @include when(disabled) {
    & .el-switch__core,
    & .el-switch__label {
      cursor: not-allowed;
    }
    & .el-switch__title--left {
      color: $--switch-disabled-background-color;
    }
    & .el-switch__title--right {
      color: $--switch-disabled-background-color;
    }
  }

  @include e(title) {
    @include m(left) {
      margin-right: 4px;
      font-size: $--switch-font-size;
    }
    @include m(right) {
      margin-left: 4px;
      font-size: $--switch-font-size;
    }
  }

  @include e(layout) {
    position: relative;
  }

  @include e(label) {
    transition: .2s;
    height: $--switch-height;
    display: inline-block;
    font-size: $--switch-font-size;
    font-weight: bold;
    cursor: pointer;
    vertical-align: middle;
    color: $--color-white;
    width: 22px;
    text-align: center;

    @include when(active) {
      color: transparent;
    }

    @include m(left) {
      // margin-right: 10px;
      position: absolute;
      z-index: 1;
      top: 0;
      left: $--switch-width * 0.1;
    }
    @include m(right) {
      // margin-left: 10px;
      position: absolute;
      z-index: 1;
      top: 0;
      left: $--switch-width * 0.45;
    }
    & * {
      line-height: 1;
      // font-size: $--switch-font-size;
      display: inline-block;
      vertical-align: middle;
    }
  }

  @include e(input) {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    margin: 0;
    &:focus ~ .el-switch__core {
      // outline: 1px solid $--color-primary;
    }
  }

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

    & .el-switch__button {
      position: absolute;
      top: 0;
      bottom: 0;
      margin: auto;
      left: 2px;
      border-radius: 5px;
      transition: transform .3s;
      width: $--switch-button-size;
      height: $--switch-button-size;
      background-color: $--color-white;
    }
  }

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

  @include when(disabled) {
    .el-switch__core {
      border: 1px solid $--switch-disabled-border-color;
      background-color: $--switch-disabled-background-color;
    }
    &.is-checked {
      .el-switch__core {
        border: 1px solid $--switch-disabled-checked-border-color;
        background-color: $--switch-disabled-checked-background-color;
      }
    }
    // opacity: 0.6;
  }

  @include m(wide) {
    .el-switch__label {
      &.el-switch__label--left {
        span {
          left: 10px;
        }
      }
      &.el-switch__label--right {
        span {
          right: 10px;
        }
      }
    }
  }

  & .label-fade-enter,
  & .label-fade-leave-active {
    opacity: 0;
  }
  @include m(small) {  
    height: $--switch-small-height;
    line-height: $--switch-small-height;
    @include e(label) {
      font-size: $--switch-font-small-size;
      height: $--switch-small-height;
    }
    & .el-switch__title--left {
      font-weight: 400;
    }
    & .el-switch__title--right {
      font-weight: 400;
    }
    .el-switch__label--right {
      left: $--switch-width * 0.35;
    }
    @include e(core) {
      height:$--switch-small-height;
      width: $--switch-small-width !important;
      border-radius: $--border-radius-base;
      // @include m(left) {
      //   left: $--switch-width * 0.21;
      // }
      & .el-switch__button {
        position: absolute;
        top: 0;
        bottom: 0;
        margin: auto;
        left: 1px;
        border-radius: $--border-radius-small;
        transition: transform .3s;
        width: $--switch-button-small-size;
        height: $--switch-button-small-size;
        background-color: $--color-white;
      }
    }
  }
}

