// (C) 2025 GoodData Corporation

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

.gd-ui-kit-menu {
    $root: &;

    max-height: 300px;
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    user-select: none;

    &--size {
        &-small {
            --item-padding-vertical: 4px;
            --item-padding-horizontal: 10px;
            --item-font-size: 12px;
            --item-line-height: 18px;
            --item-height: 26px;
        }

        &-medium {
            --item-padding-vertical: 8px;
            --item-padding-horizontal: 10px;
            --item-font-size: 14px;
            --item-line-height: 20px;
            --item-height: 36px;
        }
    }

    &__content-container {
        display: contents;
    }

    // Wraps custom (drill-in) content. Becomes a flex child so its content is
    // bounded by the menu's max-height and can scroll instead of overflowing.
    &__content-wrapper {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
    }

    &__items-container {
        width: 100%;
        height: 100%;
        overflow-y: auto;
        overflow-x: hidden;
        overscroll-behavior: contain;

        &--container-bottom-padding-small {
            padding-bottom: 6px;
        }

        &--container-bottom-padding-medium {
            padding-bottom: 10px;
        }

        &--container-top-padding-small {
            padding-top: 6px;
        }

        &--container-top-padding-medium {
            padding-top: 10px;
        }
    }

    @media #{variables.$small-only} {
        // !important to override inline style from maxWidth prop
        /* stylelint-disable-next-line declaration-no-important */
        max-width: 100vw !important;
        max-height: 100vh;
        width: 100%;
    }

    &__menu-header {
        background: var(--gd-palette-complementary-2);

        &-button {
            cursor: pointer;
            background: none;
            border: none;
            padding: 0;
            color: var(--gd-palette-complementary-6);
        }

        &-title {
            &-text {
                flex-grow: 1;
                color: var(--gd-palette-complementary-6);
                margin: 0;
                white-space: nowrap;
                font-size: 11px;
                font-style: normal;
                font-weight: 700;
                text-transform: uppercase;
                overflow: hidden;
            }
        }

        &-close-icon {
            flex-shrink: 0;
        }
    }

    &__group {
        list-style: none;
        margin: 0;
        padding: 0;
    }

    &__group-title-container {
        padding: 4px 10px;
        display: flex;
    }

    &__group-title {
        text-transform: uppercase;
        color: var(--gd-palette-complementary-5);
        font-size: 10px;
        font-weight: normal;
        margin: 0;
    }

    &__group-separator {
        flex-grow: 1;
        display: flex;
        vertical-align: middle;
    }

    &__items {
        list-style: none;
        margin: 0;
        padding: 0;
        outline: none;

        // Focus ring when not controlling by mouse
        #{$root}:not(#{$root}--controlType-mouse) &:focus-visible #{$root}__item-wrapper--isFocused {
            @include mixins.focus-ring;
        }
    }

    &__item-wrapper .gd-ui-kit-tooltip__anchor:not(.gd-ui-kit-tooltip__anchor--inline) {
        width: 100%;
    }

    &__item {
        height: var(--item-height);
        padding: var(--item-padding-vertical) var(--item-padding-horizontal);
        cursor: pointer;
        display: flex;
        align-items: center;
        font-size: var(--item-font-size);
        line-height: var(--item-line-height, 20px);
        color: var(--gd-palette-complementary-8);
        transition: background-color 0.2s;
        box-sizing: border-box;
        gap: 10px;

        // Controlled by mouse and has hover
        #{$root}--controlType-mouse &:hover:not(&--isDisabled) {
            background-color: var(--gd-palette-complementary-2);
            color: var(--gd-palette-complementary-9);
        }
        #{$root}--controlType-mouse &:hover:not(&--isDisabled)#{$root}__item--isDestructive {
            background-color: var(--gd-palette-error-dimmed);
            color: var(--gd-palette-error-base);

            & svg {
                fill: var(--gd-palette-error-base);
            }
        }

        &--isDisabled {
            color: var(--gd-palette-complementary-5);
        }

        &--isSelected {
            font-weight: bold;
            background: none;
            color: var(--gd-palette-primary-base);
        }

        #{$root}--controlType-mouse &--isSelected:hover:not(&--isDisabled) {
            background-color: var(--gd-palette-primary-dimmed);
            color: var(--gd-palette-primary-base);
        }

        > :not(#{$root}__item-title) {
            flex: none;
        }

        // The submenu indicator is an affordance, not content, so it takes the muted colour rather
        // than inheriting the label's.
        .gd-icon-navigateright {
            color: var(--gd-palette-complementary-5);
        }
    }

    &__item-title {
        display: block;
        width: 100%;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}
