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

@switch-prefix-cls: ~'@{clinia-prefix}-switch';
@switch-duration: 0.36s;

.@{switch-prefix-cls} {
  .reset-component;
  position: relative;
  display: inline-block;
  box-sizing: border-box;
  height: @switch-height;
  min-width: 32px;
  line-height: @switch-height - 2px;
  vertical-align: middle;
  border-radius: 100px;
  border: 1px solid transparent;
  background-color: @disabled-darker-fill-color;
  cursor: pointer;
  transition: all @switch-duration;
  user-select: none;
  margin: 2px 4px;

  &-inner {
    color: @white;
    font-size: @font-size-sm;
    margin-left: 24px;
    margin-right: 6px;
    display: block;
  }

  &-loading-icon,
  &:after {
    position: absolute;
    width: @switch-height + 6px;
    height: @switch-height + 6px;
    left: -4px;
    top: -4px;
    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, 0.2);
    background-color: @disabled-fill-color;
  }

  &:active:before,
  &:active:after {
    width: 24px;
  }

  &-loading-icon {
    // loading default use animation
    // animation: loadingCircle 1s infinite linear;
    background: transparent;
    z-index: 1;
    display: none;
    font-size: 12px;
    svg {
      position: absolute;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
      margin: auto;
    }
  }
  &-small&-checked {
    & .@{switch-prefix-cls}-loading-icon {
      left: 100%;
      margin-left: @switch-sm-checked-margin-left;
      svg {
        left: -3px;
      }
    }

    .@{switch-prefix-cls}-inner {
      margin-left: 3px;
      margin-right: 18px;
    }
  }

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

  &-checked&-loading &-loading-icon {
    color: @text-color-dark;
  }

  &-disabled&-loading &-loading-icon {
    color: @text-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: 28px;
    line-height: @switch-sm-height - 2px;

    .@{switch-prefix-cls}-inner {
      margin-left: 18px;
      margin-right: 3px;
      font-size: @font-size-sm;
    }

    &:after {
      width: @switch-sm-height + 6px;
      height: @switch-sm-height + 6px;
    }

    &:active:before,
    &:active:after {
      width: 16px;
    }
  }

  &-small &-loading-icon {
    width: @switch-sm-height - 4px;
    height: @switch-sm-height - 4px;
    svg {
      left: 3px;
      top: 12px;
    }
  }

  &-small&-loading &-loading-icon {
    // animation: AntSwitchSmallLoadingCircle 1s infinite linear;
    transform: scale(0.8);
    font-weight: @font-weight-bold;
  }

  &-checked {
    background-color: color(~`colorPalette("@{switch-color}", 7) `) ;

    .@{switch-prefix-cls}-inner {
      margin-left: 6px;
      margin-right: 24px;
    }

    &:after {
      left: 100%;
      transform: translateX(-100%);
      margin-left: 4px;
      background-color: @switch-color;
    }

    & .@{switch-prefix-cls}-loading-icon {
      left: 100%;
      margin-left: -19px;
      svg {
        left: 5px;
      }
    }
  }

  &-disabled {
    cursor: not-allowed;
    background-color: #F8F8FA;
    * {
      cursor: not-allowed;
    }

    &:after {
      background-color: @disabled-bg;
    }
  }
}

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