/**
 * 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/>.
 */

$tlp-dropdown-radius: var(--tlp-large-radius);
$tlp-dropdown-arrow-size: 10px;
$tlp-dropdown-transition: 75ms ease-out;

.tlp-dropdown {
    display: inline-block;
    position: relative;
}

.tlp-dropdown-menu {
    display: none;
    position: absolute;
    z-index: 1000;
    flex-direction: column;
    padding: var(--tlp-small-spacing) 0;
    transition: box-shadow $tlp-dropdown-transition;
    border-bottom: 0;
    border-radius: $tlp-dropdown-radius;
    background: var(--tlp-white-color);
    box-shadow: none;
    pointer-events: none;

    &:not(.tlp-dropdown-submenu) {
        margin: $tlp-dropdown-arrow-size 0 0;

        &::before,
        &::after {
            content: "";
            display: block;
            position: absolute;
            left: 20px;
            width: 0;
            height: 0;
            margin: 0 #{-$tlp-dropdown-arrow-size};
            border: $tlp-dropdown-arrow-size solid transparent;
        }

        &::before {
            bottom: calc(100% + 1px);
            border-bottom-color: var(--tlp-dark-color-transparent-90);
        }

        &::after {
            bottom: 100%;
            border-bottom-color: var(--tlp-white-color);
        }

        &[data-placement^="top"] {
            &::before {
                top: calc(100% + 1px);
                border-top-color: var(--tlp-dark-color-transparent-90);
                border-bottom-color: transparent;
            }

            &::after {
                top: 100%;
                border-top-color: var(--tlp-white-color);
                border-bottom-color: transparent;
            }
        }

        &[data-placement$="end"] {
            &::before,
            &::after {
                right: 20px;
                left: auto;
            }
        }
    }

    &.tlp-dropdown-shown {
        display: flex;
        box-shadow: var(--tlp-flyover-shadow);
        pointer-events: auto;

        &.tlp-dropdown-menu-on-icon {
            $offset-for-icon: 10px;

            transform: translateX(-$offset-for-icon);

            &[data-placement$="end"] {
                transform: translateX($offset-for-icon);
            }
        }
    }

    &.tlp-dropdown-with-tabs-on-top {
        padding: 0 0 var(--tlp-small-spacing);

        > .tlp-tabs {
            margin: 0 0 var(--tlp-small-spacing);
            padding: 0;
            background: none;
            box-shadow: inset 0 -1px 0 var(--tlp-neutral-light-color);
        }
    }

    &.tlp-dropdown-menu-large {
        transform: translateX(3px);

        &[data-placement$="end"] {
            transform: translateX(-4px);
        }
    }
}

.tlp-dropdown-menu-actions {
    display: flex;
    justify-content: space-between;
    padding: var(--tlp-small-spacing) var(--tlp-medium-spacing);
    gap: var(--tlp-medium-spacing);
}

.tlp-dropdown-menu-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;

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

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

.tlp-dropdown-menu-item {
    padding: var(--tlp-small-spacing) var(--tlp-medium-spacing);
    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-hover-background);
        color: var(--tlp-main-color);
        text-decoration: none;
    }

    &.tlp-dropdown-menu-item-submenu {
        position: relative;
        padding: var(--tlp-small-spacing) var(--tlp-large-spacing) var(--tlp-small-spacing)
            var(--tlp-medium-spacing);

        &::after {
            content: "";
            display: block;
            position: absolute;
            top: 10px;
            right: var(--tlp-small-spacing);
            width: 4px;
            height: 12px;
            background: var(--tlp-dimmed-color);
            mask-image: url("./assets/dropdown-caret.svg");
        }

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

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

.tlp-dropdown-menu-item-disabled,
.tlp-dropdown-menu-item[disabled] {
    opacity: 0.5;
    cursor: not-allowed;

    &:focus,
    &:hover {
        background: inherit;
        color: inherit;
    }
}

.tlp-dropdown-menu-text {
    padding: var(--tlp-small-spacing) var(--tlp-medium-spacing);
    border: 0;
    color: var(--tlp-dimmed-color);
    font-size: 0.8125rem;
    font-weight: 400;
    letter-spacing: normal;
    line-height: 1.125rem;
    text-align: left;
    text-decoration: none;
    text-transform: none;
    white-space: nowrap;
}

.tlp-dropdown-menu-item-danger {
    color: var(--tlp-danger-dark-color);

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

.tlp-dropdown-split-button {
    display: flex;
    align-items: center;
}

.tlp-dropdown-split-button-main[class*="tlp-button"] {
    border-right: 0;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.tlp-dropdown-split-button-caret[class*="tlp-button"] {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;

    &.tlp-button-large {
        padding: 0 var(--tlp-medium-spacing);
    }
}
