@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) {
    &:not(.is-readable){
      & .el-switch__core {
        cursor: not-allowed;
        border-color: $--color-secondary;
        background-color: $--color-secondary;
      }
    }
  }

  @include e(label) {
    transition: .2s;
    height: $--switch-height;
    display: inline-block;
    font-size: $--switch-font-size;
    font-weight: $--font-weight-400;
    cursor: pointer;
    vertical-align: middle;
    color: $--color-text-primary;
    position: absolute;
    z-index: 9;
    @include when(active) {
      color: $--color-white;

      // display: none;
    }

    &:not(.is-active){
      display: none;
    }

    @include m(left) {
      right: 8px;
      color: $--color-white;
      font-size: $--font-size-body-1;
    }
    @include m(right) {
      left: 8px;
      color: $--color-white;
      font-size: $--font-size-body-1;
    }
    & * {
      //line-height: 1;
      font-size: $--switch-font-size;
      display: inline-block;
      font-weight: $--font-weight-400;
    }

  }

  @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;
    //border: $--border-1 solid $--switch-off-color;
    outline: none;
    // border-radius: $--switch-core-border-radius;
    // border-radius: $--border-radius-large;
    border-radius: 12px;
    box-sizing: border-box;
    background: $--switch-off-color;
    cursor: pointer;
    transition: border-color .3s, background-color .3s;
    vertical-align: middle;
    i{
      position: absolute;
      top: -1px;
      left: 5px;
      z-index: 9;
      img{
        width: 14px;
        height: 14px;
        animation: loading-rotate 1.5s linear infinite;
      }
    }
    .loading-right{
      right: 5px;
      left: initial;
    }

    &:after {
      content: "";
      position: absolute;
      top: 4px;
      left: 4px;
      border-radius: $--border-radius-circle;
      width: $--switch-button-size;
      height: $--switch-button-size;
      background-color: $--color-white;
    }

    @include m(small) {
      width: $--switch-width-small;
      height: $--switch-height-small;
      // border-radius: $--switch-core-small-border-radius;
      border-radius: $--border-radius-large;

      &:after {
        width: 12px;
        height: 12px;
        top: 2px;
        left: 2px;
      }
      i{
        top: -5px;
        left: 3.5px;
      }
      img {
        width: 8px !important;
        height: 8px !important;
      }
      .loading-right{
        right: 4px;
      }
    }
  }

  @include when(checked) {
    .el-switch__core {
      border-color: $--switch-on-color;
      background-color: $--switch-on-color;
      &::after {
        left: unset;
        right: 4px;
      }
    }
    .el-switch__core--small {
      &::after {
        left: unset;
        right: 2px;
      }
    }
    @include when(disabled) {
      &:not(.is-readable) {
        .el-switch__core {
          border-color: $--color-disabled-background;
          background-color: $--color-disabled-background;
        }
      }
    }
  }

  @include when(disabled) {
    //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;
  }
}
@keyframes loading-rotate {
  100% {
    transform: rotate(360deg);
  }
}
