// own vars
$eccgui-size-typo-tag: $eccgui-size-typo-caption !default;
$eccgui-size-typo-tag-lineheight: $eccgui-size-typo-caption-lineheight !default;
$eccgui-size-typo-tag-large: $eccgui-size-typo-text !default;
$eccgui-size-typo-tag-large-lineheight: $eccgui-size-typo-text-lineheight !default;
$eccgui-size-margin-tag: $eccgui-size-inline-whitespace * 0.5 !default;
$eccgui-color-tag-background-emphasized: $eccgui-color-workspace-text !default;

// lib vars
$tag-default-color: $eccgui-color-tag-background-emphasized;

// $dark-tag-default-color: $gray5 !default;
$tag-height: $eccgui-size-typo-tag * $eccgui-size-typo-tag-lineheight;
$tag-line-height: $eccgui-size-typo-tag;
$tag-padding-top: ($tag-height - $tag-line-height) * 0.5;
$tag-padding: $tag-padding-top * 2;
$tag-margin: 0;
$tag-height-small: $eccgui-size-typo-tag;
$tag-line-height-small: $tag-height-small;
$tag-padding-small: $tag-padding-top * 0.5;
$tag-height-large: $eccgui-size-typo-tag-large * $eccgui-size-typo-tag-large-lineheight;
$tag-line-height-large: $eccgui-size-typo-tag-large;
$tag-padding-large: ($tag-height-large - $tag-line-height-large);

// $tag-icon-spacing: ($tag-height - 12px) * 0.5 !default;
// $tag-icon-spacing-large: ($tag-height-large - $pt-icon-size-standard) * 0.5 !default;
$tag-round-adjustment: 0 !default;

@use "sass:color";
@import "~@blueprintjs/core/src/components/tag/tag";

.#{$eccgui}-tag__item {
    flex-grow: 0;
    flex-shrink: 0;
    min-width: calc(#{$tag-height} - 2px);
    min-height: calc(#{$tag-height} - 2px);
    max-height: calc(#{$tag-height} - 2px);
    padding: 0 $tag-padding-top;
    line-height: calc(#{$tag-height} - 2px);

    &.#{$ns}-round {
        border-radius: $tag-height * 0.5;
    }

    .#{$ns}-fill {
        padding: $tag-padding-top 0;
    }

    .#{$ns}-tag-remove {
        padding: 0;
        margin: 0 !important;
    }

    .#{$eccgui}-overviewitem__description > & {
        max-width: 39%;
    }

    &.#{$eccgui}-tag--small {
        min-width: calc(#{$tag-height-small} + #{$tag-padding-small});
        min-height: calc(#{$tag-height-small} + #{$tag-padding-small});
        max-height: calc(#{$tag-height-small} + #{$tag-padding-small});
        padding: 0 $tag-padding-small;
        font-size: calc(#{$eccgui-size-typo-tag} - 1px);
        line-height: calc(#{$tag-height-small} + #{$tag-padding-small});

        &.#{$ns}-round {
            border-radius: $tag-height-small * 0.5;
        }

        .#{$ns}-fill {
            padding: $tag-padding-small 0;
        }
    }

    &.#{$eccgui}-tag--large {
        min-width: calc(#{$tag-height-large} + #{$tag-padding-large} - 2px);
        min-height: calc(#{$tag-height-large} + #{$tag-padding-large} - 2px);
        max-height: calc(#{$tag-height-large} + #{$tag-padding-large} - 2px);
        font-size: $eccgui-size-typo-tag-large;
        line-height: calc(#{$tag-height-large} + #{$tag-padding-large} - 2px);

        &.#{$ns}-round {
            border-radius: $tag-height-large * 0.5;
        }
    }

    svg {
        max-height: 1em;
        fill: currentcolor;
        stroke: initial;
    }
}

.#{$eccgui}-tag__list-wrapper,
.#{$eccgui}-tag__list-label,
.#{$eccgui}-tag__list-content,
.#{$eccgui}-tag__list,
.#{$eccgui}-tag__list-item {
    display: inline;
    font-size: $eccgui-size-typo-tag;
    font-weight: $eccgui-font-weight-regular;
    line-height: $eccgui-size-typo-tag-lineheight;
    vertical-align: middle;
}

.#{$eccgui}-tag__list-label {
    white-space: nowrap;
}

.#{$eccgui}-tag__list-wrapper:not(:last-child),
.#{$eccgui}-tag__list:not(:last-child) {
    margin-right: $eccgui-size-margin-tag * 2;
}

.#{$eccgui}-tag__list-item {
    display: inline-flex;
    max-width: 100%;
    margin-bottom: $eccgui-size-margin-tag;

    .#{$eccgui}-overviewitem__line &,
    .#{$eccgui}-typography__overflowtext & {
        margin-bottom: 0;
    }
}

.#{$eccgui}-tag__list-label,
.#{$eccgui}-tag__list-item:not(:last-child) {
    margin-right: $eccgui-size-margin-tag;
}

.#{$ns}-tag-remove {
    color: inherit !important;
    .#{$ns}-icon,
    svg {
        width: $eccgui-size-typo-tag;
        height: $eccgui-size-typo-tag;
        fill: currentcolor;
    }
}

