@use 'sass:list';
@use 'sass:string';
@use 'sass:meta';
@use '../../list/list-includes/list-includes.scss' as *;
@use '../../math/get-numeric/get-numeric.scss' as *;

/**
 * Parses a given list of values using standard CSS order (top, right, bottom, left).
 *
 * If one argument is supplied it used for all positioning properties.
 * If two arguments are supplied the first is used as 'top' and 'bottom' value, the second is used as 'left' and 'right' value.
 * If three arguments are supplied the first is used as 'top' value, the second is used as 'left' and 'right' value, the third is used as 'bottom' value.
 * If four arguments are supplied the first is used as 'top' value, the second is used as 'right' value, the third is used as 'bottom' value, the fourth is used as 'left' value.
 *
 * @param     {list}    $values    A list of values.
 *
 * @return    {map}     Full set of positioning properties structured of (position: value).
 */
@function parse-directions($values...) {
	@if (list.length($values) == 1) {
		$values: list.nth($values, 1);
	}

	$top: if(list.length($values) >= 1, string.unquote(#{list.nth($values, 1)}), null);
	$right: if(list.length($values) >= 2, string.unquote(#{list.nth($values, 2)}), $top);
	$bottom: if(list.length($values) >= 3, string.unquote(#{list.nth($values, 3)}), $top);
	$left: if(list.length($values) >= 4, string.unquote(#{list.nth($values, 4)}), $right);
	$top: if(list-includes(('', 'null', 'n'), $top), null, $top);
	$right: if(list-includes(('', 'null', 'n'), $right), null, $right);
	$bottom: if(list-includes(('', 'null', 'n'), $bottom), null, $bottom);
	$left: if(list-includes(('', 'null', 'n'), $left), null, $left);
	$top-numeric: get-numeric($top);
	$right-numeric: get-numeric($right);
	$bottom-numeric: get-numeric($bottom);
	$left-numeric: get-numeric($left);

	@return (
		top: if($top-numeric, $top-numeric, $top),
		right: if($right-numeric, $right-numeric, $right),
		bottom: if($bottom-numeric, $bottom-numeric, $bottom),
		left: if($left-numeric, $left-numeric, $left),
	);
}
