@import url(../var.less);

@switch-prefix: ~"@{prefix}switch";

.@{switch-prefix}{
  display: inline-flex;
  align-items: center;
  position: relative;
  font-size: @switch-font-size;
  line-height: @switch-height;
  height: @switch-height;
  vertical-align: middle;

  &.is-disabled, &.is-loading-disabled {
    & .w-switch__core,
    & .w-switch__label {
      cursor: not-allowed;
    }
  }

  &__label {
    transition: .2s;
    height: @switch-height;
    display: inline-block;
    font-size: @switch-font-size;
    font-weight: 500;
    cursor: pointer;
    vertical-align: middle;
    color: @switch-label-color;

    &.is-active {
      color: @primary-text-color;
    }

    &--left {
      margin-right: 16px;
    }
  
    &--right {
      margin-left: 16px;
    }
  
    & * {
      line-height: 1.5;
      font-size: @switch-font-size;
      display: inline-block;
    }
  }

  &__input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    margin: 0;
  }

  &__core {
    margin: 0;
    display: inline-block;
    position: relative;
    min-width: @switch-width;
    height: @switch-height;
    line-height: @switch-height - 2 *2 ;
    border: 2px solid @switch-off-color;
    outline: none;
    border-radius: @switch-core-border-radius;
    box-sizing: border-box;
    cursor: pointer;
    transition: border-color .3s, background-color .3s;
    vertical-align: middle;

    &:after {
      content: "";
      position: absolute;
      top: 5px;
      left: 5px;
      border-radius: @border-radius-circle;
      transition: all .3s;
      width: @switch-button-size;
      height: @switch-button-size;
      background-color: #8890A0;
    }
  }

  &__children {
    &--left {
      color: @color-white;
      margin-right: 18px;
      margin-left: 4px;
    }

    &--right {
      color: @switch-off-color;
      margin-left: 18px;
      margin-right: 4px;
    }
  }

  &.is-checked {
    .w-switch__core {
      border-color: @switch-on-color;
      background-color: @switch-on-color;
      &::after {
        left: 100%;
        margin-left: -@switch-button-size - 5px;
        background-color: @color-white;
      }
    }
  }

  &.is-disabled {
    opacity: 0.6;
  }

  &.is-loading-disabled {
    opacity: 1;
  }

  &.is-inactive-color {
    .w-switch__core { 
      &::after {
        background-color: @color-white;
      }
    } 
  }

  &--wide {
    .w-switch__label {
      &.w-switch__label--left {
        span {
          left: 10px;
        }
      }
      &.w-switch__label--right {
        span {
          right: 10px;
        }
      }
    }
  }

  & .label-fade-enter,
  & .label-fade-leave-active {
    opacity: 0;
  }

  &--small {
    .w-switch__core {
      min-width: @switch-small-width;
      height: @switch-small-height;
      line-height: @switch-small-height - 2 *2 ;

      &::after {
        top: 3px;
        left: 3px;
        width: @switch-small-button-size;
        height: @switch-small-button-size;
      }
    }    
  }

  &--small.is-checked &__core::after {
    margin-left: -@switch-small-button-size - 2px;
  }
  
}

