@use "sass:map";
@use "./toast.config" as config;
@use "../../01-core/external" as *;

@mixin ss-toast-region {
    position: fixed;
    z-index: map.get(config.$ss-toast-config, z-index);

    display: flex;
    flex-direction: column;
    gap: map.get(config.$ss-toast-config, region-gap);

    margin: 0;
    padding: 0;
    list-style: none;
    pointer-events: none;
}

@mixin ss-toast {
    pointer-events: auto;
    position: relative;
    overflow: hidden;

    display: flex;
    align-items: flex-start;
    gap: map.get(config.$ss-toast-config, gap);

    min-width: map.get(config.$ss-toast-config, min-width);
    max-width: map.get(config.$ss-toast-config, max-width);
    padding: map.get(config.$ss-toast-config, padding);

    background: map.get(config.$ss-toast-config, bg);
    color: map.get(config.$ss-toast-config, fg);
    border-radius: map.get(config.$ss-toast-config, radius);
    box-shadow: map.get(config.$ss-toast-config, shadow);

    // Fades and slides when `NotificationManager` adds and removes it.
    transition:
        opacity map.get(config.$ss-toast-config, duration) var(--ss-ease-in-out),
        transform map.get(config.$ss-toast-config, duration) var(--ss-ease-in-out);

    @media (prefers-reduced-motion: reduce) {
        transition: none;
    }
}

/// Entering (first frame) and leaving: transparent and nudged sideways.
@mixin ss-toast-transient {
    opacity: 0;
    transform: translateY(map.get(config.$ss-toast-config, gap));
}

@mixin ss-toast-variant($variant) {
    $v: map.get(map.get(config.$ss-toast-config, variants), $variant);

    background: map.get($v, bg);
    color: map.get($v, fg);
}

/// Text column: title and message; takes the free width.
@mixin ss-toast-content {
    flex: 1 1 auto;
    min-inline-size: 0;
}

/// Bold first line above the message.
@mixin ss-toast-title {
    display: block;
    font-weight: var(--ss-font-weight-semibold, 600);
}

/// Row of buttons under the message.
@mixin ss-toast-actions {
    display: flex;
    flex-wrap: wrap;
    gap: map.get(config.$ss-toast-config, gap);
    margin-block-start: map.get(config.$ss-toast-config, gap);
}

/// Close button (with `ss-c-close`): toast colour, pushed to the end.
@mixin ss-toast-close {
    flex: none;
    margin-inline-start: auto;
    color: inherit;
}

/// Leading glyph (check, cross, !, i): fixed width, aligned with the title.
@mixin ss-toast-icon {
    flex: none;
    font-weight: var(--ss-font-weight-semibold, 600);
    line-height: inherit;
}

/// Message text under the title.
@mixin ss-toast-message {
    display: block;
}

/// Action button: toast colour, outlined, square.
@mixin ss-toast-action {
    padding: q(2) q(10);
    background: transparent;
    color: inherit;
    border: q(1) solid currentColor;
    border-radius: 0;
    font: inherit;
    cursor: pointer;

    &:hover {
        background: color-mix(in srgb, currentColor 15%, transparent);
    }
    &:focus-visible {
        outline: var(--ss-focus-ring-width, #{q(2)}) solid currentColor;
        outline-offset: var(--ss-focus-ring-offset, #{q(2)});
    }
}

/// Time-left bar along the bottom edge; the manager animates the bar's width.
@mixin ss-toast-progress {
    position: absolute;
    inset-inline: 0;
    inset-block-end: 0;
    block-size: q(3);
    background: color-mix(in srgb, currentColor 20%, transparent);
}

@mixin ss-toast-progress-bar {
    inline-size: 100%;
    block-size: 100%;
    background: currentColor;
    opacity: 0.6;
}
