@import '../../style/variables';
@import './mixin';

.#{$prefix}switch {
  display: inline-block;
  box-sizing: border-box;
  position: relative;
  cursor: pointer;

  &__bg {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    font-family: $font-family;
    background-color: rgba(0, 0, 0, 0.25);
    transition: background-color 300ms;
    user-select: none;
  }

  &__thumb {
    position: relative;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    left: 0;
    top: 50%;
    transform: translateX(-50%) translateY(-50%);
    background-color: #fff;
    border: 1px solid rgba(0, 0, 0, 0.25);
    box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.2);
    transition: all 300ms;
    color: rgba(0, 0, 0, 0.25);
  }

  &__label {
    box-sizing: border-box;
    display: block;
    color: #fff;
    text-align: center;
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    padding-left: 11px;
    padding-right: 5px;
    transition: all 300ms;
  }

  &_checked {
    .#{$prefix}switch {
      &__bg {
        background-color: $primary-color;
      }

      &__thumb {
        left: 100%;
        border-color: $primary-color;
        color: $primary-color;
      }

      &__label {
        padding-left: 5px;
        padding-right: 11px;
      }
    }
  }

  &_disabled {
    cursor: not-allowed;
    opacity: 0.4;
  }

  //TODO: optimise
  &_loading {
    .#{$prefix}switch__thumb:before {
      display: inline-block !important;
    }
  }

  &_sm {
    margin: 0 10px;
    font-size: $switch-sm-font-size;
    width: 29px;
    height: 14px;

    .#{$prefix}switch {
      &__bg {
        border-radius: 18px;
      }

      &__thumb {
        @include switch-bg(18px);
      }

      &__label {
        line-height: 14px;
      }
    }
  }

  &_md {
    margin: 0 12px;
    font-size: $switch-md-font-size;
    width: 36px;
    height: 16px;

    .#{$prefix}switch {
      &__bg {
        border-radius: 22px;
      }

      &__thumb {
        @include switch-bg(22px);
      }

      &__label {
        line-height: 17px;
      }
    }
  }

  &_lg {
    margin: 0 14px;
    font-size: $switch-lg-font-size;
    width: 42px;
    height: 20px;

    .#{$prefix}switch {
      &__bg {
        border-radius: 26px;
      }

      &__thumb {
        @include switch-bg(26px);
      }

      &__label {
        line-height: 20px;
      }
    }
  }
}
