@import '../../style/themes/index';
@import '../../style/mixins/index';

@switch-prefix-cls: ~'@{ant-prefix}-switch';
@switch-transition-func: ease; // @ease-in-out-circ;
@switch-transition-speed: 0.3s;

.switch-size(@height) {
  @width: round(@height * @switch-width-ratio);
  @toggle-size: @height - 2 * @switch-toggle-indent;
  @activeTranslateX: @width - @toggle-size - 2 * @switch-toggle-indent;

  width: @width;
  height: @height;
  line-height: @height;
  border-radius: @height / 2;

  &::after {
    .square(@toggle-size);
  }

  .@{switch-prefix-cls}-inner {
    margin-right: round(@height * 0.2);
    margin-left: @height;
  }

  &.@{switch-prefix-cls}-checked {
    &::after {
      transform: translateX(@activeTranslateX);
    }

    .@{switch-prefix-cls}-inner {
      margin-right: @height;
      margin-left: round(@height * 0.2);
    }

    .@{switch-prefix-cls}-loading-icon {
      left: 100%;
      margin-left: (-@toggle-size - @switch-toggle-indent);
    }
  }

  .@{switch-prefix-cls}-loading-icon {
    .square(@toggle-size);
  }
}

.@{switch-prefix-cls} {
  .reset-component;

  position: relative;
  display: flex;
  .switch-size(@switch-height);
  vertical-align: middle;
  background-color: @switch-bg;
  border: 0;
  cursor: pointer;
  transition: background-color @switch-transition-speed @switch-transition-func;
  user-select: none;

  &-inner {
    display: block;
    width: 100%;
    text-align: center;
    color: @text-color-inverse;
    font-size: @font-size-sm;
  }

  &-loading-icon,
  &::after {
    position: absolute;
    top: @switch-toggle-indent;
    left: @switch-toggle-indent;
    background-color: @component-background;
    border-radius: 50%;
    transition: transform @switch-transition-speed @switch-transition-func;
    will-change: transform;
    content: '';
  }

  &::after {
    box-shadow: @switch-toggle-shadow;
  }

  &-loading-icon {
    z-index: 1;
    display: none;
    font-size: 12px;
    // loading default use animation
    // animation: loadingCircle 1s infinite linear;
    background: transparent;
    svg {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      margin: auto;
    }
  }

  &-loading &-loading-icon {
    display: inline-block;
    color: @text-color;
  }

  &-checked&-loading &-loading-icon {
    color: @switch-checked-bg;
  }

  &:focus {
    outline: 0;
  }

  &-small {
    .switch-size(@switch-sm-height);
  }

  &-small&-loading &-loading-icon {
    //font-weight: bold;
    transform: scale(0.66667);
  }

  &-large {
    .switch-size(@switch-lg-height);
  }

  &-checked {
    background-color: @switch-checked-bg;
  }

  &-loading,
  &-disabled {
    cursor: default;
    opacity: @switch-disabled-opacity;
    pointer-events: none;
  }
}

@keyframes AntSwitchSmallLoadingCircle {
  0% {
    transform: rotate(0deg) scale(0.66667);
    transform-origin: 50% 50%;
  }
  100% {
    transform: rotate(360deg) scale(0.66667);
    transform-origin: 50% 50%;
  }
}
