/**
 * Copyright (c) Enalean, 2017 - 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/>.
 */

$step-transition-duration: 75ms;
$step-background: var(--tlp-white-color);
$step-color: var(--tlp-dark-color);
$step-active-color: var(--tlp-main-color);
$step-active-background: var(--tlp-main-color-transparent-90);
$switch-menu-background: var(--tlp-white-color);
$switch-menu-item-color: var(--tlp-dark-color);
$switch-menu-item-hover-background: var(--tlp-main-color-transparent-90);
$switch-menu-item-hover-color: var(--tlp-main-color);

.breadcrumb-container {
    display: flex;
    align-items: center;
    padding: var(--tlp-medium-spacing) var(--tlp-medium-spacing) 0;
}

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    font-weight: 600;
}

.breadcrumb-item {
    display: inline-flex;
    position: relative;
    align-items: center;
    margin: 0 8px 0 0;
    line-height: 1rem;

    &:last-child {
        margin: 0;
    }

    &:not(:last-child)::after {
        content: "\f054"; // fa-chevron-right
        position: relative;
        top: 1px;
        right: -4px;
        font-family: "Font Awesome 6 Free";
        font-size: 0.55rem;
    }

    &:not(.breadcrumb-item-disabled):hover > .breadcrumb-link,
    &:not(.breadcrumb-item-disabled):focus-within > .breadcrumb-link {
        background: $step-active-background;
        color: $step-active-color;
    }
}

.breadcrumb-link {
    position: relative;
    padding: 4px 6px;
    border-radius: var(--tlp-medium-radius);
    color: $step-color;
    font-size: 0.875rem;

    &:hover {
        text-decoration: none;
    }
}

.breadcrumb-switchable {
    > .breadcrumb-link {
        padding: 4px 20px 4px 6px;

        &::after {
            content: "\f0d7"; // fa-caret-down
            position: absolute;
            z-index: 1;
            right: 8px;
            transition: color $step-transition-duration;
            opacity: 0.5;
            font-family: "Font Awesome 6 Free";
            font-size: 0.625rem;
        }
    }

    &:hover,
    &:focus-within {
        > .breadcrumb-switch-menu-container {
            transform: translateY(0);
            opacity: 1;
            pointer-events: auto;
        }

        > .breadcrumb-link::after {
            color: $step-active-color;
        }
    }
}

.breadcrumb-switch-menu-container {
    position: absolute;
    z-index: 1000;
    top: 24px;
    left: 0;
    min-width: 100%;
    max-width: 350px;
    padding: 6px 0 0;
    transform: translateY(-10px);
    transition:
        opacity $step-transition-duration,
        transform $step-transition-duration;
    opacity: 0;
    pointer-events: none;
}

.breadcrumb-switch-menu {
    border-radius: var(--tlp-medium-radius);
    background: $switch-menu-background;
    box-shadow: var(--tlp-flyover-shadow);
}

.breadcrumb-dropdown-item {
    &:hover > .breadcrumb-dropdown-link {
        background: $switch-menu-item-hover-background;
        color: $switch-menu-item-hover-color;
    }

    &:nth-child(2) > .breadcrumb-dropdown-link {
        border-radius: var(--tlp-medium-radius) var(--tlp-medium-radius) 0 0;
    }

    &:last-child > .breadcrumb-dropdown-link {
        border-radius: 0 0 var(--tlp-medium-radius) var(--tlp-medium-radius);
    }

    &:nth-child(2):last-child > .breadcrumb-dropdown-link {
        border-radius: var(--tlp-medium-radius);
    }
}

.breadcrumb-dropdown-link {
    display: block;
    padding: var(--tlp-small-spacing) var(--tlp-medium-spacing);
    overflow: hidden;
    color: $switch-menu-item-color;
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: normal;
    line-height: 1rem;
    text-overflow: ellipsis;
    white-space: nowrap;

    &:hover {
        text-decoration: none;
    }
}

.breadcrumb-dropdown-separator {
    display: block;
    margin: var(--tlp-small-spacing) 0;
    border-top: 1px solid var(--tlp-neutral-light-color);

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

.breadcrumb-dropdown-section-title {
    margin: var(--tlp-small-spacing) 0 0;
    padding: var(--tlp-medium-spacing) var(--tlp-medium-spacing) var(--tlp-small-spacing);
    border-top: 1px solid var(--tlp-neutral-light-color);
    color: var(--tlp-dimmed-color);
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    line-height: 1rem;
    text-transform: uppercase;
    white-space: nowrap;

    &:first-child {
        margin: 0;
        padding: var(--tlp-small-spacing) var(--tlp-medium-spacing);
        border-top: 0;
    }
}

.breadcrumb-project-privacy-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    color: var(--tlp-white-color);
    font-size: 0.7rem;
    cursor: help;

    &.fa-lock,
    &.fa-tlp-lock-plus-r {
        background: var(--tlp-main-color);
    }

    &.fa-lock-open,
    &.fa-tlp-unlock-plus-r {
        background: var(--tlp-dark-color-transparent-90);
        color: var(--tlp-dark-color-lighter-10);
    }
}

.breadcrumb-project-privacy-icon-with-flags {
    display: flex;
    align-items: center;
    margin: 0 var(--tlp-small-spacing) 0 0;
    padding: 4px;
    border-radius: var(--tlp-medium-radius);
    cursor: help;

    &[data-privacy-icon="fa-lock"],
    &[data-privacy-icon="fa-tlp-lock-plus-r"] {
        background: var(--tlp-main-color-transparent-90);
        color: var(--tlp-main-color);

        > .breadcrumb-project-privacy-icon {
            color: var(--tlp-main-color);
        }
    }

    &[data-privacy-icon="fa-lock-open"],
    &[data-privacy-icon="fa-tlp-unlock-plus-r"] {
        background: var(--tlp-dark-color-transparent-90);
        color: var(--tlp-dark-color-lighter-10);

        > .breadcrumb-project-privacy-icon {
            color: var(--tlp-dark-color-lighter-10);
        }
    }

    > .breadcrumb-project-privacy-icon {
        width: auto;
        height: auto;
        margin: 0 8px 0 6px;
        background: none;
        font-size: 0.875rem;
    }

    > .tuleap-svg-project-shield {
        display: none;
    }

    + #current-project-nav-title-popover {
        margin-top: 0;
    }
}

body:not(.sidebar-collapsed) {
    .breadcrumb-project-privacy-icon-with-flags,
    .breadcrumb-project-privacy-icon,
    .breadcrumb-with-only-one-item,
    .breadcrumb-project {
        display: none;
    }
}

.current-project-nav-flag-labels {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
}

.current-project-nav-flag-label {
    max-width: 150px;
    overflow: hidden;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    line-height: 0.625rem;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}
