@use 'sass:color';
@use 'sass:map';

@function light-change($color, $amount, $isDark) {
    $multiplier: if($isDark, -1, 1);
    @return color.adjust($color, $lightness: $amount * $multiplier);
}

@function alpha-change($color, $alpha) {
    @return color.change($color, $alpha: $alpha);
}

@function color-variants-light($color, $is-dark, $with-base: false) {
    $set: (
        '3%':  light-change($color, -3%, $is-dark),
        '6%':  light-change($color, -6%, $is-dark),
        '9%':  light-change($color, -9%, $is-dark),
        '12%': light-change($color, -12%, $is-dark),
        '15%': light-change($color, -15%, $is-dark),
        '18%': light-change($color, -18%, $is-dark),
        '21%': light-change($color, -21%, $is-dark),
        '24%': light-change($color, -24%, $is-dark),
        '27%': light-change($color, -27%, $is-dark),
        '30%': light-change($color, -30%, $is-dark),
        '33%': light-change($color, -33%, $is-dark),
        '36%': light-change($color, -36%, $is-dark),
        '39%': light-change($color, -39%, $is-dark)
    );

    @if $with-base {
        $set: map.merge((base: $color), $set);
    }

    @return $set;  
}

@function color-variants-dark($color, $is-dark, $with-base: false) {
    $set: (
        '3%':  light-change($color, 3%, $is-dark),
        '6%':  light-change($color, 6%, $is-dark),
        '9%':  light-change($color, 9%, $is-dark),
        '12%': light-change($color, 12%, $is-dark),
        '15%': light-change($color, 15%, $is-dark),
        '18%': light-change($color, 18%, $is-dark),
        '21%': light-change($color, 21%, $is-dark),
        '24%': light-change($color, 24%, $is-dark),
        '27%': light-change($color, 27%, $is-dark),
        '30%': light-change($color, 30%, $is-dark),
        '33%': light-change($color, 33%, $is-dark),
        '36%': light-change($color, 36%, $is-dark),
        '39%': light-change($color, 39%, $is-dark),
    );

    @if $with-base {
        $set: map.merge((base: $color), $set);
    }

    @return $set;    
}

@function variants($color, $is-dark, $light: true, $dark: true, $base: true, $override-base-with: null) {
    $set: ();

    // base: $color,
    // light: color-variants-light($color, $is-dark),
    // dark: color-variants-dark($color, $is-dark),

    @if $light {
        $set: map.merge($set, (light: color-variants-light($color, $is-dark)));
    }

    @if $dark {
        $set: map.merge($set, (dark: color-variants-dark($color, $is-dark)));
    }

    @if $base {
        @if $override-base-with {
            $set: map.merge($set, (base: $override-base-with));
        } @else {
            $set: map.merge($set, (base: $color));
        }
    }

    @return $set;
}