@import "shared/mixins-and-vars";

// Color variables (appears count calculates by raw css)
@color0: #fff; // Appears 4 times
@color1: #494a50; // Appears 3 times
@color2: #a5a5a4; // Appears 2 times
@color3: #20c270; // Appears 2 times
@anim-time: 0.2s;
@large-anim-time: 0.2s;
@desktop-min: 960px;
@flyout-width: 75vw;
@desktop: ~"only screen and (min-width: @{desktop-min})"; // please use mobile first here.
@hamburger-translate-y: ~"min(@{flyout-width}, 350px)";
@hamburger-offset-y: ~"calc(-1 * @{hamburger-translate-y})";
@hamburger-menu-icon-top: 20px;
@focus-area-padding: 15px;

// This would be normally set to a lower number.  However, AblePlayer's
// max z-index is 10000, so we are compensating.
@min-z-index: 0;

@menu-orientation: right;

// Height variables (appears count calculates by raw css)
@height0: 100vh; // Appears 3 times

* {
    box-sizing: border-box;
}

#enable-flyout-menu {
    @media @tablet, @desktop {
        display: flex;
        align-items: center;
        flex-grow: 1;
        text-align: center;
        justify-content: end;
        padding-right: 10px;
    }
}

@media @mobile, @tablet {
    .enable-flyout__top-level {
        background-color: @dark-grey;
    }
}

