@import '../../../styles/definitions/mixins';
@import '../../../styles/definitions/placeholders';
@import '../../../styles/definitions/variables';

// Portal target for footer upward menus on storefronts where body is position:relative.
.languageSwitcher_upwardPortalRoot {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 0;
    pointer-events: none;
}

.languageSwitcher {
    &_wrapper {
        position: relative;
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        width: fit-content;
        max-width: 100%;
    }

    &_button {
        display: flex;
        align-items: center;
        gap: 5px;
        border: 0;
        background-color: transparent;
        color: inherit;
        font: inherit;
        cursor: pointer;
        padding: 4px 20px 4px 5px;
        position: relative;
        outline: none;

        // React Aria sets data-focus-visible only for keyboard focus, not clicks.
        &[data-focus-visible] {
            @include focus-outline-style;
        }

        // Header bars can be light or dark; use the link text token instead of default blue.
        .headerAuxiliaryBar_languagesSwitcher & {
            &[data-focus-visible] {
                @include focus-outline-style(var(--text-color, #{$header-nav-link-color}));
            }
        }

        .bottomBarMenu_languageSwitcher & {
            &[data-focus-visible] {
                @include focus-outline-style(currentColor);
            }
        }

        // CSS-drawn chevron so the control still reads as a dropdown. We draw
        // it with borders (not an SVG data URI) because `currentColor` resolves
        // correctly on borders but does NOT resolve inside SVG data URIs —
        // they render in an isolated document and would silently fall back to
        // black, becoming invisible on dark-themed headers.
        &::after {
            content: '';
            position: absolute;
            top: 50%;
            right: 5px;
            width: 0;
            height: 0;
            margin-top: -2px;
            border-right: 4px solid transparent;
            border-bottom: 0;
            border-left: 4px solid transparent;
            border-top: 5px solid currentColor;
            pointer-events: none;
        }

        &[data-open]::after {
            transform: rotate(180deg);
            margin-top: -3px;
        }
    }

    // Backward-compatible alias retained in the JSX for tenant CSS that used
    // languageSwitcher_select before this control moved off native <select>.
    // New component styles belong on languageSwitcher_button.
    &_label {
        &--hidden {
            @extend %sr-only;
        }
    }

    &_value {
        text-align: end;
    }

    // The popover/listbox/option colors below are hardcoded (not `inherit`ed
    // from the surrounding header/footer theme, and not `$body-color` /
    // `var(--bodyText)`) on purpose: this menu is rendered by us, not by the
    // browser, so it must supply its own readable colors in every browser
    // instead of relying on OS/browser dropdown defaults or tenant body-text
    // tokens. `--bodyText` is light on dark-themed storefronts, which would
    // recreate the Firefox dark-on-dark / light-on-white contrast failure
    // this component replaces.
    // Hardcode popover *color* only (see above). Font family/size come from the
    // theme manager via --bodyFont / --bodyBaseSize so tenant fonts (e.g. TeleNeo)
    // apply to the portaled menu, which is not a DOM child of the header/footer.
    &_popover {
        pointer-events: auto;
        z-index: 10;
        min-width: 180px;
        background-color: $white;
        color: $deep-gray;
        border-radius: 3px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
        overflow: hidden;
        @include fontFamily;
        font-size: $bodyFontSize5;
        line-height: $genericLineHeight;

        &[data-placement^='top'] {
            box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
        }
    }

    &_listbox {
        outline: none;
        padding: 4px 0;
        max-height: 300px;
        overflow-y: auto;
    }

    &_option {
        padding: 8px 12px;
        cursor: pointer;
        white-space: nowrap;

        &[data-focused],
        &[data-hovered] {
            background-color: $light-gray;
        }

        &[data-selected] {
            font-weight: 500;
            background-color: $light-gray;

            &[data-focused],
            &[data-hovered] {
                background-color: $gray-92;
            }
        }
    }
}