.#{$ns}-tag {
    --eccgui-tag-border-width: 1px;

    border-style: solid;
    border-width: var(--eccgui-tag-border-width);

    &:not([class*="#{$ns}-intent-"]) {
        --eccgui-tag-bg: #{$tag-default-color};
        --eccgui-tag-border: #{$tag-default-color};
        --eccgui-tag-text: #{eccgui-color-var("identity", "text", "100")};
        --eccgui-tag-emfactor: 100%;

        color: var(--eccgui-tag-text);
        background-color: eccgui-color-mix(
            var(--eccgui-tag-bg) var(--eccgui-tag-emfactor),
            eccgui-color-var("identity", "background", "100")
        );
        border-color: eccgui-color-rgba(var(--eccgui-tag-border), calc(0.25 * var(--eccgui-tag-emfactor)));

        &.#{$eccgui}-tag--strongeremphasis {
            --eccgui-tag-emfactor: 95%;
        }
        &.#{$eccgui}-tag--strongemphasis {
            --eccgui-tag-emfactor: 90%;
        }
        &.#{$eccgui}-tag--normalemphasis {
            --eccgui-tag-emfactor: 85%;
        }
        &.#{$eccgui}-tag--weakemphasis {
            --eccgui-tag-emfactor: 80%;
        }
        &.#{$eccgui}-tag--weakeremphasis {
            --eccgui-tag-emfactor: 75%;
        }

        &.#{$eccgui}-intent--primary {
            --eccgui-tag-bg: #{$eccgui-color-primary};
            --eccgui-tag-border: #{$eccgui-color-primary};
            --eccgui-tag-text: #{$eccgui-color-primary-contrast};
        }
        &.#{$eccgui}-intent--accent {
            --eccgui-tag-bg: #{$eccgui-color-accent};
            --eccgui-tag-border: #{$eccgui-color-accent};
            --eccgui-tag-text: #{$eccgui-color-accent-contrast};
        }
        &.#{$eccgui}-intent--info {
            --eccgui-tag-bg: #{$eccgui-color-info-text};
            --eccgui-tag-border: #{$eccgui-color-info-text};
            --eccgui-tag-text: #{$eccgui-color-info-background};
        }
        &.#{$eccgui}-intent--success {
            --eccgui-tag-bg: #{$eccgui-color-success-text};
            --eccgui-tag-border: #{$eccgui-color-success-text};
            --eccgui-tag-text: #{$eccgui-color-success-background};
        }
        &.#{$eccgui}-intent--warning {
            --eccgui-tag-bg: #{$eccgui-color-warning-text};
            --eccgui-tag-border: #{$eccgui-color-warning-text};
            --eccgui-tag-text: #{$eccgui-color-warning-background};
        }
        &.#{$eccgui}-intent--danger {
            --eccgui-tag-bg: #{$eccgui-color-danger-text};
            --eccgui-tag-border: #{$eccgui-color-danger-text};
            --eccgui-tag-text: #{$eccgui-color-danger-background};
        }

        &.#{$ns}-minimal,
        &.#{$ns}-minimal.#{$ns}-interactive {
            --eccgui-tag-bg: #{eccgui-color-var("identity", "background", "500")};
            --eccgui-tag-border: #{$tag-default-color};
            --eccgui-tag-text: #{$tag-default-color};

            color: var(--eccgui-tag-text);
            background-color: eccgui-color-mix(
                var(--eccgui-tag-bg) var(--eccgui-tag-emfactor),
                eccgui-color-var("identity", "background", "100")
            );
            border-color: eccgui-color-rgba(var(--eccgui-tag-border), calc(0.25 * var(--eccgui-tag-emfactor)));

            &.#{$eccgui}-tag--strongeremphasis {
                --eccgui-tag-emfactor: 100%;
            }
            &.#{$eccgui}-tag--strongemphasis {
                --eccgui-tag-emfactor: 90%;
            }
            &.#{$eccgui}-tag--normalemphasis {
                --eccgui-tag-emfactor: 80%;
            }
            &.#{$eccgui}-tag--weakemphasis {
                --eccgui-tag-emfactor: 70%;
            }
            &.#{$eccgui}-tag--weakeremphasis {
                --eccgui-tag-emfactor: 60%;
            }

            &[class*="#{$eccgui}-intent--"] {
                color: eccgui-color-rgba(var(--eccgui-tag-text), var(--eccgui-tag-emfactor));
                border-color: eccgui-color-rgba(var(--eccgui-tag-border), calc(0.25 * var(--eccgui-tag-emfactor)));
            }

            &.#{$eccgui}-intent--primary {
                --eccgui-tag-text: #{$eccgui-color-primary};
                --eccgui-tag-border: #{$eccgui-color-primary};
                --eccgui-tag-bg: #{$eccgui-color-primary-contrast};
            }
            &.#{$eccgui}-intent--accent {
                --eccgui-tag-text: #{$eccgui-color-accent};
                --eccgui-tag-border: #{$eccgui-color-accent};
                --eccgui-tag-bg: #{$eccgui-color-accent-contrast};
            }
            &.#{$eccgui}-intent--info {
                --eccgui-tag-text: #{$eccgui-color-info-text};
                --eccgui-tag-border: #{$eccgui-color-info-text};
                --eccgui-tag-bg: #{$eccgui-color-info-background};
            }
            &.#{$eccgui}-intent--success {
                --eccgui-tag-text: #{$eccgui-color-success-text};
                --eccgui-tag-border: #{$eccgui-color-success-text};
                --eccgui-tag-bg: #{$eccgui-color-success-background};
            }
            &.#{$eccgui}-intent--warning {
                --eccgui-tag-text: #{$eccgui-color-warning-text};
                --eccgui-tag-border: #{$eccgui-color-warning-text};
                --eccgui-tag-bg: #{$eccgui-color-warning-background};
            }
            &.#{$eccgui}-intent--danger {
                --eccgui-tag-text: #{$eccgui-color-danger-text};
                --eccgui-tag-border: #{$eccgui-color-danger-text};
                --eccgui-tag-bg: #{$eccgui-color-danger-background};
            }
        }
    }
}

@media print {
    .#{$eccgui}-tag__item {
        print-color-adjust: exact;
    }
}
