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

$accessibility-pattern-width: 20px;
$accessibility-pattern-right-margin: 6px;

@each $color-name, $colors in tlp-swatch-colors.$color-map {
    .element-card-#{$color-name} {
        --card-color: #{map.get($colors, "primary")};
    }

    .element-card-xref-#{$color-name} {
        color: #{map.get($colors, "text")};
    }

    .element-card-background-#{$color-name} {
        --secondary-color: #{map.get($colors, "secondary")};
        --border-color: #{map.get($colors, "border")};
        --text-color: #{map.get($colors, "text")};
        --accessibility-pattern: url("#{map.get($colors, 'pattern')}");

        .element-card-xref {
            color: var(--text-color);
        }
    }
}

.element-card {
    position: relative;
    z-index: 1;
    justify-content: space-between;
    padding: var(--tlp-small-spacing) var(--tlp-small-spacing) var(--tlp-small-spacing)
        calc(var(--tlp-small-spacing) + 2px);
    border: 1px solid var(--border-color, transparent);
    border-radius: var(--tlp-medium-radius);
    background: var(--secondary-color, var(--tlp-white-color));
    box-shadow: var(--tlp-card-shadow);

    &[class*="element-card-background-"] {
        box-shadow: 0 1px 2px rgb(0 0 0 / 10%);
    }

    &::before {
        content: "";
        display: block;
        position: absolute;
        top: -1px;
        left: -1px;
        width: 4px;
        height: calc(100% + 2px);
        border-radius: var(--tlp-medium-radius) 0 0 var(--tlp-medium-radius);
        background: var(--card-color);
    }

    &.element-card-with-accessibility {
        &[class*="element-card-background-"] {
            padding: var(--tlp-small-spacing)
                calc(
                    var(--tlp-small-spacing) + #{$accessibility-pattern-width} + #{$accessibility-pattern-right-margin}
                )
                var(--tlp-small-spacing) calc(var(--tlp-small-spacing) + 2px);

            > .element-card-accessibility {
                opacity: 0.5;
                background-color: var(--text-color);
                mask-image: var(--accessibility-pattern);
            }
        }

        &:not([class*="element-card-background-"]) > .element-card-accessibility {
            display: none;
        }

        > .element-card-content > .element-card-info {
            margin: 0 5px 0 0;
        }
    }

    .element-card-accessibility {
        position: absolute;
        top: 0;
        right: $accessibility-pattern-right-margin;
        width: $accessibility-pattern-width;
        height: 100%;
    }
}

.element-card-xref-label {
    display: flex;
    font-size: 0.625rem;
    line-height: 0.8125rem;
    white-space: nowrap;

    > .element-card-xref {
        margin: 0 0 calc(var(--tlp-small-spacing) / 2);

        > .element-card-xref-project {
            font-weight: 600;

            > .element-card-xref-icon {
                margin: 0 calc(var(--tlp-small-spacing) / 2);
            }

            > .element-card-xref-project-icon {
                margin: 0 calc(var(--tlp-small-spacing) / 2) 0 0;
            }
        }
    }
}

.element-card-metadata {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
}

.element-card-label {
    font-size: 0.875rem;
    line-height: 1.125rem;
}

.element-backlog-item {
    margin: 0 0 var(--tlp-small-spacing);

    &:last-child {
        margin: 0;
    }
}

#element-skeleton {
    display: flex;
    flex-direction: column;
    margin: 0 var(--tlp-small-spacing) var(--tlp-small-spacing) var(--tlp-small-spacing);
}

.element-skeleton-xref {
    width: 70px;
    margin: 0 10px var(--tlp-small-spacing) 0;
}

.element-skeleton-title {
    width: 300px;
}

.feature-link {
    color: var(--tlp-dark-color);
    white-space: normal;
    cursor: pointer;
}

.element-card-feature-title {
    margin: 0 0 0 var(--tlp-small-spacing);
}
