@charset "UTF-8";
@use "sass:string";
@use "../../core/jkl";
@use "../../core/jkl/colors";
@use "../icon/base-styles" as icon;

@layer jokul.components {
    @include jkl.light-mode-variables {
        --jkl-checkbox-error-color: #ab2e43;
    }

    @include jkl.dark-mode-variables {
        --jkl-checkbox-error-color: #d79ba5;
    }

    .jkl-checkbox {
        --box-color: var(--jkl-color-border-action);
        --check-color: var(--jkl-color-border-action);
        --text-color: var(--jkl-color-text-default);
        --background-color: transparent;

        @include jkl.text-style("text-medium");

        display: flex;
        flex-wrap: wrap;
        color: var(--text-color);
        position: relative;

        &__input {
            // Keep the real input on top of the icon so automation tools can target it.
            position: absolute;
            inset-block-start: 0;
            inset-inline-start: 0;
            block-size: 1lh;
            inline-size: 1lh;
            margin: 0;
            padding: 0;
            cursor: pointer;
            z-index: 1;
            appearance: none;
            background: transparent;
            border: 0;

            @include jkl.reset-outline;
        }

        &__label {
            cursor: pointer;
            display: flex;

            @include jkl.motion;
            transition-property: color;

            @include jkl.text-style("text-medium");

            &::before {
                content: "check_box_outline_blank";
                margin-inline-end: 0.25em;

                @include icon.base-styles;
            }
        }

        &__input:focus-visible + &__label::before {
            @include jkl.focus-outline;
        }

        &__input:is(:hover, :active) + &__label,
        &__label:hover,
        &__label:active {
            --jkl-icon-weight: #{jkl.$icon-weight-bold};
        }

        &__input:checked + &__label::before {
            content: "check_box";

            --jkl-icon-fill: 1;
        }

        &__input:indeterminate:not(:checked) + &__label::before {
            content: "indeterminate_check_box";

            --jkl-icon-fill: 1;
        }

        &__input[aria-invalid="true"] + &__label::before {
            color: var(--jkl-checkbox-error-color);
        }

        & + & {
            margin-top: 0.75em;
        }

        &--inline {
            display: inline-flex;

            &:not(:last-of-type) {
                margin-right: var(--jkl-unit-30);
            }
        }
    }
}
