/**
 * Copyright (c) Enalean, 2016-Present. All Rights Reserved.
 *
 * This file is a part of Tuleap.
 *
 * Tuleap is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Tuleap is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Tuleap. If not, see <http://www.gnu.org/licenses/>.
 */

@use "variables-common";
@use "pkg:@tuleap/tlp-popovers";

$nav-dropdown-content-border-radius: var(--tlp-large-radius);
$dropdown-width: 250px;

/* stylelint-disable selector-no-qualifying-type */
body.has-visible-project-banner > .platform-banner:not(.platform-banner-hidden) {
    padding: var(--tlp-medium-spacing) var(--tlp-medium-spacing)
        variables-common.$top-floating-buttons-space;

    + header > .header-container {
        padding: var(--tlp-small-spacing) var(--tlp-medium-spacing) 0 0;
    }
}

header {
    position: fixed;
    z-index: 2004;
    top: 0;
    right: 0;
    justify-content: space-between;
    transition:
        background ease-in-out 100ms,
        box-shadow ease-in-out 100ms,
        top ease-in-out 50ms;

    &.full-width {
        width: 100%;

        + #main-container {
            margin-top: 64px;
        }
    }

    &.pinned {
        background: var(--tlp-white-color);
        box-shadow: var(--tlp-sticky-header-shadow);

        > .header-container {
            padding: 0 var(--tlp-medium-spacing) 0 0;

            .btn {
                padding: 0 var(--tlp-small-spacing);
                border-color: transparent !important;
                background: none !important;
                box-shadow: none !important;

                &:hover:not(:disabled, .disabled, .active),
                &:focus:not(:disabled, .disabled, .active),
                &:active:not(:disabled, .disabled, .active) {
                    border-color: transparent !important;
                    opacity: 0.7;
                    background: none !important;
                    box-shadow: none !important;
                }
            }

            .user-nav > .user-avatar {
                box-shadow: none;
            }
        }
    }
}

