/**
 * 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")};
        --text-color: #{map.get($colors, "text")};

        + .backlog-items-container > .backlog-items-children-container-handle:only-child {
            border-top: 0;
        }
    }

    .element-card.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')}");
        --accessibility-color: #{map.get($colors, "text")};
        --box-shadow: 0 1px 2px rgb(0 0 0 / 10%);

        &.element-card-user-story-closed {
            --accessibility-color: var(--tlp-dimmed-color-transparent-50);
        }
    }
}

.element-card {
    position: relative;
    z-index: 1;
    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(--box-shadow, var(--tlp-card-shadow));

    &::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 {
        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-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%;
    opacity: 0.5;
    background-color: var(--accessibility-color);
    mask-image: var(--accessibility-pattern);
}

.element-card-closed {
    border-color: transparent;
    background: var(--tlp-background-color);
    box-shadow: var(--tlp-card-shadow);

    .element-card-xref,
    .element-card-label {
        color: var(--tlp-dimmed-color-transparent-50);
    }
}

.element-card-xref {
    width: max-content;
    margin: 0 0 calc(var(--tlp-small-spacing) / 2);
    color: var(--text-color);
    font-size: 0.625rem;
    line-height: 0.8125rem;

    &:hover {
        text-decoration: underline;
    }
}

.element-card-xref-label {
    display: flex;
    flex-direction: column;
}

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

#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;
}

.element-draggable-item {
    cursor: move;
}

.element-not-draggable {
    cursor: not-allowed;
}

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

    &.drek-ghost {
        .element-card,
        .backlog-items-container {
            visibility: hidden;
        }
    }

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

.backlog-items-container {
    width: 95%;
    margin: 0 auto var(--tlp-small-spacing);
    border-radius: 0 0 var(--tlp-medium-radius) var(--tlp-medium-radius);
    background: var(--tlp-fade-background-color);
}

.backlog-items-children-container {
    padding: var(--tlp-small-spacing);
    border-right: 1px solid var(--tlp-neutral-normal-color);
    border-left: 1px solid var(--tlp-neutral-normal-color);

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

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

.backlog-items-children-container-handle {
    position: relative;
    height: 20px;
    border: 1px solid var(--tlp-neutral-normal-color);
    border-top: 0;
    border-radius: 0 0 var(--tlp-medium-radius) var(--tlp-medium-radius);
    background: var(--tlp-fade-background-color);
    box-shadow: var(--tlp-pane-shadow);
    cursor: pointer;

    &:hover {
        background: var(--tlp-background-color-darker-02);
    }

    &:only-child {
        border-top: 1px solid var(--tlp-neutral-normal-color);
    }
}

.backlog-items-children-container-handle-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--tlp-neutral-dark-color-darker-20);
    font-size: 8px;
    font-weight: 900;
}
