// Public functions that can be used globally.

@import "dependencies";

/// Strips the units from strings
/// @param {string|number} $number - The number to remove units from.
/// @return {number} Unitless number.
/// @group core
/// @access public
/// @link https://github.com/nex3/sass/issues/533
@function strip-units($number) {
	@return $number / ($number * 0 + 1);
}

/// Takes in an absolute unit and gives back a relative one.
/// @param {number} $px - A absolute unit.
/// @param {number} $base [ $base-font-size ] - The base font size to calculate with.
/// @return {number} Realtive `em` unit.
/// @group core
/// @access public
@function em($px, $base: $base-font-size) {
	@return _calcRU($px, $base, "em");
}

/// Takes in an absolute unit and gives back a relative one.
/// @param {number} $px - A absolute unit.
/// @param {number} $base [ $base-font-size ] - The base font size to calculate with.
/// @return {number} Realtive `rem` unit.
/// @group core
/// @access public
@function rem($px, $base: $base-font-size) {
	@return _calcRU($px, $base, "rem");
}

/// Takes in an absolute unit and gives back a relative one.
/// @param {number} $px - A absolute unit.
/// @param {number} $base [ $base-font-size ] - The base font size to calculate with.
/// @return {number} Realtive `%` unit.
/// @group core
/// @access public
@function percent($px, $base: $base-font-size) {
	@return _calcRU($px, $base, "%");
}

/// Takes in an absolute unit and gives back a relative one.
/// @param {number} $size - A absolute unit.
/// @group core
/// @access public
/// @return {number} A relative unit based on the values of `$use-rem`, `$use-em`, and `$use-percent`.
@function relative($size) {
	@if($use-rem == true and $use-em == false and $use-percent == false) {
		@return rem($size);
	} @elseif($use-em == true and $use-rem == false and $use-percent == false) {
		@return em($size);
	} @elseif($use-percent == true and $use-rem == false and $use-em == false) {
		@return percent($size);
	}

	@return $size; // we're still using pixels
}

/// Takes in a color and provides a list of triad-compatible colors.
/// @param {color} $color - The color to calculate traid colors for.
/// @return {list} A list of triad colors.
/// @group core
/// @access public
@function triad($color) {
	@if(type-of($color) != "color") {
		@warn "Type must be color to continue. Aborting.";
		@return null;
	}

	$triad: ();
	$hue: strip-units(hue($color));

	@for $i from 1 through 3 {
		@if($hue + 120 > 360) {
			$hue: ($hue + 120) - 360;
		} @else {
			$hue: $hue + 120;
		}
		$color: hsl($hue, saturation($color), lightness($color));
		$triad: append($triad, $color);
	}

	@return $triad;
}

/// Takes in a color and provides a list of square-compatible colors.
/// @param {color} $color - The color to calculate traid colors for.
/// @return {list} A list of square colors.
/// @group core
/// @access public
@function square($color) {
	@if(type-of($color) != "color") {
		@warn "Type must be color to continue. Aborting.";
		@return null;
	}

	$square: ();
	$hue: strip-units(hue($color));

	@for $i from 1 through 4 {
		@if($hue + 90 > 360) {
			$hue: ($hue + 90) - 360;
		} @else {
			$hue: $hue + 90;
		}
		$color: hsl($hue, saturation($color), lightness($color));
		$square: append($square, $color);
	}

	@return $square;
}