body.has-sidebar {
    header.pinned {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        width: calc(100% - #{variables-common.$sidebar-width});
        height: variables-common.$navbar-height;
    }

    &.sidebar-collapsed header.pinned {
        width: calc(100% - #{variables-common.$sidebar-width-collapsed});
    }
}

.header-container {
    display: flex;
    box-sizing: border-box;
    align-items: center;
    justify-content: space-between;
    padding: var(--tlp-medium-spacing) var(--tlp-medium-spacing) 0;
    transition: padding ease-in-out 100ms;

    .btn:not(.btn-link),
    .btn {
        display: inline-flex;
        box-sizing: border-box;
        align-items: center;
        justify-content: center;
        height: 40px;
        margin: 0 0 0 var(--tlp-small-spacing);
        padding: 0 var(--tlp-medium-spacing);
        overflow: hidden;
        transition:
            box-shadow 75ms ease-in-out,
            background 75ms ease-in-out,
            border-color 75ms ease-in-out,
            padding 75ms ease-in-out;
        border-radius: 30px;
        border-color: var(--tlp-white-color) !important;
        background: var(--tlp-white-color) !important;
        box-shadow: var(--tlp-button-shadow) !important;
        color: var(--tlp-dark-color);
        font-family: var(--tlp-font-family);
        font-size: 0.875rem;
        font-weight: 500;
        letter-spacing: 0;
        line-height: 1.5rem;
        text-decoration: none;
        text-transform: none;
        vertical-align: middle;
        white-space: nowrap;
        cursor: pointer;

        &:hover:not(:disabled, .disabled, .active),
        &:active:not(:disabled, .disabled, .active),
        &:focus:not(:disabled, .disabled, .active) {
            transition:
                box-shadow 75ms ease-in-out,
                background 75ms ease-in-out,
                border-color 75ms ease-in-out;
            border-color: var(--tlp-white-color) !important;
            background: #fafafa !important;
            box-shadow: var(--tlp-button-shadow-hover) !important;
            text-decoration: none;
        }

        &:active:not(:disabled, .disabled, .active),
        &:focus:not(:disabled, .disabled, .active) {
            background: var(--tlp-background-color-lighter-50) !important;
        }

        > .btn-icon {
            margin: 0 8px 0 0;
            font-size: 0.85rem;
        }

        @media screen and (max-width: 1100px) {
            width: 40px;

            > .btn-icon {
                margin: 0;
            }

            > .header-button-label {
                position: absolute;
                clip-path: inset(50%);
                white-space: nowrap;
            }
        }
    }
}

.header-container-spacer {
    flex: 1 1 auto;
}

.btn.admin-link:not(.btn-link) {
    width: 40px;
    padding: 0;
    color: var(--tlp-danger-color);

    > .fa-cogs {
        margin: 0;
    }
}

.new-nav,
.user-nav {
    position: relative;

    > .nav-link {
        margin: 0 0 0 var(--tlp-large-spacing);
        transition: opacity ease-in-out 75ms;
        color: var(--tlp-dimmed-color);
        font-size: 0.875rem;

        &:hover {
            color: var(--tlp-dark-color);
            text-decoration: none;
        }
    }

    > .nav-dropdown {
        width: $dropdown-width;

        > .tlp-popover-arrow {
            &::before {
                background: none;
            }

            &::after {
                background: var(--tlp-dark-color);
            }
        }

        > .tlp-popover-header {
            min-height: 4px;
            padding: 0 var(--tlp-small-spacing);
            background: var(--tlp-dark-color);
        }

        > .tlp-popover-body {
            padding: 0;
        }
    }
}

.nav-dropdown-item {
    display: flex;
    box-sizing: border-box;
    align-items: center;
    width: 100%;
    padding: var(--tlp-small-spacing) var(--tlp-medium-spacing);
    overflow: hidden;
    border: 0;
    background: var(--tlp-white-color);
    color: var(--tlp-dark-color);
    font-family: var(--tlp-font-family);
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: normal;
    line-height: 1rem;
    text-align: left;
    text-decoration: none;
    text-transform: none;
    white-space: nowrap;
    cursor: pointer;

    &:focus,
    &:hover {
        background: var(--tlp-main-color-transparent-90);
        color: var(--tlp-main-color);
        text-decoration: none;
    }

    &:last-child {
        margin: 0 0 var(--tlp-small-spacing);
    }

    > .nav-dropdown-item-icon {
        margin: 0 calc(var(--tlp-small-spacing) / 1.5) 0 0;
        font-size: 0.7rem;
    }
}

.nav-dropdown-item-title {
    padding: var(--tlp-medium-spacing) var(--tlp-medium-spacing) var(--tlp-small-spacing);
    color: var(--tlp-dimmed-color);
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    line-height: 1rem;
    text-transform: uppercase;
}

.nav-dropdown-item-divider {
    margin: var(--tlp-small-spacing) 0;
    border-top: 1px solid var(--tlp-neutral-normal-color);

    &:first-child {
        display: none;
    }
}

.nav-dropdown-form {
    margin: 0;
}

.nav-dropdown-item-unique-dashboard:last-child {
    margin: var(--tlp-small-spacing) 0;
}

.user-nav {
    > .user-avatar {
        width: 38px;
        height: 38px;
        margin: 0 0 0 var(--tlp-small-spacing);
        padding: 0;
        overflow: hidden;
        border: 1px solid var(--tlp-white-color);
        border-radius: 50%;
        box-shadow: var(--tlp-button-shadow);
        cursor: pointer;

        &:hover,
        &:focus {
            box-shadow: var(--tlp-button-shadow-hover);
        }
    }

    > .nav-dropdown > .tlp-popover-header > .user-avatar {
        flex: 0 0 auto;
        width: 40px;
        height: 40px;
        margin: var(--tlp-small-spacing) var(--tlp-small-spacing) var(--tlp-small-spacing) 0;
        overflow: hidden;
        border-radius: 50%;
    }

    .user-infos-names {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        letter-spacing: normal;
        text-transform: none;
    }

    .user-infos-real-name {
        // we substract the size of the tlp-avatar and the padding around and between the elements
        max-width: calc(
            #{$dropdown-width} - (var(--tlp-small-spacing) + 40px + var(--tlp-small-spacing) +
                        var(--tlp-small-spacing))
        );
        margin: 0 0 4px;
        overflow: hidden;
        color: var(--tlp-white-color);
        font-size: 0.875rem;
        font-weight: 600;
        line-height: 1;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .user-infos-login-name {
        color: var(--tlp-neutral-dark-color);
        font-size: 0.75rem;
        font-weight: 400;
        line-height: 1;
    }
}
