// Functions
// Custom Sass functions used in Shellinabox S3


// Colors arithmetic
// Used in `mixins` to generate 216 colors table
@function sum-colors($color-a, $color-b, $amount) {
	@return adjust-color($color-a,
		$red:     red($color-b) * $amount,
		$green: green($color-b) * $amount,
		$blue:   blue($color-b) * $amount
	);
}


// Sass map abstraction
// Retrieve property from theme
@function theme($prop) {
	@return map-get($theme, $prop);
}

// Retrieve color from theme
@function color($name) {
	@if ($name == "background" or $name == "foreground") {
		@return theme($name);
	}

	// Lookup into theme's sorted palette
	$index: index((
			black, red, green, yellow, blue, magenta, cyan, white,
			brightblack, brightred,     brightgreen, brightyellow,
			brightblue,  brightmagenta, brightcyan,  brightwhite), $name);

	@return nth(theme(colors), $index);
}

// Retrieve property from theme
@function ui-color($color) {
	@return map-get($ui-colors, $color);
}
