@use "sass:color";

.react-flow__node {
    &.selected::before {
        position: absolute;
        inset: -6 * $reactflow-node-border-width;
        z-index: 0;
        content: " ";
        background-color: eccgui-color-rgba($reactflow-edge-stroke-color-selected, 0.05);
        border-color: $reactflow-edge-stroke-color-selected;
        border-style: dotted;
        border-width: 1px;
        border-radius: $reactflow-node-border-radius;
    }

    &.react-flow__node-default {
        width: unset !important;
        height: unset !important;
        padding: unset !important;
        color: unset !important;
        text-align: unset !important;

        // remove default styles
        background-color: unset !important;
        border: unset !important;

        &.selected,
        &.selected:hover {
            box-shadow: none;
        }
    }

    &.selected,
    &:focus,
    &:focus-visible {
        outline: none;
    }
}

.#{$eccgui}-graphviz__node {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    font-size: $reactflow-node-font-size;
    color: $reactflow-node-color;
    background-color: $reactflow-node-background-color;
    border-color: $reactflow-node-border-color;
    border-style: solid;
    border-width: $reactflow-node-border-width;
    border-radius: $reactflow-node-border-radius;

    &:hover {
        box-shadow: 0 0 0 6 * $reactflow-node-border-width
            eccgui-color-rgba($reactflow-edge-stroke-color-selected, 0.05);
    }

    &.was-resized.is-resizable-vertical {
        max-height: unset;
    }
}

.#{$eccgui}-graphviz__node--tiny {
    width: $reactflow-node-basesize * 4;
    min-height: $reactflow-node-basesize;
    max-height: $reactflow-node-basesize * 4;
}

.#{$eccgui}-graphviz__node--small {
    width: $reactflow-node-basesize * 5;
    min-height: $reactflow-node-basesize;
    max-height: $reactflow-node-basesize * 8;
}

.#{$eccgui}-graphviz__node--medium {
    width: $reactflow-node-basesize * 8;
    min-height: $reactflow-node-basesize;
    max-height: $reactflow-node-basesize * 13;
}

.#{$eccgui}-graphviz__node--large {
    width: $reactflow-node-basesize * 13;
    min-height: $reactflow-node-basesize;
    max-height: $reactflow-node-basesize * 13;
}

.#{$eccgui}-graphviz__node--fullwidth {
    width: 100%;
}

.#{$eccgui}-graphviz__node--minimal-rectangular,
.#{$eccgui}-graphviz__node--minimal-circular {
    /* FIXME: does not work correctly with tooltips around
    transition: width $reactflow-transition-time $reactflow-transition-function,
        max-height $reactflow-transition-time $reactflow-transition-function,
        border-radius $reactflow-transition-time $reactflow-transition-function;
    */

    .react-flow__node:not(.selected) /*:not(:hover)*/ & {
        z-index: 3;
        width: $reactflow-node-basesize;
        max-height: $reactflow-node-basesize;

        .#{$eccgui}-graphviz__node__header-depiction + .#{$eccgui}-graphviz__node__header-label,
        .#{$eccgui}-graphviz__node__header-menu,
        .#{$eccgui}-graphviz__node__content,
        .#{$eccgui}-graphviz__node__extension,
        .#{$eccgui}-graphviz__node__footer {
            display: none;
        }

        .#{$eccgui}-graphviz__node__header-depiction {
            max-width: calc(#{$reactflow-node-basesize} - #{2 * $reactflow-node-border-width});
            max-height: calc(#{$reactflow-node-basesize} - #{2 * $reactflow-node-border-width});
        }
    }
}

.#{$eccgui}-graphviz__node--minimal-circular {
    .react-flow__node:not(.selected) /*:not(:hover)*/ & {
        border-radius: 100%;

        .#{$eccgui}-graphviz__node__header-depiction {
            border-radius: 100%;
        }
    }
}

.#{$eccgui}-graphviz__node__header {
    box-sizing: border-box;
    display: flex;
    flex-grow: 0;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    min-height: $reactflow-node-basesize;

    .#{$ns}-button:not([class*="#{$ns}-intent-"]) {
        color: currentcolor;
    }
}

.#{$eccgui}-graphviz__node__header--large {
    min-height: $reactflow-node-largesize;
}

.#{$eccgui}-graphviz__node__header-depiction,
.#{$eccgui}-graphviz__node__header-menu {
    display: flex;
    flex-grow: 0;
    flex-shrink: 0;
    align-items: center;
    max-height: calc(#{$reactflow-node-basesize} - #{2 * $reactflow-node-border-width});
    margin: 0 $eccgui-size-block-whitespace * 0.25;

    .#{$eccgui}-graphviz__node__header--large & {
        max-height: calc(#{$reactflow-node-largesize} - #{2 * $reactflow-node-border-width});
    }
}

