@import "mixins/mixins";
@import "common/var";

@mixin switch-size($width, $height, $core,$font-size) {
  height: $height;
  font-size: $font-size;
  @include e(label){
    font-size:$font-size;
    height: $height;
    line-height: $height;
  }
  @include e(core) {
    width: $width;
    height: $height;
    &:after {
      width: $core;
      height: $core;
    }
  }
  @include when(checked) {
    .xb-switch__core {
      &::after {
        margin-left: -$core - 1px;
      }
    }
  }
}

@include b(switch) {
  display: inline-flex;
  align-items: center;
  position: relative;
  font-size: $--font-size-base - 2px;
  height: $--switch-height;
  vertical-align: middle;

  & + & {
    margin-left: 10px;
  }

  @include when(disabled) {
    & .xb-switch__core,
    & .xb-switch__label {
      cursor: not-allowed;
    }
  }

  @include e(label) {
    transition: .2s;
    height: $--switch-height;
    line-height: $--switch-height;
    display: inline-block;
    font-size: $--font-size-base - 2px;
    font-weight: $--font-weight-base;
    cursor: pointer;
    color: $--color-white;

    @include m((left, right)){
      position: absolute;
      z-index: 5;
      top: 0;
    }
    @include m(left) {
      right: 10px;
    }
    @include m(right) {
      left: 10px;
    }
    & * {
      line-height: 1;
      font-size: $--font-size-base - 2px;
      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;
    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;

    &:after {
      content: "";
      position: absolute;
      display: block;
      left: 1px;
      top: 50%;
      transform: translateY(-50%);
      border-radius: $--border-radius-circle;
      transition: all .3s;
      width: $--switch-button-size;
      height: $--switch-button-size;
      background-color: $--color-white;
    }
  }

  @include when(checked) {
    .xb-switch__core {
      @include switch-on-color;
      &::after {
        left: 100%;
        margin-left: -$--switch-button-size - 1px;
      }
    }
  }

  @include when(disabled) {
    opacity: 0.6;
  }

  @include m(wide) {
    .xb-switch__label {
      &.xb-switch__label--left {
        span {
          left: 12px;
        }
      }
      &.xb-switch__label--right {
        span {
          right: 12px;
        }
      }
    }
  }
  
  @include m(big) {
    @include switch-size($--switch-big-width,$--switch-big-height,$--switch-button-big-size,$--switch-big-font-size);
  }
  @include m(medium) {
    @include switch-size($--switch-width,$--switch-height,$--switch-button-size,$--switch-font-size);
  }
  @include m(small) {
    @include switch-size($--switch-small-width,$--switch-small-height,$--switch-button-small-size,$--switch-small-font-size);
    @include e(label){
      @include m(left) {
        right: $--switch-button-small-size / 3.5;
      }
      @include m(right) {
        left: $--switch-button-small-size / 3.5;
      }
    }
  }

  & .label-fade-enter,
  & .label-fade-leave-active {
    opacity: 0;
  }
}
