/**
 * @license chowa v1.1.3
 *
 * Copyright (c) Chowa Techonlogies Co.,Ltd.(http://www.chowa.cn).
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
@import "../../styles/variables.scss";
@import "../../styles/mixin.scss";
@import "../../styles/animation/rotating.scss";

.#{$prefix}switch-wrapper {
    color: $text-color-gray;
    display: inline-block;
    margin: 0;
    padding: 0;
    height: $io-height-base;
    line-height: $io-height-base;
    font-size: $font-size-base;
    outline: none;
    white-space: nowrap;

    &:not(.#{$prefix}switch-disabled):hover .#{$prefix}switch {
        @include io-hover();
    }

    &:not(.#{$prefix}switch-disabled):focus .#{$prefix}switch {
        @include io-focus();
    }

    &.#{$prefix}has-error .#{$prefix}switch {
        @include has-error();
    }

    + .#{$prefix}switch-wrapper {
        margin-left: $base-padding * 1.2;
    }
}

@keyframes #{$prefix}switch-btn-anim {
    50% {
        width: 26px;
    }
}

.#{$prefix}switch {
    display: inline-block;
    position: relative;
    vertical-align: top;
    cursor: pointer;
    margin: ($io-height-base - 22px) / 2 0;
    padding: 0;
    height: 22px;
    min-width: 44px;
    border-radius: 11px;
    box-sizing: border-box;
    border: 1px solid $border-color;
    background-color: $background-color-base;
    transition: all $anim-duration ease-in;

    &:focus-within {
        .#{$prefix}switch-circle:before {
            animation-name: #{$prefix}switch-btn-anim;
            animation-duration: $anim-duration;
            animation-timing-function: ease-in-out;
        }
    }
}

.#{$prefix}switch-circle {
    position: absolute;
    display: block;
    top: 1px;
    left: 0;
    padding: 0 1px;
    margin: 0;
    transition: all $anim-duration ease-in;

    &:before {
        margin: 0;
        padding: 0;
        width: 18px;
        height: 18px;
        content: '';
        border-radius: 100%;
        background-color: $background-color-light;
        box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1), 0 4px 0 0 rgba(0, 0, 0, 0.04), 0 4px 9px rgba(0, 0, 0, 0.13), 0 3px 3px rgba(0, 0, 0, 0.05);
        display: block;
        cursor: pointer;
        z-index: 10;
    }
}

.#{$prefix}switch-inner {
    display: block;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    color: $text-color-light;
    line-height: 22px;
    font-size: $font-size-small;
    padding-right: 10px;
    padding-left: 22px;
}

.#{$prefix}switch-input {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
}

.#{$prefix}switch-label {
    padding: 0;
    margin: 0 0 0 ($base-padding * 0.6);
}

.#{$prefix}switch-checked .#{$prefix}switch {
    background-color: lighten($primary-color, 5%);
    border-color: $primary-color;

    .#{$prefix}switch-circle {
        left: 100%;
        transform: translateX(-100%);
    }

    .#{$prefix}switch-inner {
        color: $dark-text-color-base;
        padding-left: 10px;
        padding-right: 22px;
    }
}

.#{$prefix}switch-loading .#{$prefix}switch {
    cursor: not-allowed;

    .#{$prefix}switch-circle {
        &:before {
            cursor: not-allowed;
        }

        &:after {
            content: '';
            display: block;
            z-index: 15;
            position: absolute;
            top: 3px;
            left: 4px;
            right: 4px;
            bottom: 3px;
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            cursor: not-allowed;
            border-top: 1px solid $primary-color;
            border-radius: 100%;
            animation-name: #{$prefix}rotating;
            animation-duration: $anim-duration * 5;
            animation-timing-function: linear;
            animation-iteration-count: infinite;
        }
    }
}

.#{$prefix}switch-disabled {
    color: $text-color-light;

    .#{$prefix}switch,
    .#{$prefix}switch-circle:before {
        cursor: not-allowed;
        background-color: $disabled-color;
    }
}
