@use 'sass:list';
@use "sass:math";
@use "sass:color";

@function new-breakpoint($query: $feature $value) {
    $default-feature-min: "min-width";

    @if list.length($query) == 1 {
        $query: $default-feature-min nth($query, 1);
    } @else if is-even(list.length($query)) {
        $query: list.append($query, 12);
    }
    @return $query;
}

@function tint-color($color, $weight) {
    @return color.mix(white, $color, $weight);
}

// Shade a color: mix a color with black
@function shade-color($color, $weight) {
    @return color.mix(black, $color, $weight);
}

@function shift-color($color, $weight) {
    @if $weight > 0 {
        @return shade-color($color, $weight);
    } @else {
        @return tint-color($color, -$weight);
    }
}

@function col_r($color) {
    @if $color <=0.03928 {
        @return math.div($color, 12.92);
    }

    @else {
        @return math.pow(math.div(($color + 0.055), 1.055), (2.4));
    }
}

@function getContrast($bgColor, $lightColor: #fff, $darkColor: #000) {
    @if ($bgColor == null) {
        @return null;
    }
    $r: color.channel($bgColor, "red", $space: rgb);
    $g: color.channel($bgColor, "green", $space: rgb);
    $b: color.channel($bgColor, "blue", $space: rgb);
    $ui_r: calc($r / 255);
    $ui_g: calc($g / 255);
    $ui_b: calc($b / 255);

    $ui_r_c: col_r($ui_r);
    $ui_g_c: col_r($ui_g);
    $ui_b_c: col_r($ui_b);

    $L: (
        0.2126 * $ui_r_c) + (0.7152 * $ui_g_c) + (0.0722 * $ui_b_c
    );

    @if ($L > 0.179) {
        @return $darkColor;
    }

    @else {
        @return $lightColor;
    }
}

@function rem-to-px($value) {
    $stripValue: math.div($value, $value * 0 + 1);
    @return $stripValue * 16;
}