@import "../../style/themes/default";
@import "../../style/mixins/index";

@switch-prefix-cls: ~"@{dt-prefix}-switch";
@switch-duration: .36s;

.@{switch-prefix-cls} {
  .reset-component;
  @point-size: 14px;
  @point-sm-size: 8px;
  @switch-min-width: 36px;
  @switch-sm-min-width: 20px;
  @point-active-size: 4*@point-size/3;
  @point-active-sm-size: 4*@point-sm-size/3;

  position: relative;
  display: inline-block;
  box-sizing: border-box;
  height: @switch-height;
  min-width: @switch-min-width;
  line-height: @switch-height - 2px;
  vertical-align: middle;
  border-radius: 100px;
  border: 1px solid transparent;
  background-color: @switch-close-color;
  cursor: pointer;
  transition: all @switch-duration;
  user-select: none;

  &-inner {
    color: #fff;
    //font-size: @font-size-sm;
    .iconfont-size-under-12px(9px);
    margin-left: @point-size + 6px;
    margin-right: 6px;
    display: block;
  }

  &:before,
  &:after {
    position: absolute;
    width: @point-size;
    height: @point-size;
    left: (@switch-height - @point-size - 2) / 2;
    top: (@switch-height - @point-size - 2) / 2;
    border-radius: 18px;
    background-color: @component-background;
    content: " ";
    cursor: pointer;
    transition: all @switch-duration @ease-in-out-circ;
  }

  &:after {
    box-shadow: 0 2px 4px 0 rgba(0, 35, 11, .2);
  }

  &:active:before,
  &:active:after {
    width: @point-active-size;
  }

  &:before {
    content: @icon-loading;
    font-family: icon;
    font-size: 12px;
    animation: SwitchloadingCircle 1s infinite linear;
    text-align: center;
    background: transparent;
    z-index: 1;
    display: none;
  }

  &-loading:before {
    display: inline-block;
    color: @text-color;
  }

  &-checked&-loading:before {
    color: @switch-color;
  }

  &:focus {
    box-shadow: 0 0 0 2px fade(@switch-color, 20%);
    outline: 0;
  }

  &:focus:hover {
    box-shadow: none;
  }

  &-small {
    height: @switch-sm-height;
    min-width: @switch-sm-min-width;
    line-height: @switch-sm-height - 2px;

    .@{switch-prefix-cls}-inner {
      margin-left: @point-sm-size + 3px;
      margin-right: 3px;
      font-size: @font-size-sm;
    }

    &:before,
    &:after {
      width: @point-sm-size;
      height: @point-sm-size;
      left: (@switch-sm-height - @point-sm-size - 2) / 2;
      top: (@switch-sm-height - @point-sm-size - 2) / 2;
    }

    &:active:before,
    &:active:after {
      width: @point-active-sm-size;
    }
  }

  &-small&-checked {
    &:before,
    &:after {
      left: 100%;
      margin-left: -(@point-sm-size + 0.5px);
    }

    .@{switch-prefix-cls}-inner {
      margin-left: 3px;
      margin-right: @point-sm-size + 3px;
    }
  }

  &-small:active&-checked:before,
  &-small:active&-checked:after {
    margin-left: -(@point-active-sm-size + 0.5px);
  }

  &-small&-loading:before {
    animation: SwitchSmallLoadingCircle 1s infinite linear;
    font-weight: bold;
  }

  &-checked {
    background-color: @switch-color;

    .@{switch-prefix-cls}-inner {
      margin-left: 6px;
      margin-right: @point-size + 6px;
    }

    &:before,
    &:after {
      left: 100%;
      margin-left: -(@point-size + 1px);
    }

    &:active:before,
    &:active:after {
      margin-left: -(@point-active-size + 1px);
    }
  }

  &-loading,
  &-disabled {
    pointer-events: none;
    opacity: @switch-disabled-opacity;
  }
  &-disabled{
    background-color: @switch-disabled-close-color;
    
    .@{switch-prefix-cls}-inner {
      color: @switch-disabled-font-color;
    }

    &:before,
    &:after {
      background-color: @switch-close-color;
    }
  }
}

@keyframes SwitchSmallLoadingCircle {
  0% {
    transform-origin: 50% 50%;
    transform: rotate(0deg) scale(0.41667);
  }
  100% {
    transform-origin: 50% 50%;
    transform: rotate(360deg) scale(0.41667);
  }
}

@keyframes SwitchloadingCircle {
  0% {
    transform-origin: 50% 50%;
    transform: rotate(0deg) scale(0.83333);
  }
  100% {
    transform-origin: 50% 50%;
    transform: rotate(360deg) scale(0.83333);
  }
}