@use '../../styles/mixins/hover';
@use '../../styles/variables';

// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.

.form-check {
    position: relative;
    display: block;
    width: max-content;
    padding-left: 1rem;
    font-size: variables.$font-size-base;
    line-height: variables.$line-height-base;
    &:last-of-type {
        margin-bottom: 0;
    }
}

.form-check-input {
    position: absolute;
    margin-top: variables.$form-check-input-margin-t;
    margin-left: -(variables.$form-check-input-margin-l);

    &:disabled ~ .form-check-label {
        cursor: variables.$disabled-cursor;
        color: variables.$input-form-check-disable-color;
    }
}

.form-check-label {
    margin-bottom: 0; // Override default `<label>` bottom margin
}

.form-check-inline {
    display: -webkit-inline-box;
    display: -ms-inline-flexbox;
    display: inline-flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    padding-left: 0;
    margin-right: variables.$form-check-inline-margin-r;
    // Undo .form-check-input defaults and add some `margin-right`.
    .form-check-input {
        position: relative;
        flex-shrink: 0;
        margin-top: 0;
        margin-right: variables.$form-check-inline-input-margin-r;
        margin-left: 0;
    }
}

input[type='radio'],
input[type='checkbox'] {
    margin-top: 3px;
    -webkit-appearance: none;
    appearance: none;
    width: variables.$input-form-check-size;
    height: variables.$input-form-check-size;
    border: solid 1px variables.$input-form-check-border-color;
    cursor: variables.$hand-cursor;
    transition: border variables.$transition-duration-normal;

    box-sizing: border-box;
    padding: 0;

    &:not(.form-check-input) {
        position: relative;
    }

    &:checked {
        &::after {
            opacity: 1;
        }
        &:not(:disabled) {
            border-color: variables.$primary;
        }
    }

    &:focus {
        outline: 0;
    }

    &:not(:disabled) {
        @include hover.hover {
            border-color: variables.$primary;
        }
    }

    &:disabled {
        background-color: variables.$checkbox-disabled-bg-color;
        cursor: variables.$disabled-cursor;
    }
}

// checkbox
input[type='checkbox'] {
    border-radius: 2px;
    &:after {
        position: absolute;
        border: 3px solid variables.$primary;
        border-top: 0;
        border-left: 0;
        opacity: 0;
        content: ' ';
        top: 4px;
        left: 1px;
        width: 10px;
        height: 14px;
    }

    &:checked {
        &::after {
            transform: rotate(45deg) scale(0.6) translate(-50%, -50%);
            transition: all 0.1s cubic-bezier(0.71, -0.46, 0.88, 0.6);
        }
        &:not(:disabled) {
            background: variables.$primary;
            &::after {
                border-color: variables.$white;
            }
        }
        &:disabled {
            &::after {
                border-color: variables.$input-form-check-disable-color;
            }
        }
    }
}

input.form-check-indeterminate[type='checkbox'] {
    &::after {
        top: 50%;
        left: 50%;
        width: 6px;
        height: 6px;
        background-color: variables.$primary;
        border: 0;
        transform: translate(-50%, -50%);
        opacity: 1;
        content: ' ';
    }
    &:disabled {
        &::after {
            background-color: variables.$input-form-check-disable-color;
        }
    }
}

//radio
input[type='radio'] {
    border-radius: 100%;
    cursor: variables.$hand-cursor;
    &::after {
        content: '';
        position: absolute;
        top: 3px;
        left: 3px;
        display: block;
        width: 8px;
        height: 8px;
        border-radius: 100%;
        background: variables.$primary;
        opacity: 0;
        transition: all 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
    }

    &:checked {
        &:not(:disabled) {
            &::after {
                background: variables.$primary;
            }
        }
        &:disabled {
            &::after {
                background: variables.$input-form-check-disable-color;
            }
        }
    }

    // .set-input-hover-border();
}

.form-check-label {
    margin-left: variables.$form-check-label-margin-l;
    cursor: variables.$hand-cursor;
    color: variables.$input-label-color;
    transition: color variables.$transition-duration-normal;
    user-select: none;
    margin-bottom: 0;
    .form-check-inline & {
        margin-left: variables.$form-check-label-margin-l;
    }
}

// checked style
.form-check-checked > .form-check-label {
    color: variables.$input-label-checked-color;
}

.form-check-no-label-text {
    position: relative;
    vertical-align: text-bottom;
}

.form-check-inline-no-label-text {
    margin-right: 0.5rem;
}
