// (C) 2026 GoodData Corporation

@use "sass:math";

@use "../../../styles/scss/variables";
@use "../../../styles/scss/mixins";

$item-height: 40px;
$indicator-width: 4px;
$item-padding: 12px;
$icon-size: 18px;
$item-gap: 10px;
$action-required-size: 8px;
$chevron-size: 14px;
$flyover-width: 230px;

.gd-ui-kit-resizable-sidebar-navigation {
    $root: &;

    display: block;

    &__list,
    &__children,
    &__flyover-list {
        display: flex;
        flex-direction: column;
        margin: 0;
        padding: 0;
        list-style: none;
    }

    // The anchor of a rail flyover spans the row, so hover and the highlight cover the whole rail.
    &__flyover-anchor {
        display: block;
        width: 100%;
    }

    // The rail centers each row's content, whether it is the item or its tooltip anchor wrapper.
    &__row--rail {
        display: flex;
        justify-content: center;

        .gd-ui-kit-tooltip__anchor {
            display: block;
            width: 100%;
        }
    }

    // The left border is the state indicator: neutral on hover, primary for the current page.
    &__item {
        display: flex;
        align-items: center;
        gap: $item-gap;
        box-sizing: border-box;
        width: 100%;
        min-height: $item-height;
        padding: 0 $item-padding 0 ($item-padding - $indicator-width);
        border: 0;
        border-left: $indicator-width solid transparent;
        border-radius: 0;
        background: transparent;
        color: variables.$gd-color-text;
        font-family: inherit;
        font-size: 14px;
        line-height: 20px;
        text-align: left;
        text-decoration: none;
        cursor: pointer;
        transition: var(--gd-transition-all);

        &:hover,
        &--open {
            border-left-color: variables.$gd-color-disabled;
            background-color: variables.$is-focused-background;
            color: variables.$gd-color-dark;
            text-decoration: none;
        }

        &:focus {
            outline: none;
        }

        &:focus-visible {
            @include mixins.focus-ring;
        }

        &--active,
        &--selected {
            font-weight: 700;
        }

        &--active:not(#{$root}__item--child),
        &--active:not(#{$root}__item--child):hover {
            border-left-color: variables.$gd-palette-primary-base;
            background-color: variables.$is-focused-background;
            color: variables.$gd-color-dark;
        }

        // Sub-items align their label with the label of the group above and show no indicator.
        &--child {
            padding-left: $item-padding + $icon-size + $item-gap;
            border-left: 0;
            color: variables.$gd-color-link;

            &:hover {
                background-color: variables.$is-focused-background;
                color: variables.$gd-color-dark;
            }
        }

        &--child#{$root}__item--selected,
        &--child#{$root}__item--selected:hover {
            background-color: variables.$is-focused-background;
            color: variables.$gd-color-dark;
        }

        &--flyover {
            padding-left: $item-padding;
        }

        // The icon stays centered in the rail; the right padding balances the indicator.
        &--rail {
            position: relative;
            justify-content: center;
            padding: 0 $indicator-width 0 0;
        }
    }

    &__flyover {
        box-sizing: border-box;
        width: $flyover-width;
        padding: 0 0 10px;
        overflow: hidden auto;
        overscroll-behavior: contain;
        border-radius: variables.$gd-rounded-small;
        background-color: variables.$gd-color-white;
        box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.1);
    }

    &__icon {
        position: relative;
        display: flex;
        flex: 0 0 auto;
        align-items: center;
        justify-content: center;
        width: $icon-size;
        height: $icon-size;
        font-size: 12px;
        font-weight: 700;
        line-height: 1;
        text-transform: uppercase;
    }

    &__label {
        flex: 1 1 auto;
        min-width: 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    // Text for assistive technology only: the rail label and the action-required label.
    &__sr-only {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    &__action-required {
        position: relative;
        flex: 0 0 auto;
        width: $action-required-size;
        height: $action-required-size;
        margin-right: math.div($chevron-size - $action-required-size, 2);
        border-radius: 50%;
        background-color: variables.$gd-palette-primary-base;

        // In the rail the dot sits on the corner of the icon.
        #{$root}__item--rail & {
            position: absolute;
            top: 8px;
            right: 10px;
            margin-right: 0;
        }

        // A flyover item has no chevron above its dot, so the dot keeps its place.
        #{$root}__item--flyover & {
            margin-right: 0;
        }
    }

    &__chevron {
        display: flex;
        flex: 0 0 auto;
        align-items: center;
        transition: var(--gd-transition-all);

        &--expanded {
            transform: rotate(90deg);
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    .gd-ui-kit-resizable-sidebar-navigation__chevron,
    .gd-ui-kit-resizable-sidebar-navigation__item {
        transition: none;
    }
}
