@import (reference) "../../../assets/css/index";

@switch-prefix-cls: ~"@{fishd-prefix}-switch";
@switch-duration: 0.2s;

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

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

  &:before,
  &:after {
    position: absolute;
    width: @switch-height - 4px;
    height: @switch-height - 4px;
    left: 1px;
    top: 1px;
    border-radius: @switch-border-radius;
    background-color: @component-background;
    content: " ";
    cursor: pointer;
    transition: all @switch-duration ease-in-out;
  }

  &:after {
    box-shadow: 0 2px 4px 0 rgba(0, 35, 11, 0.2);
  }

  &:before {
    content: "\e6a4";
    font-family: "@{iconfont-prefix}";
    animation: loadingCircle 1s infinite linear;
    text-align: center;
    background: transparent;
    z-index: 1;
    display: none;
    font-size: 12px;
  }

  &-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: 32px;
    line-height: @switch-sm-height - 2px;

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

    &:before,
    &:after {
      width: @switch-sm-height - 4px;
      height: @switch-sm-height - 4px;
    }
  }

  &-large {
    height: @switch-lg-height;
    min-width: 48px;
    line-height: @switch-lg-height - 2px;

    .@{switch-prefix-cls}-inner {
      margin-left: 30px;
      margin-right: 8px;
      font-size: @font-size-lg;
    }

    &:before,
    &:after {
      width: @switch-lg-height - 4px;
      height: @switch-lg-height - 4px;
    }
  }

  &-small&-checked {
    &:before {
      left: 100%;
      margin-left: @switch-sm-checked-margin-left;
    }
    .@{switch-prefix-cls}-inner {
      margin-left: 3px;
      margin-right: 18px;
    }
  }

  &-large&-checked {
    &:before {
      left: 100%;
      margin-left: @switch-lg-checked-margin-left;
    }
    .@{switch-prefix-cls}-inner {
      margin-left: 8px;
      margin-right: 30px;
    }
  }

  &-small&-loading:before {
    animation: fishdSwitchSmallLoadingCircle 1s infinite linear;
    font-weight: bold;
  }

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

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

    &:before {
      left: 100%;
      margin-left: -17px;
    }

    &:after {
      left: 100%;
      transform: translateX(-100%);
      margin-left: -1px;
    }
  }

  &-wave {
    display: none;
  }

  &-clicked {
    .@{switch-prefix-cls}-wave {
      position: absolute;
      top: -1px;
      left: -1px;
      bottom: -1px;
      right: -1px;
      border-radius: inherit;
      border: 0 solid @primary-color;
      opacity: 0.4;
      animation: switchEffect 0.4s;
      display: block;
    }
  }

  &-loading {
    pointer-events: none;
    opacity: @switch-disabled-opacity;
  }
  &-disabled {
    cursor: not-allowed;
    opacity: @switch-disabled-opacity;
  }
}

@keyframes switchEffect {
  to {
    opacity: 0;
    top: -6px;
    left: -6px;
    bottom: -6px;
    right: -6px;
    border-width: 6px;
  }
}

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