.#{$eccgui}-graphviz__node__header-depiction {
    justify-content: center;

    /* TODO: does not work correctly with tooltips around
    transition: border-radius $reactflow-transition-time $reactflow-transition-function;
    */
    min-width: calc(#{$reactflow-node-basesize} - #{2 * $reactflow-node-border-width});
    max-width: calc(2 * (#{$reactflow-node-basesize} - #{2 * $reactflow-node-border-width}));
    min-height: calc(#{$reactflow-node-basesize} - #{2 * $reactflow-node-border-width});
    overflow: hidden;
    border-radius: $reactflow-node-border-radius;

    & .#{$eccgui}-depiction {
        flex-grow: 0;
        flex-shrink: 0;
        align-self: stretch;

        /*
        Fix for Firefox,
        the width of .#{$eccgui}-depiction container is not reduced to its content
        when .#{$eccgui}-depiction__image updated to the available height.
        */
        .#{$eccgui}-depiction__image {
            height: calc(#{$reactflow-node-basesize} - #{2 * $reactflow-node-border-width});
        }
    }

    .#{$eccgui}-graphviz__node__header--large & {
        min-width: calc(#{$reactflow-node-largesize} - #{2 * $reactflow-node-border-width});
        max-width: calc(2 * (#{$reactflow-node-largesize} - #{2 * $reactflow-node-border-width}));
        min-height: calc(#{$reactflow-node-largesize} - #{2 * $reactflow-node-border-width});

        .#{$eccgui}-depiction__image {
            height: calc(#{$reactflow-node-largesize} - #{2 * $reactflow-node-border-width});
        }
    }
}

.#{$eccgui}-graphviz__node__header-label {
    display: inline-flex;
    flex-grow: 1;
    flex-shrink: 1;
    flex-direction: column;
    margin: 0 $eccgui-size-block-whitespace * 0.25;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
    white-space: nowrap;
}

.#{$eccgui}-graphviz__node__header-label__mainline,
.#{$eccgui}-graphviz__node__header-label__subline {
    flex-grow: 0;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.#{$eccgui}-graphviz__node__content {
    flex-grow: 1;
    padding: $eccgui-size-block-whitespace * 0.5 $eccgui-size-block-whitespace * 0.25;
    margin: 0.1px; // workaround that Firefox displays node borders better when canvas is scaled down
    overflow: hidden;
    color: $eccgui-color-workspace-text;
    background-color: $card-background-color;

    &:hover {
        overflow: auto;
    }
}

.#{$eccgui}-graphviz__node__footer {
    padding: $eccgui-size-block-whitespace * 0.5 $eccgui-size-block-whitespace * 0.25;
    font-size: $reactflow-node-font-size;
    color: $reactflow-node-color;
    background-color: $reactflow-node-background-color;
}

// Node Resizer

.#{$eccgui}-graphviz__node.is-resizable-horizontal,
.#{$eccgui}-graphviz__node.is-resizable-vertical {
    min-width: 2.5 * $reactflow-node-basesize;
    min-height: 2.5 * $reactflow-node-basesize;
}

.#{$eccgui}-graphviz__node__resizer--cursorhandles {
    position: absolute;
    right: 0;
    bottom: 0;
    display: none;
    width: 0;
    height: 0;
    overflow: visible;

    & > div {
        top: unset !important;
        right: -1 * $reactflow-cursor-delimiter-offset !important;
        bottom: -1 * $reactflow-cursor-delimiter-offset !important;
        left: unset !important;
        z-index: 0 !important;
        width: $reactflow-cursor-delimiter-offset * 3 !important;
        height: $reactflow-cursor-delimiter-offset * 3 !important;
        overflow: visible;
        border-right: $reactflow-node-border-width solid $reactflow-node-border-color;
        border-bottom: $reactflow-node-border-width solid $reactflow-node-border-color;

        .#{$eccgui}-graphviz__node__resizer--right:not(.#{$eccgui}-graphviz__node__resizer--bottom) & {
            bottom: 0 !important;
            border-bottom: none;
        }
        .#{$eccgui}-graphviz__node__resizer--bottom:not(.#{$eccgui}-graphviz__node__resizer--right) & {
            right: 0 !important;
            border-right: none;
        }
    }
}

