@import "../../../../../styles/definitions/mixins";
@import "../../../../../styles/definitions/breakpoints";

// Local Variables
$home-bar-border-thickness: 1px;
$home-bar-nav-icon-size: 20px;
$header-default-zindex: 1;

$link-color: var(--text-color, $header-nav-link-color);
$link-hover-color: var(--text-hover-color, $header-nav-link-hover-color);
$link-active-color: var(--text-active-color, $header-nav-link-active-color);

$vertical-padding: var(--bar-vertical-padding, 20px);

$home-bar-height: calc((var(--bar-vertical-padding, 20px) - 40px) / 2);

$home-bar-max-current-height: calc((max(#{$vertical-padding}, var(--logo-height) + 20px)) / 2 + 11px);

%home-bar-nav-icon {
    width: $home-bar-nav-icon-size;
    height: auto;
}

// Component Styles
.headerHomeBar {
    &_homeBar {
        position: relative;

        // apply padding on parent item so bottom border goes inside when hover
        .headerNavigation_item {
            // fix on Safari so underline goes inside padding
            align-items: center;
        }

        .headerNavigation_subMenu {
            top: 30px;
            left: auto;
            width: 300px;
        }

        .headerNavigation_subMenuLink {
            padding: 12px 20px;
        }
    }

    &_userDropdownBtn .buttonIcon_icon {
        @include fill-header-arrow-svg-color($link-color);
    }

    &_userDropdownLink {
        &--userCompanyDropDown {
            background: none;
            border: none;
            margin: 0;
            font: inherit;
            text-decoration: none;
            cursor: pointer;
            width: 100%;

            &:hover,
            &:focus {
                text-decoration: underline;
            }
            > span {
                width: 100%;
            }
        }
    }

    &_userDropdownItem {
        &--userDropdownCompanySwitcher {
            font-size: 12px;
            color: $gray-61;
            padding: 6px 12px 4px;
            letter-spacing: 0.5px;
            text-transform: uppercase;
        }
    }

    &_userCompanyDropdownSpan {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    &_userCompanyText {
        text-align: left;
    }

    &_userCompanyDropdownSpanSelected {
        display: flex;
        font-size: 14px;
        color: #29732d;
        font-weight: 500;
        text-transform: capitalize;
        margin-top: 2px;
    }

    &_userCompanyDropdownSelectedCompany {
        color: #29732d
    }

    &_menuDivider {
        border: none;
        border-top: 1px solid #e0e0e0;
    }

    &_wrapper {
        position: relative;
        display: flex;
        justify-content: space-between;
        align-items: center;
        align-content: center;
        background-color: var(--background-color, $header-nav-bg-color);
        padding-top: 10px;
        padding-bottom: 10px;
        height: calc(max(#{$vertical-padding}, var(--logo-height) + 20px));

        &::before {
            content: "";
            display: block;
            width: 100vw;
            height: 100%;
            position: absolute;
            top: 0;
            left: 50%;
            margin-left: -50vw;

            background-color: var(--background-color, $header-nav-bg-color);
            border-top: $home-bar-border-thickness solid var(--border-color, $header-nav-border-color);
            border-bottom: $home-bar-border-thickness solid var(--border-color, $header-nav-border-color);
        }

        @include media-lg-down {
            flex-wrap: wrap;
            height: fit-content
        }

        &--small-text,
        &--small-text .headerHomeBar_userName {
            @include default($bodyFontSize6);
            @include fontFamily;
        }

        &--medium-text,
        &--medium-text .headerHomeBar_userName {
            @include default($bodyFontSize5);
            @include fontFamily;
        }

        &--large-text,
        &--large-text .headerHomeBar_userName {
            @include default($bodyFontSize4);
            @include fontFamily;
        }

        &--only-quicknav .headerHomeBar_homeBarNav {
            margin-left: auto;
        }
    }

    &_logoWrapper {
        margin-right: 30px;
        z-index: 1;
    }

    &_navigation {
        flex-shrink: 0;
        margin: $home-bar-height 15px $home-bar-height 0;
        flex-grow: 1;
        align-self: stretch;
    }

    &_centerSearch {
        display: flex;
        z-index: 1;

        @include media-md-down {
            width: 100%;
            order: 3;
            padding-top: 10px;
        }

        @include media-between-md-lg {
            padding-top: 10px;
        }

        @include media-lg-up {
            width: 250px;
            margin-right: -15px;
        }

        @include media-xxl-up {
            width: var(--center-search-width);
            margin-left: auto;
        }
    }

    &_searchBar {
        flex-grow: 1;
    }

    &_burgerBtn {
        margin-right: 20px;
        z-index: 1;
        // Necessary to proceed this way instead of .headerHomeBar_burgerIcon
        // because ButtonIcon's svg fill has a higher specificity
        svg,
        &:focus svg {
            fill: $link-color;
        }
    }

    &_mobileMenu {
        position: absolute;
        top: 100%;
        left: 50%;
        transform: translateX(-50%);
        z-index: calc($header-default-zindex + 3);
    }

    &_homeBarNav {
        display: flex;
        align-self: stretch;
        flex-shrink: 0;
        margin-left: -$grid-gutter-width;
        margin-right: -$grid-gutter-width;

        &--nav {
            margin-right: $grid-gutter-width;
        }

        &--quick-links {
            margin-left: auto;
        }

        &List {
            @extend %reset-list;
            display: flex;
            align-items: stretch;

            @include media-md-down {
                flex-direction: column;
                justify-content: center;
                align-items: flex-end;
            }
        }

        &Item {
            display: flex;
            align-items: stretch;
            margin: 0 $grid-gutter-width;
            position: relative;

            .buttonIcon_icon--right+.buttonIcon_text {
                margin-right: $header-dropdown-arrow-spacing;
            }
        }

        &Link {
            justify-content: flex-end;
            display: flex;
            align-items: center;

            color: $link-color;
            fill: $link-color;

            &:hover,
            &:focus {
                color: $link-hover-color;
                fill: $link-hover-color;
                text-decoration: none;
            }

            &:active {
                color: $link-active-color;
                fill: $link-active-color;
                text-decoration: none;
            }

            @include media-md-down {
                &--cart svg {
                    height: 20px;
                }
            }
        }

        &Icon {
            @extend %home-bar-nav-icon;
        }

        @include media-md-down {
            margin-left: auto;
        }
    }

    &_cart {
        &Icon {
            @extend %home-bar-nav-icon;
        }

        &Notification {
            position: absolute;
            left: 10px;
            padding: 3px 5px;
            background-color: $green-33;
            color: $white;
            border: 0;
            border-radius: 2px;
            line-height: 1;

            @include media-md-down {
                top: -6px;
            }

            @include media-md-up {
                top: -3px
            }

            @include media-lg-up {
                top: calc(
                    max(
                        var(--bar-vertical-padding, 20px) - 40px,
                        var(--logo-height) - 20px
                        ) / 2  - 5px
                    );
            }
        }

        &Overlay {
            position: absolute;
            top: $home-bar-max-current-height;
            right: 0;
            width: 420px;
            z-index: calc($header-default-zindex + 3);

            &:before{
                z-index: -1;
            }

            @include media-md-up {
                min-width: 400px;
            }

            @include media-lg-down {
                top: 50px;
            }

            @include media-md-down {
                width: calc(100vw - 2 * #{$grid-gutter-width});
            }
        }
    }

    &_userLabel {
        display: inline-flex;
        align-items: center;
        color: $link-color;
    }

    &_userDropdown {
        &Btn {
            svg {
                width: $header-dropdown-arrow-icon-width;
                fill: $link-color;
            }
            &:hover,
            &:focus {
                .headerHomeBar_userLabel {
                    color: $link-hover-color;
                }
                svg {
                    fill: $link-hover-color;
                    @include fill-header-arrow-svg-color($link-hover-color);
                }
            }

            &:active {
                .headerHomeBar_userLabel {
                    color: $link-active-color;
                }
                svg {
                    fill: $link-active-color;
                }
            }
        }
        &List {
            @extend %reset-list;
            position: absolute;
            top: $home-bar-max-current-height;
            right: 0;
            width: 200px;
            border: 1px solid $gray-80;
            border-radius: 3px;
            z-index: calc($header-default-zindex + 3);
            background-color: $white;
            visibility: hidden;

            @include media-lg-down {
                top: 50px;
            }

            &--visible {
                visibility: visible;
            }

            @include sub-menu-nub;
        }
        &Link {
            display: flex;
            justify-content: flex-start;
            padding: 10px;
            position: relative;
            color: $title-color;

            &:hover,
            &:focus {
                background-color: $light-gray;
                text-decoration: none;
            }
        }
    }

    &_userAvatar {
        margin-right: 10px;
    }
}
