/**
 * 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 "sass:color";
@use "sass:map";
@use "pkg:@tuleap/tlp-swatch-colors";

$-tlp-badge-radius: var(--tlp-small-radius);
$-tlp-badge-color: var(--tlp-white-color);
$badge-names: (
    "tlp-badge-primary",
    "tlp-badge-secondary",
    "tlp-badge-info",
    "tlp-badge-success",
    "tlp-badge-warning",
    "tlp-badge-danger"
);

@mixin -badge {
    display: inline-block;
    padding: var(--tlp-badge-padding);
    border-radius: $-tlp-badge-radius;
    color: $-tlp-badge-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;

    &:hover {
        text-decoration: none;
    }

    &.tlp-badge-rounded {
        border-radius: var(--tlp-medium-spacing);
    }
}

%-tlp-badge {
    @include -badge;
}

@mixin -outline-on-dark-background {
    font-weight: normal;
}

.tlp-badge-icon {
    margin: 0 5px 0 0;
    font-size: 0.625rem;
}

.tlp-badge-primary {
    @extend %-tlp-badge;

    background: var(--tlp-main-color);

    &.tlp-badge-outline {
        background: var(--tlp-main-color-transparent-90);
        color: var(--tlp-main-color);

        &.tlp-badge-on-dark-background {
            @include -outline-on-dark-background;

            background: var(--tlp-main-color-transparent-80);
            color: var(--tlp-main-color-lighter-50);
        }
    }
}

// Used by select2 choices
@mixin tlp-primary-outline-badge {
    @include -badge;

    background: var(--tlp-main-color-transparent-90);
    color: var(--tlp-main-color);
}

.tlp-badge-secondary {
    @extend %-tlp-badge;

    background: var(--tlp-neutral-dark-color);
    color: var(--tlp-dimmed-color-darker-10);

    &.tlp-badge-outline {
        background: var(--tlp-neutral-dark-color-transparent-50);
        color: var(--tlp-dimmed-color-darker-10);

        &.tlp-badge-on-dark-background {
            @include -outline-on-dark-background;

            background: var(--tlp-neutral-normal-color-transparent-80);
            color: var(--tlp-neutral-dark-color);
        }
    }
}

.tlp-badge-info {
    @extend %-tlp-badge;

    background: var(--tlp-info-color);

    &.tlp-badge-outline {
        background: var(--tlp-badge-info-background);
        color: var(--tlp-info-dark-color);

        &.tlp-badge-on-dark-background {
            @include -outline-on-dark-background;

            background: var(--tlp-info-color-transparent-85);
            color: var(--tlp-info-color-lighter-35);
        }
    }
}

.tlp-badge-success {
    @extend %-tlp-badge;

    background: var(--tlp-success-color);

    &.tlp-badge-outline {
        background: var(--tlp-badge-success-background);
        color: var(--tlp-success-dark-color);

        &.tlp-badge-on-dark-background {
            @include -outline-on-dark-background;

            background: var(--tlp-success-color-transparent-85);
            color: var(--tlp-success-color-lighter-35);
        }
    }
}

.tlp-badge-warning {
    @extend %-tlp-badge;

    background: var(--tlp-warning-color);

    &.tlp-badge-outline {
        background: var(--tlp-badge-warning-background);
        color: var(--tlp-warning-dark-color);

        &.tlp-badge-on-dark-background {
            @include -outline-on-dark-background;

            background: var(--tlp-warning-color-transparent-85);
            color: var(--tlp-warning-color-lighter-20);
        }
    }
}

.tlp-badge-danger {
    @extend %-tlp-badge;

    background: var(--tlp-danger-color);

    &.tlp-badge-outline {
        background: var(--tlp-badge-danger-background);
        color: var(--tlp-danger-dark-color);

        &.tlp-badge-on-dark-background {
            @include -outline-on-dark-background;

            background: var(--tlp-danger-color-transparent-75);
            color: var(--tlp-danger-color-lighter-60);
        }
    }
}

@each $color-name, $colors in tlp-swatch-colors.$color-map {
    .tlp-badge-#{$color-name} {
        @extend %-tlp-badge;

        background: map.get($colors, "text");

        &.tlp-badge-outline {
            background: map.get($colors, "secondary");
            color: map.get($colors, "text");

            &.tlp-badge-on-dark-background {
                @include -outline-on-dark-background;

                background: map.get($colors, "badge-background-on-dark");
                color: map.get($colors, "badge-color-on-dark");
            }
        }
    }
}
