@use 'sass:meta';
@use 'sass:string';
@use 'config';

/* BEM support Func
 -------------------------- */
@function selectorToString($selector) {
	$selector: meta.inspect($selector);
	$selector: string.slice($selector, 2, -2);
	@return $selector;
}

@function containsModifier($selector) {
	$selector: selectorToString($selector);

	@if string.index($selector, config.$modifier-separator) {
		@return true;
	} @else {
		@return false;
	}
}

@function containWhenFlag($selector) {
	$selector: selectorToString($selector);

	@if string.index($selector, '.' + config.$state-prefix) {
		@return true;
	} @else {
		@return false;
	}
}

@function containPseudoClass($selector) {
	$selector: selectorToString($selector);

	@if string.index($selector, ':') {
		@return true;
	} @else {
		@return false;
	}
}

@function hitAllSpecialNestRule($selector) {
	@return containsModifier($selector) or containWhenFlag($selector) or containPseudoClass($selector);
}

@function lightness($h, $s, $l, $lightness) {
	@return hsl(var(#{$h}), var(#{$s}), calc(var(#{$l}) + #{$lightness}));
}

@function saturation($h, $s, $l, $saturation) {
	@return hsl(var(#{$h}), calc(var(#{$s}) + #{$saturation}), var(#{$l}));
}
