/**
 * Copyright (c) Enalean, 2022-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 "sass:color";
@use "sass:map";
@use "pkg:@tuleap/tlp-swatch-colors";

.list-picker-selection {
    display: flex;
    box-sizing: border-box;
    align-items: center;
    width: 100%;
    border: 1px solid var(--tlp-form-element-border-color);
    border-radius: var(--tlp-form-element-border-radius);
    background: var(--tlp-form-element-background);
    font-size: var(--tlp-form-element-font-size);
    line-height: normal;
    cursor: default;
    user-select: none;

    &.list-picker-single {
        height: var(--tlp-form-element-height);
        padding: 0
            calc(
                (var(--tlp-form-element-padding-horizontal) * 2) +
                    var(--tlp-form-element-select-background-size)
            )
            0 var(--tlp-form-element-padding-horizontal);
        background: var(--tlp-form-element-background)
            url("@tuleap/tlp-styles/images/field-double-arrows.svg") no-repeat;
        background-position: right var(--tlp-form-element-padding-horizontal) center;
    }

    &.list-picker-multiple {
        position: relative;
        min-height: var(--tlp-form-element-height);
        padding: 0 52px 5px 6px;
        background: var(--tlp-form-element-background)
            url("@tuleap/tlp-styles/images/field-ellipsis.svg") no-repeat;
        background-position: right 10px top 17px;
        background-size: 15px 5px;
    }
}

.list-picker-with-open-dropdown {
    .list-picker-selection {
        border-radius: var(--tlp-form-element-border-radius) var(--tlp-form-element-border-radius) 0
            0;
        border-color: var(--tlp-main-color);
    }

    &.list-picker-with-dropdown-above .list-picker-selection {
        border-radius: 0 0 var(--tlp-form-element-border-radius)
            var(--tlp-form-element-border-radius);
    }
}

.list-picker-selected-value {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: default;

    > .list-picker-search-field {
        width: 100%;
        border: 0;
        line-height: 1.5rem;
        cursor: pointer;
    }
}

.list-picker-selected-value-remove-button {
    position: relative;
    top: -1px;
    float: right;
    font-size: 18px;
    line-height: 17px;
    white-space: nowrap;
}

.list-picker-value-remove-button {
    margin: 0 5px 0 0;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;
}

.list-picker-multiple > .list-picker-selected-value-remove-button {
    position: absolute;
    top: 7px;
    right: 32px;
    margin: 2px 0 0;
}

.list-picker:not(.list-picker-disabled) {
    .list-picker-selected-value-remove-button:hover,
    .list-picker-value-remove-button:hover {
        opacity: 0.5;
        cursor: pointer;
    }
}

.list-picker-badge {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    margin: 6px 5px 0 0;
    padding: var(--tlp-badge-padding);
    border-radius: var(--tlp-small-radius);
    background: var(--tlp-main-color-transparent-90);
    color: var(--tlp-main-color);
    font-size: var(--tlp-badge-font-size);
    font-weight: var(--tlp-badge-font-weight);
    line-height: var(--tlp-badge-line-height);
    text-decoration: none;
    vertical-align: middle;
    white-space: nowrap;
    cursor: pointer;
}

@each $color-name, $colors in tlp-swatch-colors.$color-map {
    .list-picker-badge-#{$color-name} {
        border: 1px solid color.adjust(map.get($colors, "primary"), $alpha: - 0.4);
        background: color.adjust(map.get($colors, "primary"), $alpha: - 0.9);
        color: map.get($colors, "text");
    }
}

.list-picker-disabled {
    .list-picker-badge,
    .list-picker-selection {
        cursor: not-allowed;
    }
}

.list-picker-error,
.tlp-form-element-error {
    .list-picker-selection {
        border-color: var(--tlp-danger-color);
        color: var(--tlp-danger-color);

        &:focus {
            box-shadow: var(--tlp-shadow-focus-error);
        }
    }

    .list-picker-badge {
        border-color: var(--tlp-danger-color);
        background-color: var(--tlp-danger-color-transparent-90);
        color: var(--tlp-danger-dark-color);

        &:focus {
            box-shadow: var(--tlp-shadow-focus-error);
        }
    }
}
