@import '../colors';

.switch {
  position: relative;
  display: inline-block;

  * {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  label {
    cursor: pointer;
    font-size: 0.8rem;
    color: $color-N700;

    .lever {
      content: '';
      display: inline-block;
      position: relative;
      width: 16px;
      height: 10px;
      background-color: $color-N200;
      border-radius: 15px;
      -webkit-transition: background 0.3s ease;
      transition: background 0.3s ease;
      vertical-align: middle;

      &:before {
        background-color: rgba(38, 166, 154, 0.15);
      }

      &:after {
        background-color: $color-N500;
        box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2),
          0px 2px 2px 0 rgba(0, 0, 0, 0.14), 0px 1px 5px 0 rgba(0, 0, 0, 0.12);
      }

      &:before,
      &:after {
        content: '';
        position: absolute;
        display: inline-block;
        width: 16px;
        height: 16px;
        border-radius: 50%;
        left: -10px;
        top: -3px;
        transition: left 0.3s ease, background 0.3s ease, box-shadow 0.1s ease,
          transform 0.1s ease, -webkit-box-shadow 0.1s ease,
          -webkit-transform 0.1s ease;
      }
    }

    [type='checkbox']:not(:checked),
    [type='checkbox']:checked {
      position: absolute;
      opacity: 0;
      pointer-events: none;
    }

    span {
      &:first-child {
        margin-right: 16px;
      }

      &:last-child {
        margin-left: 16px;
      }
    }

    input[type='checkbox'] {
      opacity: 0;
      width: 0;
      height: 0;

      &:checked + .lever {
        &:before,
        &:after {
          left: 10px;
        }
      }
    }
  }

  &:not(.disabled) {
    input[type='checkbox'] {
      &:checked + .lever {
        background-color: $color-B200;

        &:after {
          background-color: $color-B500;
        }
      }
    }
  }

  &.thick {
    label {
      .lever {
        width: 44px;
        height: 25px;
        background-color: $color-N300;

        &:after {
          background-color: $color-N0;
        }

        &:before,
        &:after {
          width: 21px;
          height: 21px;
          left: 2px;
          top: 2px;
        }
      }

      input[type='checkbox'] {
        &:checked + .lever {
          &:before,
          &:after {
            right: 0;
          }
        }
      }
    }

    &:not(.disabled) {
      input[type='checkbox'] {
        &:checked + .lever {
          background-color: $color-B500;

          &::before {
            left: 22px;
          }

          &:after {
            background-color: $color-N0;
            left: 21px;
          }
        }
      }
    }
  }
}
