/**
 * 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 "../button_styles_mixins" as button_styles;

$tlp-tabs-transition: 75ms ease-out;
$active-tab-border-width: 3px;
$inactive-tab-right-border-width: 1px;
$inactive-tab-right-margin: calc(
    var(--tlp-medium-spacing) + #{$active-tab-border-width} - #{$inactive-tab-right-border-width}
);

.tlp-tabs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    margin: 0 0 var(--tlp-medium-spacing);
    padding: 0 var(--tlp-medium-spacing);
    box-shadow: inset 0 -1px 0 var(--tlp-neutral-normal-color);
}

.tlp-tabs-vertical {
    flex-direction: column;
    align-items: flex-start;
    padding: 0;
    border-radius: var(--tlp-large-radius);
    box-shadow: none;
}

.tlp-pane > .tlp-pane-container > .tlp-tabs {
    margin: 0;
    padding: 0;
    box-shadow: inset 0 -1px 0 var(--tlp-neutral-normal-color);
}

.tlp-tab-menu {
    display: flex;
    position: absolute;
    z-index: 10000;
    bottom: 7px;
    left: 0;
    flex-direction: column;
    min-width: 100%;
    padding: calc(var(--tlp-medium-spacing) / 2) 0;
    transform: translateY(100%);
    transition:
        bottom $tlp-tabs-transition,
        opacity $tlp-tabs-transition,
        box-shadow $tlp-tabs-transition;
    border-top: 0;
    border-bottom: 0;
    border-radius: 0 0 var(--tlp-large-radius) var(--tlp-large-radius);
    opacity: 0;
    background: var(--tlp-white-color);
    box-shadow: none;
    pointer-events: none;
}

.tlp-tab-menu-title {
    margin: calc(var(--tlp-medium-spacing) / 2) 0 0;
    padding: var(--tlp-medium-spacing) var(--tlp-medium-spacing) calc(var(--tlp-medium-spacing) / 2);
    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;

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

.tlp-tab-menu-item {
    padding: calc(var(--tlp-medium-spacing) / 2) var(--tlp-medium-spacing);
    color: var(--tlp-dark-color);
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: normal;
    line-height: 1rem;
    text-decoration: none;
    text-transform: none;
    white-space: nowrap;

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

    &:last-child {
        border-radius: 0 0 var(--tlp-large-radius) var(--tlp-large-radius);
    }

    &.tlp-text-danger {
        color: var(--tlp-danger-dark-color);

        &:focus,
        &:hover {
            background: var(--tlp-danger-color-transparent-90);
            color: var(--tlp-danger-dark-color);
        }
    }
}

.tlp-tab-menu-separator {
    width: 100%;
    border-top: 1px solid var(--tlp-neutral-light-color);
}

button:where(.tlp-tab) {
    @include button_styles.unset-button-style;

    cursor: pointer;

    &:focus {
        color: var(--tlp-main-color);
    }
}

.tlp-tab {
    display: flex;
    position: relative;
    flex: 0 0 auto;
    align-items: center;
    align-self: stretch;
    min-height: var(--tlp-jumbo-spacing);
    padding: 0 var(--tlp-large-spacing);
    transition:
        color $tlp-tabs-transition,
        border-bottom-color $tlp-tabs-transition;
    border-bottom: $active-tab-border-width solid transparent;
    color: var(--tlp-dimmed-color);
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    text-transform: capitalize;

    &.tlp-tab-active,
    &:hover {
        border-bottom-color: var(--tlp-main-color);
        color: var(--tlp-main-color);
        text-decoration: none;
    }

    &.tlp-tab-disabled,
    &.tlp-tab-disabled:hover,
    &[disabled],
    &[disabled]:hover {
        border-bottom-color: transparent;
        color: var(--tlp-dimmed-color-lighter-50);
        cursor: not-allowed;

        > .tlp-tab-badge-append {
            opacity: 0.25;
        }
    }

    &:hover > .tlp-tab-menu {
        bottom: -$active-tab-border-width;
        transition:
            bottom $tlp-tabs-transition,
            opacity $tlp-tabs-transition;
        opacity: 1;
        box-shadow: var(--tlp-flyover-shadow);
        pointer-events: auto;
    }

    > .fa-caret-down {
        margin: 0 0 0 var(--tlp-small-spacing);
        font-size: 0.7rem;
    }
}

.tlp-tabs-vertical > .tlp-tab {
    justify-content: flex-end;
    width: 100%;
    padding: var(--tlp-medium-spacing) $inactive-tab-right-margin var(--tlp-medium-spacing)
        var(--tlp-medium-spacing);
    transition:
        color $tlp-tabs-transition,
        border-right-color $tlp-tabs-transition;
    border: 0;
    border-right: $inactive-tab-right-border-width solid
        var(--tlp-neutral-dark-color-transparent-50);
    line-height: 0.875rem;
    white-space: nowrap;

    &.tlp-tab-active,
    &:hover {
        padding: var(--tlp-medium-spacing);
        border: 0;
        border-right: $active-tab-border-width solid var(--tlp-main-color);
    }

    &.tlp-tab-disabled,
    &.tlp-tab-disabled:hover,
    &[disabled],
    &[disabled]:hover {
        padding: var(--tlp-medium-spacing) $inactive-tab-right-margin var(--tlp-medium-spacing)
            var(--tlp-medium-spacing);
        border-right: $inactive-tab-right-border-width solid
            var(--tlp-neutral-dark-color-transparent-50);
        color: var(--tlp-dimmed-color-lighter-50);

        > .tlp-tab-badge-append {
            opacity: 0.25;
        }
    }

    > .tlp-tab-icon {
        order: 1;
        margin: 0 0 0 var(--tlp-small-spacing);
    }
}

.tlp-tabs-vertical-section {
    width: 100%;
    margin: 0;
    padding-bottom: var(--tlp-medium-spacing);
    border-right: $inactive-tab-right-border-width solid
        var(--tlp-neutral-dark-color-transparent-50);
    border-radius: 0;

    > .tlp-tab {
        border-color: transparent;
    }
}

.tlp-tabs-vertical-section-title {
    width: 100%;
    margin: 0;
    padding: 0 $inactive-tab-right-margin 0 var(--tlp-medium-spacing);
    color: var(--tlp-dimmed-color-lighter-30);
    font-size: 0.85rem;
    font-weight: 800;
    text-align: end;
    text-transform: uppercase;
}

.tlp-tab-icon {
    margin: 0 var(--tlp-small-spacing) 0 0;
    font-size: 0.75rem;

    &.fa-external-link-alt {
        margin: 0 0 0 var(--tlp-small-spacing);
        font-size: 0.625rem;
    }
}

.tlp-tab-badge-append {
    margin: calc(-1 * var(--tlp-small-spacing)) 0 calc(-1 * var(--tlp-small-spacing))
        var(--tlp-small-spacing);
    transition: opacity $tlp-tabs-transition;
    border-radius: var(--tlp-medium-spacing);
    letter-spacing: normal;
    line-height: unset;
    text-transform: none;
}
