// PADDY MAN, CHALE. I SEE YOU KEEP WAAA... LONG TIME NO SEE

@use 'sass:color';
$maxFixations: 4;
$maxSaccadesInterval: 4;
$activeFixationOpacity: 100%;

//define colors for fixations
$hue1: #3aa757ff;
$hue2: #453823ff;
$hue3: #561f37ff;
$hue4: rgb(68, 155, 255);
$delta: 8%;

$saccadesColorsBase: (
	0,
	$hue1),
	(1, $hue2),
	(2, $hue3),
	(3, $hue4
);

/**
	generate (3) fixation-strength variants
*/
@mixin makeFixation($fixationStrength, $saccadesColor) {
	$fixationsAllowed: $fixationStrength;

	@for $fixationsAllowed from 1 through $fixationStrength {
		[fixation-strength='#{$fixationsAllowed}'] {
			display: inline;
			--fixation-edge-opacity: $activeFixationOpacity;
			font-weight: var(--br-boldness);
			line-height: var(--br-line-height, initial);
			color: #{$saccadesColor};
			text-decoration: var(--br-line-style) underline 2px;
			text-underline-offset: 3px;
		}
	}
}

// generate all saccades-interval variants
@mixin makeSaccades($fixationStrength) {
	@for $saccadesIndex from 0 through $maxSaccadesInterval {
		&[saccades-interval='#{$saccadesIndex}'][fixation-strength='#{$fixationStrength}'] br-bold:nth-of-type(#{$saccadesIndex + 1}n + 1) {
			//for each saccade variant, make 3 fixation-strength variants
			// fixation-strength variants are applied inclusively from 1 through 4
			@include makeFixation($fixationStrength, var(--saccadesColor));
		}
	}
}

@mixin makeColorVariants($color, $id, $delta, $label) {
	&[saccades-color='#{$label}'] {
		br-bold:nth-of-type(#{$maxSaccadesInterval}n + #{$id}) {
			--saccadesColor: #{color.adjust($color, $lightness: $delta)};
		}
	}

	&[saccades-color='#{$label}-100'] {
		br-bold:nth-of-type(#{$maxSaccadesInterval}n + #{$id}) {
			--saccadesColor: #{color.adjust($color, $lightness: $delta * 2.7)};
		}
	}

	&[saccades-color='custom'] br-bold:nth-of-type(#{$maxSaccadesInterval}n + #{$id}) {
		--saccadesColor: var(--saccadesColorOveride-#{$id});
	}

}

[br-mode='on'] {

	br-bold *,
	br-edge {
		opacity: (var(--fixation-edge-opacity, $activeFixationOpacity));
	}

	@for $fixationStrength from 1 through $maxFixations {
		@include makeSaccades($fixationStrength);
	}

	@each $id, $color in $saccadesColorsBase {
		@include makeColorVariants($color, $id, $delta, 'light');

		@include makeColorVariants($color, $id, -$delta, 'dark');
	}

	$excludedElements: (
		nav,
		footer,
		p,
		a,
		button,
		aside
	);

@each $excludedElement in $excludedElements {

	&.br-exclusions-#{$excludedElement} #{$excludedElement} {

		& br-bold :is(*, [fixation-strength]),
		& br-edge {
			--fixation-edge-opacity: initial !important;
			--br-line-height: initial !important;
			--br-boldness: initial !important;
			opacity: initial;
		}
	}

}
}