$base: "switch";

.#{$base} {
  --checked-color: var(--color-primary);
  --height: 31px;
  --width: 51px;
  --border-width: 2px;

  display: inline-block;
  vertical-align: middle;
  box-sizing: border-box;
  position: relative;
  align-self: center;
  cursor: pointer;

  input {
    display: none;
  }

  &-checkbox {
    min-width: var(--width);
    height: var(--height);
    box-sizing: border-box;
    border-radius: 31px;
    background: var(--color-border);
    z-index: 0;
    overflow: hidden;
    line-height: var(--height);

    &:before {
      content: " ";
      position: absolute;
      left: var(--border-width);
      top: var(--border-width);
      width: calc(100% - 2 * var(--border-width));
      height: calc(var(--height) - 2 * var(--border-width));
      border-radius: calc(var(--height) - 2 * var(--border-width));
      box-sizing: border-box;
      background: var(--color-background);
      z-index: 1;
      transition: all 200ms;
      transform: scale(1);
    }
  }

  &-inner {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 8px 0 calc(var(--height) - var(--border-width) + 5px);
    height: 100%;
    color: var(--color-weak);
    transition: margin 200ms;
    font-size: var(--font-size-7);
  }

  /* 选中状态 */
  &.#{$base}-checked {
    .#{$base}-checkbox {
      background: var(--checked-color);

      &:before {
        transform: scale(0);
      }
    }

    .#{$base}-handle {
      left: calc(100% - (var(--height) - var(--border-width)));
    }

    .#{$base}-inner {
      margin: 0 calc(var(--height) - var(--border-width) + 5px) 0 8px;
      color: var(--color-text-light-solid);
    }
  }

  /* 禁用状态 */
  &.#{$base}-disabled {
    cursor: not-allowed;
    opacity: 0.4;
  }
}
