//---------------------------
//
// Color functions
//
//---------------------------

//---------------------------
//
// Defining acceptable alpha & shade values for color functions
//
//---------------------------
$__alpha-stops: (0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1);
$__shade-vals: ("x-dark", "dark", "base", "medium", "light", "x-light");

//---------------------------
//
// The grayscale function takes two arguments:
//  REQUIRED: Level of gray
//    There are 10 levels of gray, ranging from 1 to 10 (darkest to lightest).
//  OPTIONAL: Level of opacity
//    There are 11 levels of opacity, ranging from 0.0 to 1.0 (transparent to opaque).
//
// Example: grayscale(1, 1);
// This will create a dark gray that is fully opaque.
//
//---------------------------
@function grayscale($gradation, $alpha: 1) {
    @if map-has-key($DBgrayscaleColors, $gradation) {
        $alpha-val: $alpha;

        @if index($__alpha-stops, $alpha-val) == null {
            @error "Only alpha values in 0.1 increments are allowed";
        }

        $grayscale-val: map-get($DBgrayscaleColors, $gradation);
        @return rgba($grayscale-val, $alpha-val);
    } @else {
        @warn "No gradation of #{$gradation} found in $DBgrayscaleColors map.";
    }
}

//---------------------------
//
// The color function takes three arguments:
//  REQUIRED: Color
//    There are 7 colors (gray, blue, green, red, yellow, black, white).
//  OPTIONAL: Shade
//    Each color has 6 shades (x-dark, dark, base, medium, light, x-light).
//  OPTIONAL: Opacity
//    Each shade has 11 levels of opacity, ranging from 0.0 to 1.0 (transparent to opaque).
//
// Example: color(blue);
// This will create a base blue that is fully opaque.
//
// Example 2: color(red, dark, 0.8);
// This will create a dark red that is 80% opaque.
//
// Example 3: color(yellow, 0.6);
// This will create a base yellow that is 60% opaque.
//
//---------------------------
@function color($name, $properties...) {
    $n: length($properties);
    $i: 1;

    $shade-val: "base";
    $alpha-val: 1;

    @while $i <= $n {
        $current-property: (nth($properties, $i));

        @if type-of($current-property) == "string" {
            $shade-val: $current-property;
        } @else if type-of($current-property) == "number" {
            $alpha-val: $current-property;
        }

        $i: $i + 1;
    }

    @if index($__shade-vals, $shade-val) == null {
        @warn "Only the following shades are allowed: " + $__shade-vals;
    }

    @if index($__alpha-stops, $alpha-val) == null {
        @error "Only alpha values in 0.1 increments are allowed";
    }

    @if map-has-key($DBglobalColors, $name) {
        $rgb-val: ();

        @if $name == white or $name == black {
            $rgb-val: map-get($DBglobalColors, $name);
        } @else {
            $rgb-val: map-get(map-get($DBglobalColors, $name), $shade-val);
        }

        @return rgba($rgb-val, $alpha-val);
    } @else {
        @warn "No global color called #{$name} found."
        + "Are you sure it's in `variables/colors?`";
    }
}

