@use '../core/styles/common/tokens';
@use '../core/styles/common/animation';
@use './toggle-theme' as theme;

$toggle-thumb-offset: 8px;

.kbq-toggle {
    display: inline-block;

    .kbq-toggle__circle {
        position: absolute;

        border-radius: 50%;

        transform: translateX(-1px); // due to EDGE animation features

        height: 10px;
        width: 10px;
    }

    .kbq-toggle-layout {
        display: flex;
        flex-direction: row;
        align-items: flex-start;

        cursor: inherit;

        &.kbq-toggle-layout_left {
            flex-direction: row-reverse;
        }

        &:has(.kbq-toggle-label:not(:empty)) .kbq-toggle-bar-container {
            padding-top: tokens.kbq-css-half-difference(typography-text-normal-line-height, toggle-size-normal-height);
        }
    }

    .kbq-toggle-bar-container {
        display: flex;
        align-items: center;
    }

    .kbq-toggle-bar {
        position: relative;
        box-sizing: border-box;

        display: flex;
        align-items: center;

        border: {
            width: 1px;
            style: solid;
            radius: 8px;
        }

        transition: background 100ms ease-in-out;
        height: var(--kbq-toggle-size-normal-height);
        width: var(--kbq-toggle-size-normal-width);

        .kbq-toggle__thumb {
            position: absolute;
            left: $toggle-thumb-offset;
            display: none;
            justify-content: center;
            align-items: center;
            width: 10px;
            height: 2px;
            border-radius: var(--kbq-size-border-width);
            transition: left 50ms ease-in-out;
        }
    }

    .kbq-hint {
        margin-top: var(--kbq-size-3xs);
    }

    &.kbq-indeterminate {
        &.cdk-keyboard-focused {
            .kbq-toggle-bar {
                .kbq-toggle__thumb {
                    left: $toggle-thumb-offset + 2px;
                }
            }
        }

        &:not(.kbq-disabled) .kbq-toggle-bar:hover {
            .kbq-toggle__thumb {
                left: $toggle-thumb-offset + 2px;
            }
        }

        .kbq-toggle-bar {
            .kbq-toggle__thumb {
                display: block;
            }
        }
    }
}

.kbq-toggle__content {
    display: flex;
    flex-direction: column;

    flex: 1;

    &:has(.kbq-toggle-label:not(:empty)) {
        &.kbq-toggle__content_left {
            margin-right: var(--kbq-toggle-size-normal-horizontal-content-padding);
        }

        &.kbq-toggle__content_right {
            margin-left: var(--kbq-toggle-size-normal-horizontal-content-padding);
        }
    }
}

.kbq-toggle.kbq-toggle_big {
    & .kbq-toggle-bar {
        height: var(--kbq-toggle-size-big-height);
        width: var(--kbq-toggle-size-big-width);
    }

    .kbq-toggle-layout {
        &:has(.kbq-toggle-label:not(:empty)) .kbq-toggle-bar-container {
            padding-top: tokens.kbq-css-half-difference(typography-text-big-line-height, toggle-size-big-height);
        }
    }
}

.kbq-toggle:not(.kbq-disabled) {
    cursor: pointer;
}

@include theme.kbq-toggle-theme();
@include theme.kbq-toggle-typography();
