@use "sass:math";

@function getBaseColor($variant) {
    @return map-get($eui-base-colors, $variant);
}

@function getColorVariant($color, $variant: 100) {
    @if ($variant < 100) {
        @return mix(#ffffff, $color, (100 - $variant) * 1%);
    } @else {
        @return mix(#000000, $color, ($variant - 100) * 1%);
    }
}

@function getPalette($baseColor, $overrideMap: false, $neutral: false) {
    // top 140 and bottom 0 are needed even not used in code
    // as they defines inversion boundaries for dark-mode theme colors,
    // once inverted, 140 becomes 0 and vice-versa
    $shadeDefs: (
        140, 130, 120, 110, 100, 75,  50,  25,  10,   5,   0
    );
    @if $neutral {
        // same remark here for the neutral/greys,
        // put more darker colors f.e. 120 to make a darker backgounrd in dark-mode theme colors
        $shadeDefs: (
            110, 100, 90, 80, 75, 50, 25, 20, 15, 10, 5, 2, 0
        );
    }
    $paletteMap: ();

    @each $shade in $shadeDefs {
        $value: getColorVariant($baseColor, $shade);

        @if $overrideMap {
            $overrideShade: map-get($overrideMap, $shade);
            @if $overrideShade {
                $value: $overrideShade;
            }
        }

        $paletteMap: map-merge(
            $paletteMap,
            (
                #{$shade}: $value
            )
        )
    }
    @return $paletteMap;
}
