@use 'kv-theme-default';
@use "sass:color";
@use "sass:map";

/// Gets the specific color's css variable from the name and variation.
/// Alpha/rgb are optional.
///
/// @deprecated Use the design token CSS variables from style-dictionary instead. e.g. var(--color-primary-base)
///
/// @example
///   kv-color(primary, base) => var(--kv-primary, #005CC7)
///   kv-color(secondary, contrast) => var(--kv-secondary-contrast)
///   kv-color(primary, base, 0.5) => rgba(var(--kv-primary-rgb, 0, 92, 199), 0.5)
@function kv-color($name, $variation: base, $alpha: null, $rgb: false) {
	$values: map.get(kv-theme-default.$colors, $name);
	@if ($values) {
		$value: map.get($values, $variation);
		$variable: --kv-#{$name}-#{$variation};

		@if ($variation == base) {
			$variable: --kv-#{$name};
		}
		@if ($alpha) {
			$value: color-to-rgb($value);
			@return rgba(var(#{$variable}-rgb, $value), $alpha);
		}
		@if ($rgb) {
			$value: color-to-rgb($value);
			$variable: #{$variable}-rgb;
		}

		@return var(#{$variable}, $value);
	}
	@return null;
}

/// @deprecated
/// Mixes a color with black to create its dark.
@function get-color-dark($color) {
	@warn 'get-color-dark is deprecated';
	@return color.mix(#000, $color, 12%);
}

/// @deprecated
/// Mixes a color with white to create its light.
@function get-color-light($color) {
	@warn 'get-color-light is deprecated';
	@return color.mix(#fff, $color, 80%);
}

/// @deprecated
// Converts a color to a comma separated rgb.
// Doesn't work with CSS variables 
// -----------------------------------------------------------
@function color-to-rgb($color) {
	@return #{color.channel($color, 'red', $space: rgb)},#{color.channel($color, 'green', $space: rgb)},#{color.channel($color, 'blue', $space: rgb)};
}
