@use 'sass:list';
@use '../max-contrast/max-contrast' as mc;
@use '../../get-font-colors/get-font-colors' as fc;
@use '../../get-color';
@use '../../color-palettes' as palette;

/// Determines the color to use against the initial given color.
/// It returns the one that provides the higher contrast, ensuring better readability.
///
/// @group Theming
///
/// @param {Color} $reference-color — The color to test against.
/// @param {Map} $theme — Optional. The theme map to pull `$black` and `$white` from.
/// @return {Color} Either `$black` or `$white`, whichever has the highest contrast ratio against the reference color.
///
/// For an interesting read, see more about the topic:
/// https:///robots.thoughtbot.com/closer-look-color-lightness
///
/// Based on the code outlined by
/// [Sergio Gomes](https://sgom.es/posts/2016-12-21-using-sass-to-automatically-pick-text-colors/).
///
/// @example scss
/// 	.body {
/// 		background: daff-color($primary, 80);
/// 		color: daff-text-contrast(daff-color($primary, 80), $theme);
/// 	}
/// @example scss
/// 	.body {
/// 		background: daff-color($primary, 80);
/// 		color: daff-text-contrast(daff-color($primary, 80));
/// 	}
///
@function daff-text-contrast(
	$reference-color,
	$theme: null
) {
	@if ($theme == null) {
		$default-black: palette.$black;
		$default-white: palette.$white;
		@return mc.daff-max-contrast($reference-color, ($default-black, $default-white));
	}
	$theme-font-colors: fc.daff-get-font-colors($theme);
	@return mc.daff-max-contrast($reference-color, $theme-font-colors);
}
