@use "styleboost/utilities/functions" as *;
@use "sass:string";
@use "sass:list";
@use "sass:map";

// Generate CSS properties
@mixin map-to-properties($map, $prefix: '') {

	@if not $prefix {
		$prefix: '';
	}

	@each $name, $value in $map {
		$type: type-of($value);

		// If the value is an empty map, skip it
		@if $type == 'map' and map.keys($value) == () {
			// Ignore
		} @else if $type == 'list' and list.length($value) == 0 {
			// Do nothing
		} @else {
			#{$prefix + $name}: #{$value};
		}
	}
}

// Generate CSS properties, but make sure it's the base value
@mixin map-to-base-properties($map, $prefix) {
	@each $name, $value in $map {
		$value: get-base-color($value);
		#{$prefix + $name}: #{$value};
	}
}

// Print a quoted string property (like `content` or `font-family`)
@mixin print-quoted-string-property($property, $value) {

	// If value is a list, quote each entry
	@if type-of($value) == 'list' {
		$quoted: null;
		@each $entry in $value {
			@if $quoted {
				$quoted: $quoted, string.quote($entry);
			} @else {
				$quoted: string.quote($entry);
			}
		}
		$value: $quoted;
	} @else {
		$value: string.quote($value);
	}

	#{$property}: $value;
}

// Print rules for all the headers
@mixin all-headers() {

	$selector: '';

	@for $i from 1 through 6 {

		@if $i > 1 {
			$selector: $selector + ', ';
		}

		$selector: $selector + 'h#{$i}, .h#{$i}';
	}

	#{ $selector } {
		@content;
	}
}

// Styles for horizontal context
@mixin in-horizontal-context($selector, $is_default: false) {

	$selectors: "";

	@if $is_default {
		$selectors: $selector + ", ";
	}

	$selectors: $selectors + $selector + ".horizontal";

	// When inside the `.level` class, it should also be horizontal
	$selectors: $selectors + ", .level > " + $selector;
	$selectors: $selectors + ", .level-item > " + $selector;

	#{$selectors} {
		@content;
	}
}

// Styles for vertical context
@mixin in-vertical-context($selector, $is_default: false) {

	$selectors: "";

	@if $is_default {
		$selectors: $selector + ", ";
	}

	$selectors: $selectors + $selector + ".vertical";

	// When inside the `.column` class, it should be horizontal
	$selectors: $selectors + ", .column > " + $selector;

	#{$selectors} {
		@content;
	}
}