.#{$eccgui}-graphviz__node__resizer {
    min-width: 2.5 * $reactflow-node-basesize;
    min-height: 2.5 * $reactflow-node-basesize;

    .selected &,
    &:hover {
        .#{$eccgui}-graphviz__node__resizer--cursorhandles {
            display: block;
        }
    }
}

// Node border overwrites

.#{$eccgui}-graphviz__node--border-solid {
    border-style: solid;
}

.#{$eccgui}-graphviz__node--border-double {
    border-style: double;
    border-width: 1.5 * $reactflow-node-border-width;
}

.#{$eccgui}-graphviz__node--border-dashed {
    border-style: dashed;
}

.#{$eccgui}-graphviz__node--border-dotted {
    border-style: dotted;
}

// Node intent

@mixin node-intent-gradient {
    border-image-source: conic-gradient(
        from var(--node-intent-angle) at 50% 50%,
        transparent,
        var(--node-intent-color) 25deg 155deg,
        transparent 180deg
    );
}

.#{$eccgui}-graphviz__node[class*="#{$eccgui}-intent--"],
.#{$eccgui}-graphviz__node--animated:not([class*="#{$eccgui}-intent--"]) {
    --node-intent-color: #{$eccgui-color-workspace-text};

    &::after {
        --node-intent-angle: #{$reactflow-transition-anglestart};

        position: absolute;
        inset: -2 * $reactflow-node-border-width;
        z-index: -1;
        display: block;
        content: " ";
        border-style: solid;
        border-width: 2 * $reactflow-node-border-width;
        border-image-slice: 1;
        border-image-width: 2 * $reactflow-node-border-width;

        @include node-intent-gradient;
    }
}

.#{$eccgui}-graphviz__node.#{$eccgui}-intent--primary {
    --node-intent-color: #{$eccgui-color-primary};
}

.#{$eccgui}-graphviz__node.#{$eccgui}-intent--accent {
    --node-intent-color: #{$eccgui-color-accent};
}

.#{$eccgui}-graphviz__node.#{$eccgui}-intent--info {
    --node-intent-color: #{$eccgui-color-info-text};
}

.#{$eccgui}-graphviz__node.#{$eccgui}-intent--success {
    --node-intent-color: #{$eccgui-color-success-text};
}

.#{$eccgui}-graphviz__node.#{$eccgui}-intent--warning {
    --node-intent-color: #{$eccgui-color-warning-text};
}

.#{$eccgui}-graphviz__node.#{$eccgui}-intent--danger {
    --node-intent-color: #{$eccgui-color-danger-text};
}

// hode highlight mark

.#{$eccgui}-graphviz__node[class*="#{$eccgui}-graphviz__node--highlight-"] {
    &::before {
        position: absolute;
        inset: -2 * $reactflow-node-border-width;
        z-index: -2;
        display: block;
        content: " ";
        border: 0.1px solid transparent; // workaround for Firefox, otherwise shadows are overlayed
        box-shadow:
            0 0 0 2 * $reactflow-node-border-width var(--node-highlight-default-color),
            0 0 0 3.5 * $reactflow-node-border-width
                var(--node-highlight-alternate-color, var(--node-highlight-default-color));
        opacity: $eccgui-opacity-disabled;
    }
}

.#{$eccgui}-graphviz__node--highlight-default {
    --node-highlight-default-color: #{$eccgui-color-accent};
    --node-highlight-alternate-color: #{$eccgui-color-accent};
}

.#{$eccgui}-graphviz__node--highlight-alternate {
    --node-highlight-default-color: #{$eccgui-color-primary};
    --node-highlight-alternate-color: #{$eccgui-color-primary};
}

.#{$eccgui}-graphviz__node--highlight-default.#{$eccgui}-graphviz__node--highlight-alternate {
    --node-highlight-default-color: #{$eccgui-color-accent};
    --node-highlight-alternate-color: #{$eccgui-color-primary};
}

// Node animation

@property --node-intent-angle {
    // rule necessary, otherwise increasing --node-intent-angle for animation does not work correctly
    syntax: "<angle>";
    initial-value: #{$reactflow-transition-anglestart};
    inherits: true;
}

.#{$eccgui}-graphviz__node--animated:after {
    animation: spinningborder 8 * $reactflow-transition-time linear infinite;

    @keyframes spinningborder {
        100% {
            --node-intent-angle: #{$reactflow-transition-anglestart + 360deg};
        }

        @for $step from 1 through 10 {
            /*
            This is a fix/workaround for Firefox/Gecko.
            Looks like "animation" the custom property is not enough.
            It is also necessary to repeat the rule.
            */
            #{$step * 10}#{"%"} {
                --node-intent-angle: #{$reactflow-transition-anglestart + $step * 36deg};

                @include node-intent-gradient;
            }
        }
    }
}