.enable-flyout {
    --enable-flyout__desktop-media-query: @desktop;
    --enable-flyout__is-hamburger: 1;
    --enable-flyout__desktop-min: @desktop-min;
    width: ~"calc(min(@{flyout-width}, 350px))";
    right: @hamburger-offset-y;
    color: @color0;
    font-size: (14 / @px);
    font-weight: 100;
    height: @height0;
    position: absolute;
    text-decoration: none;
    top: 0;
    z-index: (@min-z-index + 1);
    display: none;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;


    &::-webkit-scrollbar {
        width: 2px;
    }

    &--hidden {
        display: none;
    }

    &--will-animate {
        display: block;

        .enable-flyout {
            will-change: right;
        }
    }

    &__container {
        display: inline-block;
        padding: 0;
        margin-bottom: 0;
        color: @color0;
    }

    &__secondary-navigation {
        &--desktop {
            display: none;
        }

        &--mobile {
            .enable-flyout__list {
                padding-top: 20px;
                margin-top: 20px;
                position: relative;

                &::before {
                    content: "";
                    position: absolute;
                    top: 0;
                    left: 20px;
                    width: calc(100% - 40px);
                    height: 1px;
                    background: @color0;
                }
            }
        }
    }

    &__last-top-level-link {

        &::after {
            content: "";
            display: block;
            width: calc(100% - 40px);
            height: 1px;
            background: #fff;
            margin: 0 auto;

            @media @desktop {
                content: none;
            }
        }
    }

    // Animation for the hamburger menu icon stolen from:
    // https://codepen.io/designcouch/pen/Atyop

    &__hamburger-icon {
        @hamburger-width: 30px;
        @hamburger-height: 30px;
        @hamburger-padding-horiz: 18px;
        @hamburger-padding-vert: 8px;
        @hamburger-height-div-five: (@hamburger-width / 5);
        @hamburger-stroke-width: 6px;

        width: @hamburger-width;
        height: @hamburger-height;

        display: block;
        position: relative;
        margin: (@hamburger-padding-vert) (@hamburger-padding-horiz);
        transform: rotate(0deg);
        transition: 0.5s ease-in-out;
        cursor: pointer;
        top: 0;

        &-facade {
            display: block;
            width: @hamburger-width + (2 * @hamburger-padding-horiz);
            height: @hamburger-height + (2 * @hamburger-padding-vert);
            position: absolute;
            right: 2px;
            top: @hamburger-menu-icon-top;
            background: none;
            border: none;

            .enable-flyout-container--positioned-left & {
                right: initial;
                left: 2px;
            }
        }

        span {
            display: block;
            position: absolute;
            height: @hamburger-stroke-width;
            width: 100%;
            background: #FFF;

            // This is to ensure the logo appears in Windows
            // High Contast mode.
            border: 1px solid transparent;
            border-radius: (@hamburger-stroke-width / 2);
            opacity: 1;
            left: 0;
            transform: rotate(0deg);
            transition: 0.5s ease-in-out;

            &:nth-child(1) {
                top: 0px;
            }

            &:nth-child(2),
            &:nth-child(3) {
                top: (@hamburger-height-div-five * 2);
            }

            &:nth-child(4) {
                top: (@hamburger-height-div-five * 4);
            }
        }

        .enable-flyout__open-menu-button[aria-expanded="true"] & {
            span {
                background-color: white;
            }
            span:nth-child(1) {
                top: (@hamburger-height-div-five * 2);
                width: 0%;
                left: 50%;
            }

            span:nth-child(2) {
                transform: rotate(45deg);
            }

            span:nth-child(3) {
                transform: rotate(-45deg);
            }

            span:nth-child(4) {
                top: (@hamburger-height-div-five * 2);
                width: 0%;
                left: 50%;
                outline: none;
            }
        }
    }

    &__list {
        list-style-type: none;
        margin: 0;
        padding: 70px 0 0 0;
        height: @height0;
        background: @dark-grey;
    }

    &__separator {
        border: 1px solid #555555;
    }

    &__open-level-button,
    &__close-level-button,
    &__link {
        color: @color0 !important;
        display: block;
        font-family: "Helvetica", "Arial", "sans-serif";
        font-size: (18 / @px);
        line-height: 1.6;
        padding: (10 / @px) (12 / @px);
        text-decoration: none;
        transition: background @anim-time ease-in-out;
        width: 100%;
        background: transparent;
        border: none;
        text-align: left;
        font-weight: bold;

        .enable-flyout-container--positioned-left & {
            text-align: right;
        }

        // Corrects inability to style clickable `input` types in iOS
        .vendor(appearance, none);
        &:hover {
            background: @color1;
        }

        // Fix Windows Contrast Mode cutting off focus outline.
        &:focus {
            position: relative;
            z-index: 2;
        }
    }

    &__open-level-button {
        .enable-flyout-container--positioned-left & {
            padding-right: 10px;
        }
    }

    &__close-level-button {
        .enable-flyout-container--positioned-left & {
            padding-right: 20px;
        }
    }

    &__link {
        .enable-flyout-container--positioned-left & {
            padding-right: 19px;
        }
    }

    &__with-home-icon {
        position: relative;
        &::before {
            .icon-mixin("../images/Home.svg");
            top: (2 / @px);
        }
    }

    &__menu-item {
        width: 100%;
    }

    &__open-level-button {
        position: relative;
        &::after {
            .icon-mixin("../images/chevron-right.svg");
            top: (5 / @px);

            @media @desktop {
                top: (5 / @px);
            }
        }
    }

    &__body--is-open {
        height: @height0;
        overflow: hidden;
    }

    &__body--is-open &__overlay-screen {
        height: 100%;
        opacity: 1;
    }

    animation: enable-flyout__anim--mobile-close @anim-time ease-in-out forwards;
    &--is-open {
        display: block;
        visibility: visible;
        animation: enable-flyout__anim--mobile-open @anim-time ease-in-out
            forwards;

        /* fallback if animation is not supported *or* turned off */
        right: 0;

        .enable-flyout-container--positioned-left & {
            animation: enable-flyout__anim--mobile-open-left @anim-time
                ease-in-out forwards;

            /* fallback if animation is not supported *or* turned off */
            left: 0;
        }
    }

    &--is-closed {
        animation: enable-flyout__anim--mobile-open @anim-time ease-in-out
            reverse;

        /* fallback if animation is not supported *or* turned off */
        right: @hamburger-offset-y;

        .enable-flyout-container--positioned-left & {
            animation: enable-flyout__anim--mobile-open-left @anim-time
                ease-in-out reverse;

            /* fallback if animation is not supported *or* turned off */
            left: @hamburger-offset-y;
        }
    }

    &__level&--is-open {
        animation: enable-flyout__anim--mobile-open @anim-time ease-in-out
            forwards;

        /* fallback if animation is not supported *or* turned off */
        right: 0;

        .enable-flyout-container--positioned-left & {
            animation: enable-flyout__anim--mobile-open-left @anim-time
                ease-in-out forwards;

            /* fallback if animation is not supported *or* turned off */
            left: 0;
        }
    }

    &__level-heading {
        display: none;
    }

    &__close-level-button {
        background: @grey;
        cursor: pointer;
        display: block;
        transition: background @anim-time ease-in-out;
        position: relative;
        &::before {
            .icon-mixin("../images/chevron-left.svg");
            top: (4 / @px);

            @media @desktop {
                top: (5 / @px);
            }
        }

        &:hover {
            background: @color1;
        }
    }
    &__open-level-button {
        cursor: pointer;
        display: block;
        transition: background @anim-time ease-in-out;

        &:hover {
            background: @color1;
        }
    }

    &__open-menu-button {
        position: absolute;
        right: 2px;
        top: @hamburger-menu-icon-top;
        z-index: (@min-z-index + 2);

        .enable-flyout-container--positioned-left & {
            right: initial;
            left: 2px;
        }
    }

    &__overlay-screen {
        background: rgba(0, 0, 0, 0.7);
        bottom: 0;
        height: 0;
        opacity: 0;
        position: fixed;
        right: 0;
        top: 0;
        transition: opacity @large-anim-time ease-in-out;
        width: 100%;
        z-index: @min-z-index;
    }

    &__open-menu-button {
        background-color: @color3;
        border: none;
        display: block;
        margin: 50px auto;
        padding: 10px 40px;
        a {
            color: @color0;
            font-size: 2em;
        }
    }

    &__open-menu-button {
        border: none;
        margin: 0;
        padding: 0;
        width: auto;
        overflow: visible;

        background: transparent;

        // inherit font & color from ancestor
        color: inherit;
        font: inherit;

        // Normalize `line-height`. Cannot be changed from `normal` in Firefox 4+.
        line-height: normal;

        // Corrects font smoothing for webkit
        -webkit-font-smoothing: inherit;
        -moz-osx-font-smoothing: inherit;

        // Corrects inability to style clickable `input` types in iOS
        .vendor(appearance, none);
    }

    /* These items are hidden in the mobile breakpoint */
    &__link-image {
        display: none;
    }

    @media @desktop {
        width: 100%;
        visibility: visible;
        right: auto;
        margin: 0;
        left: 0px;
        animation: enable-flyout__anim--desktop-close @anim-time ease-in-out
            forwards;
        top: auto;
        height: auto;
        min-height: auto;

        --enable-flyout__is-hamburger: 0;

        &__secondary-navigation {
            &--mobile {
                display: none;
            }

            &--desktop {
                display: block;
                position: absolute;
                padding: 0;
                background: transparent;
                top: 0px;
                right: (230 / @px);

                & .enable-flyout {
                    &__link {
                        padding: 17px 0;
                        margin: -17px 0;
                        margin: 0;
                    }
                }
            }
        }

        &__hamburger-icon {
            &-facade {
                display: none;
            }
        }

        &__top-level {
            position: relative;
        }

        &__open-menu-button {
            display: none;
        }

        &__list {
            padding-top: 0;
        }

        &--is-open {
            animation: enable-flyout__anim--desktop-open @anim-time ease-in-out
                forwards;
            visibility: visible;
            border-bottom: 1px solid #ccc;
            box-shadow: 0 5px 5px rgba(0, 0, 0, 0.3);
        }

        &--is-closed {
            animation: enable-flyout__anim--desktop-open @anim-time ease-in-out
                reverse;
        }

        &__level&--is-open {
            width: 18rem;
            border-radius: 0 0 10px 10px;
            box-shadow: none;
            animation: enable-flyout__anim--desktop-open @anim-time ease-in-out
                forwards;
            visibility: visible;
            padding: 15px;
            top: 66px;
            left: -14px;
        }

        &__open-level-button,
        &__close-level-button,
        &__link {
            position: relative;

            &:hover {
                background: none;
                font-weight: bold;

                .enable-flyout__secondary-navigation--desktop & {
                    text-decoration: underline;
                }

                .enable-flyout__top-level
                    > .enable-flyout__list
                    > .enable-flyout__menu-item
                    > &:before {
                        content: "";
                        position: absolute;
                        width: calc(100% - 24px);
                        height: 2px;
                        background-color: #fff;
                        bottom: 12px;
                        left: 12px;

                    .enable-flyout__secondary-navigation--desktop & {
                        content: none;
                    }
                }
            }
        }

        &__level {
            display: none;
            overflow: visible;
        }

        &__level-heading {
            font-weight: bold;
            font-size: (25 / @px);
            border-bottom: 1px solid #999;
            padding: 0 14px;
            display: block;
            text-align: left;
        }

        &__top-level {
            display: inline-block;
            height: auto;
            overflow: visible;
        }

        &--is-open &__level {
            display: block;
            position: static;
            background: white;
            color: black;
            width: 100%;
        }

        &__menu-item {
            display: inline-block;
            width: auto;
            position: relative;
        }

        &--is-open &__menu-item {
            display: block;
        }

        &__list--photo-layout &__menu-item {
            width: (100% / 5);
            float: left;
            margin: 0;
        }

        &__list--photo-layout &__link {
            transition: transform @anim-time ease-in-out;
            &:hover,
            &:focus {
                transform: scale(1.2);
                font-weight: bold;
                background: white;
            }
        }

        &__list {
            display: inline;
            text-align: center;
            background: none;
        }

        &__open-level-button {
            &::after {
                background-image: data-uri("../images/chevron-down.svg");
            }

            &[aria-expanded="true"] {
                &::after {
                    background-image: data-uri("../images/chevron-up.svg");
                }
            }
        }

        &__close-level-button {
            display: none;
        }

        &__menu-item {

            &--close {
                display: none;
                padding-right: 0;
            }
        }

        &__link {
            display: inline-block;
            text-align: center;
        }

        &__link-image {
            display: block;
            margin: 0 auto 10px auto;
            width: 180px;
        }

        &--is-open {
            display: block;
            background: @dark-grey;

            .enable-flyout__open-level-button,
            .enable-flyout__close-level-button,
            .enable-flyout__link {
                color: #FFF;
                text-align: left;

                &::after {
                    filter: none;
                }
            }
        }
    }
}

@keyframes enable-flyout__anim--mobile-open {
    0% {
        right: @hamburger-offset-y;
    }

    100% {
        right: 0;
    }
}

@keyframes enable-flyout__anim--mobile-close {
    0% {
        right: 0;
    }

    0.999% {
        right: @hamburger-offset-y;
    }
}

@keyframes enable-flyout__anim--mobile-open-left {
    0% {
        left: @hamburger-offset-y;
    }

    100% {
        left: 0;
    }
}

@keyframes enable-flyout__anim--mobile-close-left {
    0% {
        left: 0;
    }

    0.999% {
        left: @hamburger-offset-y;
    }
}
