﻿//
//Checkbox
//
.form-check {
    position: relative;
    padding-left: 2rem;
    min-height: 1.75rem;
    min-width: 1.75rem;
    font-size: 1rem;

    &.checkbox-sm {
        min-height: 1.5rem;
        min-width: 1.5rem;
        padding-left: 1.5rem;

        .checkbox-box {
            top: 0.125rem;
            width: 1rem;
            height: 1rem;
            min-width: 16px;
            .border-radius(.25rem);
        }

        input {

            &:checked,
            &:indeterminate {
                &+.checkbox-box {
                    &:after {
                        font-size: 0.45rem;
                    }
                }
            }

            &:indeterminate {
                &+.checkbox-box {
                    &:after {
                        width: 0.5rem;
                    }
                }
            }
        }
    }

    &.round-checkbox {
        padding-left: 46px;

        .checkbox-box {
            top: 0;
            height: 20px;
            width: 36px;
            border: solid 1px var(--grey-300);
            .border-radius(100px);
            background-color: var(--bg-100);
            transition: .4s;

            &:after {
                position: absolute;
                top: 1px;
                bottom: 1px;
                left: 3px;
                content: '';
                height: 16px;
                width: 16px;
                .border-radius(50%);
                background-color: var(--white);
                transition: .4s;
            }

            &:hover {
                &:after {
                    top: 1px;
                    left: 3px;
                }
            }
        }

        input {
            &:checked {
                &+.checkbox-box:after {
                    content: '';
                    top: 1px;
                    left: 18px;
                    transform: none;
                }
            }
        }
    }

    .field-invalid-msg {
        color: var(--error-main);
        font-size: 12px;
        margin-top: 2px;
    }

    .not-allowed,
    .disabled,
    [readonly] {
        pointer-events: none;
    }

    [readonly]~label {
        pointer-events: none;
    }

    &.checkbox-loading-state {
        pointer-events: none;

        input {
            &:checked {
                &+.checkbox-box {
                    background-color: var(--white);
                    border-color: var(--grey-300);
                }
            }
        }
    }

    input {
        display: none;
        position: absolute;
        top: 0;
        left: 0;
        width: 1px;
        height: 1px;
        margin: 0;
        opacity: 0;
        pointer-events: none;

        &+.checkbox-box.disabled {
            box-shadow: none;
            background-color: var(--bg-50);
            border-color: var(--grey-300);

            &:after {
                color: var(--grey-300);
            }
        }

        &:checked {
            &+.checkbox-box {
                background-color: var(--brand-600);
                border-color: var(--brand-600);

                &:after {
                    display: inline-block;
                    position: absolute;
                    left: 50%;
                    top: 50%;
                    .transform(translate(-50%, -50%));
                    content: '\e91a';
                    font-family: 'icomoon';
                    font-size: 0.5rem;
                    color: var(--white);
                }

                &:focus-visible {
                    outline: none;
                    box-shadow: 0 0 0 4px rgba(41, 112, 255, 0.24);
                }

                &.disabled {
                    box-shadow: none;
                    background-color: var(--bg-50);
                    border-color: var(--grey-300);

                    &:after {
                        color: var(--grey-300);
                    }
                }
            }
        }

        &:indeterminate {
            &+.checkbox-box {
                background-color: var(--brand-600);
                border-color: var(--brand-600);

                &:after {
                    content: '';
                    position: absolute;
                    left: 50%;
                    top: 50%;
                    width: 0.625rem;
                    height: 0.125rem;
                    border-radius: 999px;
                    background-color: var(--white);
                    .transform(translate(-50%, -50%));
                }

                &.disabled {
                    box-shadow: none;
                    background-color: var(--bg-50);
                    border-color: var(--grey-300);

                    &:after {
                        background-color: var(--grey-300);
                    }
                }
            }
        }

        &:focus-visible {
            &+.checkbox-box {
                outline: none;
                box-shadow: 0 0 0 4px rgba(152, 162, 179, 0.14);
            }
        }

        &:checked:focus-visible,
        &:indeterminate:focus-visible {
            &+.checkbox-box {
                box-shadow: 0 0 0 4px rgba(41, 112, 255, 0.24);
            }
        }
    }

    .checkbox-box {
        position: absolute;
        left: 0;
        top: 0.125rem;
        height: 1.25rem;
        width: 1.25rem;
        min-width: 20px;
        border: 1px solid var(--grey-300);
        margin-right: .25px;
        color: var(--white);
        display: flex;
        justify-content: center;
        align-items: center;
        .border-radius(.375rem);

        &:focus-visible {
            outline: none;
            box-shadow: 0 0 0 4px rgba(152, 162, 179, 0.14);
        }

        &+.form-check-label {
            line-height: 1.4;
        }
    }

    label[data-focus-click]:focus-visible:before {
        outline: 1px auto Highlight;
        outline: 1px auto -webkit-focus-ring-color;
    }

    // Validation
    input {
        &.field-invalid {

            &~label {
                color: var(--error-main);
            }

            &+.checkbox-box {
                border-color: var(--error-main);
            }
        }

        &:disabled {
            &+.checkbox-box {
                background-color: var(--bg-50);
                border-color: var(--grey-300);
                box-shadow: none;
                cursor: not-allowed;
            }

            &~.form-check-label,
            &~small {
                color: var(--grey-400);
            }
        }
    }

    small {
        display: block;
        color: var(--grey-600);
    }

    label {
        cursor: pointer;
    }

    &.right-side {
        text-align: right;
        padding-left: 0;
        padding-right: 2rem;

        .checkbox-box {
            left: inherit;
            right: 0;
        }
    }

    .form-check-label {
        color: var(--grey-700);
        font-weight: @font-weight-medium;

        &:focus-visible {
            outline: 1px auto Highlight;
            outline: 1px auto -webkit-focus-ring-color;
        }

        .icon-info-circle-light {
            margin-left: 0.5rem;
            vertical-align: middle;
        }
    }

    &.on-off {
        padding-left: 40px;

        &.right-side {
            padding-left: 0;
            padding-right: 40px;

            .on-off-slide {
                left: initial;
                right: 0;
            }
        }

        .on-off-slide {
            width: 36px;
            height: 20px;
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            border: solid 1px var(--grey-300);
            .border-radius(18px);
            background-color: var(--bg-100);
            .transition(.4s);

            &:focus-visible {
                outline: none;
                box-shadow: 0 0 0 4px rgba(152, 162, 179, 0.20);
            }


            &:before {
                position: absolute;
                content: "";
                height: 16px;
                width: 16px;
                left: 2px;
                bottom: 1px;
                top: 1px;
                .border-radius(50%);
                background-color: var(--white);
                box-shadow: 0 1px 3px 0 rgba(16, 24, 40, 0.10), 0 1px 2px 0 rgba(16, 24, 40, 0.06);
                .transition(.4s);
            }

            &.disabled {
                .filter(grayscale(100%));
                box-shadow: none;

                &:before {
                    background-color: var(--bg-50);
                }
            }
        }

        input:not(:checked):hover+label.on-off-slide {
            border-color: var(--primary);

            &:before {
                border-color: rgba(0, 0, 0, 0.15);
            }
        }

        input:checked+.on-off-slide {
            background-color: var(--primary);
            border-color: var(--primary);

            &:focus-visible {
                box-shadow: 0 0 0 4px rgba(41, 112, 255, 0.24);
            }

            &.not-allowed,
            &.disabled {
                box-shadow: none;
                background-color: color-mix(in srgb, white 20%, var(--primary));
                border-color: color-mix(in srgb, white 20%, var(--primary));

                &::before {
                    border-color: color-mix(in srgb, white 20%, var(--primary));
                }
            }
        }

        input:focus+.on-off-slide {
            .box-shadow(0 0 1px var(--primary));
        }

        input:checked+.on-off-slide:before {
            .transform(translateX(15px));
        }

        input:checked+label:after {
            content: none;
        }

        label:before {
            content: none;
        }

        .checkbox-box {
            display: none;
        }
    }
}

.form-row {
    .form-check {
        padding-left:~"calc(@{gatter} + 1.75rem)";

        &.on-off,
        &.round-checkbox {
            padding-left:~"calc(@{gatter} + 40px)";
        }

        .checkbox-box,
        .on-off-slide {
            left: @gatter;
        }

        &.right-side {
            padding-left: 0;
            padding-right:~"calc(@{gatter} + 1.75rem)";

            &.on-off,
            &.round-checkbox {
                padding-right:~"calc(@{gatter} + 40px)";
            }

            .checkbox-box,
            .on-off-slide {
                left: initial;
                right: @gatter;
            }
        }
    }
}