// node introduction animation

.#{$eccgui}-graphviz__node--introduction:not(.#{$eccgui}-graphviz__node--introduction-done) {
    visibility: hidden;
    animation-play-state: paused;

    & ~ * {
        visibility: hidden;
    }
}

.#{$eccgui}-graphviz__node--introduction-runs {
    animation-name: outline;
    animation-duration: var(--node-introduction-time);
    animation-timing-function: linear;
    animation-play-state: running;

    &[data-introduction-animation="landing"] {
        animation-name: landing;

        & ~ * {
            visibility: hidden;
        }
    }

    @keyframes landing {
        0% {
            outline: solid 0 rgb(0 0 0 / 0%);
            outline-offset: 0;
            opacity: 0;
            filter: blur($eccgui-size-block-whitespace);
            transform: scale(2);
        }

        61% {
            outline: solid 0 rgb(0 0 0 / 39%);
            outline-offset: 0;
            opacity: 1;
            filter: blur(0);
            transform: scale(1);
        }

        100% {
            outline: solid $eccgui-size-block-whitespace rgb(0 0 0 / 0%);
            outline-offset: 2 * $eccgui-size-block-whitespace;
            opacity: 1;
            filter: blur(0);
            transform: scale(1);
        }
    }

    @keyframes outline {
        0% {
            outline: solid 0 eccgui-color-rgba($eccgui-color-accent, 0);
            outline-offset: 0;
        }

        9% {
            outline: solid 0.5 * $eccgui-size-block-whitespace eccgui-color-rgba($eccgui-color-accent, 0.39);
            outline-offset: 0;
        }

        85% {
            outline: solid 0.5 * $eccgui-size-block-whitespace eccgui-color-rgba($eccgui-color-accent, 0.39);
            outline-offset: 0;
        }

        100% {
            outline: solid 0 eccgui-color-rgba($eccgui-color-accent, 0);
            outline-offset: 2 * $eccgui-size-block-whitespace;
        }
    }
}

// Node tools

.#{$eccgui}-graphviz__nodetools__content {
    flex-grow: 1;
    flex-shrink: 1;
    min-height: 0;
}

// Node content extension

.#{$eccgui}-graphviz__node__extension {
    flex-grow: 1;
    flex-shrink: 1;
    min-height: $eccgui-size-block-whitespace * 0.5;
    background-color: $reactflow-node-background-color;

    .#{$eccgui}-graphviz__node--tiny & {
        max-height: $reactflow-node-basesize * 3;
    }

    .#{$eccgui}-graphviz__node--small & {
        max-height: $reactflow-node-basesize * 5;
    }

    .#{$eccgui}-graphviz__node--medium & {
        max-height: $reactflow-node-basesize * 8;
    }

    .#{$eccgui}-graphviz__node--large & {
        max-height: $reactflow-node-basesize * 13;
    }
}

.#{$eccgui}-graphviz__node__extension--slideout {
    order: 4;
}

.#{$eccgui}-graphviz__node__extension--expanded {
    display: flex;
    flex-direction: column;

    // separation between node content and extension
    // do not inherit styles here
    border-top: 1px solid $eccgui-color-separation-divider !important;
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;

    &.#{$eccgui}-graphviz__node__extension--slideout {
        position: absolute;
        top: 100%;
        right: -1 * $reactflow-node-border-width;
        left: -1 * $reactflow-node-border-width;
        border-color: $reactflow-node-border-color;
        border-style: solid;
        border-width: $reactflow-node-border-width;
        border-radius: $reactflow-node-border-radius;
    }

    &:not(.#{$eccgui}-graphviz__node__extension--slideout) + .#{$eccgui}-graphviz__node__footer {
        border-top: 1px solid $eccgui-color-separation-divider;
    }
}

.#{$eccgui}-graphviz__node__extension-expandbutton {
    display: flex;
    width: 100%;
    min-height: 0;
    max-height: $eccgui-size-block-whitespace * 0.5;
}

.#{$eccgui}-graphviz__node__extension-body {
    flex-grow: 0;
    flex-shrink: 1;
    padding: $eccgui-size-block-whitespace * 0.5 $eccgui-size-block-whitespace * 0.25;
    overflow: auto;

    .#{$eccgui}-tag__item {
        max-width: 20%;

        &:first-child {
            max-width: 75%;
        }

        &:last-child {
            max-width: 100%;
        }
    }
}

.#{$eccgui}-graphviz__node__extension-actions {
    flex-grow: 0;
    flex-shrink: 0;
    text-align: center;
}
