@switch-prefix-cls: ~'@{css-prefix}switch';

.@{switch-prefix-cls} {
  display: inline-block;
  vertical-align: middle;
  background-color: @switch-default-bg-color;
  position: relative;
  cursor: pointer;
  user-select: none;
  transition: all @transition-time @ease-in-out;

  // hover
  &:not(&-checked):hover {
    background-color: @switch-not-checked-hover;
  }
  &-disabled&-default:not(&-checked):hover {
    background-color: @color-complementary-22;
  }
  &-loading {
    // opacity: 0.4;
    background-color: @switch-disabled-bg-color;
    &.@{switch-prefix-cls}-checked {
      background-color: @switch-disabled-checked-bg-color;
      &:before {
        border-color: transparent transparent transparent @color-brand-primary;
      }
    }
  }

  &-inner {
    color: @color-functional-white;
    font-size: @font-size-base;
    display: inline-block;
    width: 100%;

    i {
      width: 12px;
      height: 12px;
      text-align: center;
      position: relative;
      top: -0.125em;
    }
  }

  &:after {
    content: '';
    width: 18px;
    height: 18px;
    border-radius: 18px;
    background-color: @color-functional-white;
    position: absolute;
    left: 1px;
    top: 1px;
    cursor: pointer;
    transition: left @transition-time @ease-in-out,
      width @transition-time @ease-in-out;
  }

  &:active:after {
    width: 26px;
  }

  // loading 图标
  &:before {
    content: '';
    display: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background-color: transparent;
    position: absolute;
    left: 3px;
    top: 3px;
    z-index: 1;
    border: 2px solid @color-brand-disabled1;
    border-color: transparent transparent transparent @color-brand-disabled1;
    animation: switch-loading 1s linear;
    animation-iteration-count: infinite;
  }
  &-loading:before {
    display: block;
  }
  .@{switch-prefix-cls}-disabled-icon {
    font-size: 13px;
    position: absolute;
    z-index: 1;
    line-height: 20px;
    left: 3px;
    color: @switch-disabled-bg-color;
  }

  &:not(&-disabled):focus {
    // box-shadow: 0 0 0 2px fade(@color-brand-primary, 20%);
    // outline: 0;
  }

  &:focus:hover {
    //box-shadow: none;
  }

  &-small {
    min-width: 40px;
    height: 20px;
    border-radius: 10px;
    display: inline-block;
    line-height: 20px;
    vertical-align: middle;
    position: relative;
    cursor: pointer;
    user-select: none;
    transition: all @transition-time @ease-in-out;
    &:after {
      content: '';
      width: 16px;
      height: 16px;
      border-radius: 16px;
      background-color: @color-functional-white;
      position: absolute;
      left: 2px;
      top: 2px;
      cursor: pointer;
      transition: left 0.2s ease-in-out, width 0.2s ease-in-out;
    }
    &:active:after {
      width: 16px;
    }
    &:before {
      width: 16px;
      height: 16px;
      left: 1px;
      top: 2px;
    }
    .haloe-switch-inner{
      line-height: 20px;
      padding: 0 8px 0 20px;
    }
  }

  &-small&-checked:after {
    left: calc(~"100% - 16px - 2px");
  }
  &-small&-checked:before {
    left: calc(~"100% - 16px - 2px");
  }
  &-small&-checked {
    .@{switch-prefix-cls}-disabled-icon {
      left: calc(~"100% - 16px - 1px");
    }
  }

  &-small:active&-checked:after {
    left: calc(~"100% - 16px - 2px");
  }

  &-large {
    min-width: 52px;
    height: 26px;
    border-radius: 13px;
    line-height: 26px;
    display: inline-block;
    vertical-align: middle;
    position: relative;
    cursor: pointer;
    user-select: none;
    transition: all @transition-time @ease-in-out;
    &:after {
      content: '';
      width: 22px;
      height: 22px;
      border-radius: 11px;
      background-color: @color-functional-white;
      position: absolute;
      left: 2px;
      top: 2px;
      cursor: pointer;
      transition: left 0.2s ease-in-out, width 0.2s ease-in-out;
    }
    &:active:after {
      width: 22px;
    }
    &:before{
      width: 22px;
      height: 22px;
      top: 2px;
      left:1px;
    }
    .haloe-switch-inner{
      line-height: 26px;
      font-size: 14px;
      padding: 0 8px 0 26px;
    }
    
    .@{switch-prefix-cls}-disabled-icon {
      font-size: 19px;
      line-height: 26px;
      left: 3px;
    }
  }

  &-large&-checked:after {
    left: calc(~"100% - 22px - 2px");
  }
  &-large&-checked:before {
    left: calc(~"100% - 22px - 2px");
  }
  &-large&-checked {
    .@{switch-prefix-cls}-disabled-icon {
      left: calc(~"100% - 22px - 1px");
    }
  }

  &-large:active&-checked:after {
    left: calc(~"100% - 22px - 2px");
  }

  &-checked {
    border-color: @color-brand-primary;
    background-color: @color-brand-primary;

    &.@{switch-prefix-cls}-large .@{switch-prefix-cls}-inner {
      padding: 0 26px 0 8px;
    }

    &.@{switch-prefix-cls}-small .@{switch-prefix-cls}-inner {
      padding: 0 20px 0 8px;
    }

    &:after {
      left: 23px;
    }
    &:before {
      left: 25px;
    }

    &:active:after {
      left: 15px;
    }
    &:hover{
      background-color: @color-brand-hover;
    }
  }

  &-disabled {
    cursor: @cursor-disabled;
    background-color: @switch-disabled-bg-color;
    // opacity: 0.4;
    &:hover {
      background: @switch-disabled-bg-color !important;
    }

    &:after {
      background: @color-functional-white;
      cursor: not-allowed;
    }

    .@{switch-prefix-cls}-inner {
      color: @color-functional-white;
    }
  }

  &-disabled&-checked {
    background-color: @switch-disabled-checked-bg-color;
    // opacity: 0.4;
    &:hover {
      background: @switch-disabled-checked-bg-color !important;
    }

    &:after {
      background: @color-functional-white;
    }

    
    .@{switch-prefix-cls}-disabled-icon {
      color: @switch-disabled-checked-bg-color;
    }

    .@{switch-prefix-cls}-inner {
      color: @color-functional-white;
    }
  }
}

@keyframes switch-loading {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}
