////
/// @group Links
////

/// A mixin for creating a link component. This generally should be used with the `a` or `button` element.
/// @param {Map} $map - A map of `key: value` pairs. The keys and value types are listed below:
/// @example
/// (
/// 	enabled: {Bool}, // Set to false to prevent .dropdown-item styles from being output. Default: true
/// 	before: (
/// 		// .link::before
/// 	),
/// 	after: (
/// 		// .link::after
/// 	),
/// 	link: (
/// 		// .link:link
/// 		before: (
/// 			// .link:link::before
/// 		),
/// 		after: (
/// 			// .link:link::after
/// 		),
/// 		inline-item: (
/// 			// .link:link .inline-item
/// 		),
/// 		inline-item:-before (
/// 			// .link:link .inline-item-before
/// 		),
/// 		inline-item-middle: (
/// 			// .link:link .inline-item-middle
/// 		),
/// 		inline-item-after: (
/// 			// .link:link .inline-item-after
/// 		),
/// 	),
/// 	visited: (
/// 		// .link:visited
/// 		before: (
/// 			// .link:visited::before
/// 		),
/// 		after: (
/// 			// .link:visited::after
/// 		),
/// 		inline-item: (
/// 			// .link:visited .inline-item
/// 		),
/// 		inline-item:-before (
/// 			// .link:visited .inline-item-before
/// 		),
/// 		inline-item-middle: (
/// 			// .link:visited .inline-item-middle
/// 		),
/// 		inline-item-after: (
/// 			// .link:visited .inline-item-after
/// 		),
/// 	),
/// 	hover: (
/// 		// .link:hover
/// 		before: (
/// 			// .link:hover::before
/// 		),
/// 		after: (
/// 			// .link:hover::after
/// 		),
/// 		inline-item: (
/// 			// .link:hover .inline-item
/// 		),
/// 		inline-item:-before (
/// 			// .link:hover .inline-item-before
/// 		),
/// 		inline-item-middle: (
/// 			// .link:hover .inline-item-middle
/// 		),
/// 		inline-item-after: (
/// 			// .link:hover .inline-item-after
/// 		),
/// 	),
/// 	focus: (
/// 		// .link:focus
/// 		before: (
/// 			// .link:focus::before
/// 		),
/// 		after: (
/// 			// .link:focus::after
/// 		),
/// 		inline-item: (
/// 			// .link:focus .inline-item
/// 		),
/// 		inline-item:-before (
/// 			// .link:focus .inline-item-before
/// 		),
/// 		inline-item-middle: (
/// 			// .link:focus .inline-item-middle
/// 		),
/// 		inline-item-after: (
/// 			// .link:focus .inline-item-after
/// 		),
/// 	),
/// 	active: (
/// 		// .link:active
/// 		before: (
/// 			// .link:active::before
/// 		),
/// 		after: (
/// 			// .link:active::after
/// 		),
/// 		inline-item: (
/// 			// .link:active .inline-item
/// 		),
/// 		inline-item:-before (
/// 			// .link:active .inline-item-before
/// 		),
/// 		inline-item-middle: (
/// 			// .link:active .inline-item-middle
/// 		),
/// 		inline-item-after: (
/// 			// .link:active .inline-item-after
/// 		),
/// 	),
/// 	active-class: (
/// 		// .link.active
/// 		before: (
/// 			// .link.active::before
/// 		),
/// 		after: (
/// 			// .link.active::after
/// 		),
/// 		inline-item: (
/// 			// .link.active .inline-item
/// 		),
/// 		inline-item:-before (
/// 			// .link.active .inline-item-before
/// 		),
/// 		inline-item-middle: (
/// 			// .link.active .inline-item-middle
/// 		),
/// 		inline-item-after: (
/// 			// .link.active .inline-item-after
/// 		),
/// 	),
/// 	disabled: (
/// 		// .link:disabled, .link.disabled
/// 		before: (
/// 			// .link:disabled::before, .link.disabled::before
/// 		),
/// 		after: (
/// 			// .link:disabled::after, .link.disabled::after
/// 		),
/// 		active: (
/// 			// .link:disabled:active, .link.disabled:active
/// 			before: (
/// 				// .link:disabled:active::before, .link.disabled:active::before
/// 			),
/// 			after: (
/// 				// .link:disabled:active::after, .link.disabled:active::after
/// 			),
/// 		),
/// 		inline-item: (
/// 			// .link:disabled .inline-item
/// 		),
/// 		inline-item:-before (
/// 			// .link:disabled .inline-item-before
/// 		),
/// 		inline-item-middle: (
/// 			// .link:disabled .inline-item-middle
/// 		),
/// 		inline-item-after: (
/// 			// .link:disabled .inline-item-after
/// 		),
/// 	),
/// 	btn-focus: (
/// 		// .link[type]:focus
/// 	),
/// 	show: (
/// 		// .link[aria-expanded='true'], .link.show, .show .link
/// 		before: (
/// 			// .link.show::before
/// 		),
/// 		after: (
/// 			// .link.show::after, .link.disabled::after
/// 		),
/// 	),
/// 	c-inner: (
/// 		enabled: {Bool}, // Set to false to prevent .dropdown-item styles from being output. Default: true
/// 		// .link > .c-inner
/// 	),
/// 	inline-item: (
/// 		// .link .inline-item
/// 	),
/// 	inline-item-before: (
/// 		// .link .inline-item-before
/// 	),
/// 	inline-item-middle: (
/// 		// .link .inline-item-middle
/// 		inline-item-middle: (
/// 			// .link .inline-item-middle + .inline-item-middle
/// 		),
/// 	),
/// 	inline-item-after: (
/// 		// .link .inline-item-after
/// 	),
/// 	lexicon-icon: (
/// 		// .link .lexicon-icon
/// 	),
/// )
/// -=-=-=-=-=- Deprecated -=-=-=-=-=-
/// bg: {Color | String | Null}, // deprecated after 3.9.0
/// hover-bg: {Color | String | Null}, // deprecated after 3.9.0
/// hover-border-color: {Color | String | List | Null}, // deprecated after 3.9.0
/// hover-color: {Color | String | Null}, // deprecated after 3.9.0
/// hover-opacity: {Number | String | Null}, // deprecated after 3.9.0
/// hover-text-decoration: {String | Null}, // deprecated after 3.9.0
/// hover-z-index: {Number | String | Null}, // deprecated after 3.9.0
/// focus-bg: {Color | String | Null}, // deprecated after 3.9.0
/// focus-border-color: {Color | String | List | Null}, // deprecated after 3.9.0
/// focus-border-radius: {Number | String | List | Null}, // deprecated after 3.9.0
/// focus-box-shadow: {String | List | Null}, // deprecated after 3.9.0
/// focus-color: {Color | String | Null}, // deprecated after 3.9.0
/// focus-opacity: {Number | String | Null}, // deprecated after 3.9.0
/// focus-outline: {Number | String | Null}, // deprecated after 3.9.0
/// focus-text-decoration: {String | Null}, // deprecated after 3.9.0
/// focus-z-index: {Number | String | Null}, // deprecated after 3.9.0
/// active-bg: {Color | String | Null}, // deprecated after 3.9.0
/// active-border-color: {Color | String | List | Null}, // deprecated after 3.9.0
/// active-color: {Color | String | Null}, // deprecated after 3.9.0
/// active-font-weight: {Number | String | Null}, // deprecated after 3.9.0
/// active-z-index: {Number | String | Null}, // deprecated after 3.9.0
/// active-class-bg: {Color | String | Null}, // deprecated after 3.9.0
/// active-class-border-color: {Color | String | List | Null}, // deprecated after 3.9.0
/// active-class-color: {Color | String | Null}, // deprecated after 3.9.0
/// active-class-font-weight: {Number | String | Null}, // deprecated after 3.9.0
/// active-class-z-index: {Number | String | Null}, // deprecated after 3.9.0
/// disabled-bg: {Color | String | Null}, // deprecated after 3.9.0
/// disabled-border-color: {Color | String | List | Null}, // deprecated after 3.9.0
/// disabled-box-shadow: {String | List | Null}, // deprecated after 3.9.0
/// disabled-color: {Color | String | Null}, // deprecated after 3.9.0
/// disabled-cursor: {String | Null}, // deprecated after 3.9.0
/// disabled-opacity: {Number | String | Null}, // deprecated after 3.9.0
/// disabled-pointer-events: {String | Null}, // deprecated after 3.9.0
/// disabled-text-decoration: {String | Null}, // deprecated after 3.9.0
/// disabled-active: {Map | Null}, // deprecated after 3.39.0
/// btn-focus-box-shadow: {String | List | Null}, // deprecated after 3.9.0
/// btn-focus-outline: {Number | String | Null}, // deprecated after 3.9.0
/// btn-focus: {Map | Null}, // deprecated after 3.39.0
/// lexicon-icon-font-size: {Number | String | Null}, // deprecated after 3.9.0
/// lexicon-icon-margin-bottom: {Number | String | Null}, // deprecated after 3.9.0
/// lexicon-icon-margin-left: {Number | String | Null}, // deprecated after 3.9.0
/// lexicon-icon-margin-right: {Number | String | Null}, // deprecated after 3.9.0
/// lexicon-icon-margin-top: {Number | String | Null}, // deprecated after 3.9.0

@mixin clay-link($map) {
	@if (type-of($map) == 'map') {
		$enabled: setter(map-get($map, enabled), true);

		$base: map-merge(
			$map,
			(
				background-color:
					setter(map-get($map, bg), map-get($map, background-color)),
			)
		);

		$hover: setter(map-get($map, hover), ());
		$hover: map-merge(
			$hover,
			(
				background-color:
					setter(
						map-get($map, hover-bg),
						map-get($hover, background-color)
					),
				border-color:
					setter(
						map-get($map, hover-border-color),
						map-get($hover, border-color)
					),
				color:
					setter(map-get($map, hover-color), map-get($hover, color)),
				opacity:
					setter(
						map-get($map, hover-opacity),
						map-get($hover, opacity)
					),
				text-decoration:
					setter(
						map-get($map, hover-text-decoration),
						map-get($hover, text-decoration)
					),
				z-index:
					setter(
						map-get($map, hover-z-index),
						map-get($hover, z-index)
					),
			)
		);

		$focus: setter(map-get($map, focus), ());
		$focus: map-merge(
			$focus,
			(
				background-color:
					setter(
						map-get($map, focus-bg),
						map-get($focus, background-color)
					),
				border-color:
					setter(
						map-get($map, focus-border-color),
						map-get($focus, border-color)
					),
				border-radius:
					setter(
						map-get($map, focus-border-radius),
						map-get($focus, border-radius)
					),
				box-shadow:
					setter(
						map-get($map, focus-box-shadow),
						map-get($focus, box-shadow)
					),
				color:
					setter(map-get($map, focus-color), map-get($focus, color)),
				opacity:
					setter(
						map-get($map, focus-opacity),
						map-get($focus, opacity)
					),
				outline:
					setter(
						map-get($map, focus-outline),
						map-get($focus, outline)
					),
				text-decoration:
					setter(
						map-get($map, focus-text-decoration),
						map-get($focus, text-decoration)
					),
				z-index:
					setter(
						map-get($map, focus-z-index),
						map-get($focus, z-index)
					),
			)
		);

		$active: setter(map-get($map, active), ());
		$active: map-merge(
			$active,
			(
				background-color:
					setter(
						map-get($map, active-bg),
						map-get($active, background-color)
					),
				border-color:
					setter(
						map-get($map, active-border-color),
						map-get($active, border-color)
					),
				color:
					setter(
						map-get($map, active-color),
						map-get($active, color)
					),
				font-weight:
					setter(
						map-get($map, active-font-weight),
						map-get($active, font-weight)
					),
				z-index:
					setter(
						map-get($map, active-z-index),
						map-get($active, z-index)
					),
			)
		);

		$active-class: setter(map-get($map, active-class), ());
		$active-class: map-merge(
			$active-class,
			(
				background-color:
					setter(
						map-get($map, active-class-bg),
						map-get($active-class, background-color),
						map-get($active, background-color)
					),
				border-color:
					setter(
						map-get($map, active-class-border-color),
						map-get($active-class, border-color),
						map-get($active, border-color)
					),
				color:
					setter(
						map-get($map, active-class-color),
						map-get($active-class, color),
						map-get($active, color)
					),
				font-weight:
					setter(
						map-get($map, active-class-font-weight),
						map-get($active-class, font-weight),
						map-get($active, font-weight)
					),
				z-index:
					setter(
						map-get($map, active-class-z-index),
						map-get($active-class, z-index),
						map-get($active, z-index)
					),
			)
		);

		$disabled: setter(map-get($map, disabled), ());
		$disabled: map-merge(
			$disabled,
			(
				background-color:
					setter(
						map-get($map, disabled-bg),
						map-get($disabled, background-color)
					),
				border-color:
					setter(
						map-get($map, disabled-border-color),
						map-get($disabled, border-color)
					),
				box-shadow:
					setter(
						map-get($map, disabled-box-shadow),
						map-get($disabled, box-shadow)
					),
				color:
					setter(
						map-get($map, disabled-color),
						map-get($disabled, color)
					),
				cursor:
					setter(
						map-get($map, disabled-cursor),
						map-get($disabled, cursor)
					),
				opacity:
					setter(
						map-get($map, disabled-opacity),
						map-get($disabled, opacity)
					),
				pointer-events:
					setter(
						map-get($map, disabled-pointer-events),
						map-get($disabled, pointer-events)
					),
				text-decoration:
					setter(
						map-get($map, disabled-text-decoration),
						map-get($disabled, text-decoration)
					),
			)
		);

		$disabled-active: setter(map-get($disabled, active), ());
		$disabled-active: map-deep-merge(
			$disabled-active,
			map-get($map, disabled-active)
		);
		$disabled-active: map-deep-merge(
			$disabled-active,
			(
				pointer-events:
					setter(
						map-get($map, disabled-active-pointer-events),
						map-get($disabled-active, pointer-events)
					),
			)
		);

		$show: setter(map-get($map, show), ());
		$show: map-merge($active-class, $show);

		$btn-focus: setter(map-get($map, btn-focus), ());
		$btn-focus: map-merge(
			$btn-focus,
			(
				box-shadow:
					setter(
						map-get($map, btn-focus-box-shadow),
						map-get($btn-focus, box-shadow)
					),
				outline:
					setter(
						map-get($map, btn-focus-outline),
						map-get($btn-focus, outline)
					),
			)
		);

		$lexicon-icon: setter(map-get($map, lexicon-icon), ());
		$lexicon-icon: map-merge(
			$lexicon-icon,
			(
				font-size:
					setter(
						map-get($map, lexicon-icon-font-size),
						map-get($lexicon-icon, font-size)
					),
				margin-bottom:
					setter(
						map-get($map, lexicon-icon-margin-bottom),
						map-get($lexicon-icon, margin-bottom)
					),
				margin-left:
					setter(
						map-get($map, lexicon-icon-margin-left),
						map-get($lexicon-icon, margin-left)
					),
				margin-right:
					setter(
						map-get($map, lexicon-icon-margin-right),
						map-get($lexicon-icon, margin-right)
					),
				margin-top:
					setter(
						map-get($map, lexicon-icon-margin-top),
						map-get($lexicon-icon, margin-top)
					),
			)
		);

		$c-inner: setter(map-get($map, c-inner), ());
		$c-inner: map-merge(
			(
				enabled:
					if(
						variable-exists(enable-c-inner),
						$enable-c-inner,
						if(
							variable-exists(cadmin-enable-c-inner),
							$cadmin-enable-c-inner,
							true
						)
					),
				margin-bottom: math-sign(map-get($map, padding-bottom)),
				margin-left: math-sign(map-get($map, padding-left)),
				margin-right: math-sign(map-get($map, padding-right)),
				margin-top: math-sign(map-get($map, padding-top)),
			),
			$c-inner
		);

		@if ($enabled) {
			@include clay-css($base);

			&::before {
				@include clay-css(map-get($map, before));
			}

			&::after {
				@include clay-css(map-get($map, after));
			}

			&:link {
				@include clay-css(map-get($map, link));

				&::before {
					@include clay-css(map-deep-get($map, link, before));
				}

				&::after {
					@include clay-css(map-deep-get($map, link, after));
				}

				.inline-item {
					@include clay-css(map-deep-get($map, link, inline-item));
				}

				.inline-item-before {
					@include clay-css(
						map-deep-get($map, link, inline-item-before)
					);
				}

				.inline-item-middle {
					@include clay-css(
						map-deep-get($map, link, inline-item-middle)
					);
				}

				.inline-item-after {
					@include clay-css(
						map-deep-get($map, link, inline-item-after)
					);
				}
			}

			&:visited {
				@include clay-css(map-get($map, visited));

				&::before {
					@include clay-css(map-deep-get($map, visited, before));
				}

				&::after {
					@include clay-css(map-deep-get($map, visited, after));
				}

				.inline-item {
					@include clay-css(map-deep-get($map, visited, inline-item));
				}

				.inline-item-before {
					@include clay-css(
						map-deep-get($map, visited, inline-item-before)
					);
				}

				.inline-item-middle {
					@include clay-css(
						map-deep-get($map, visited, inline-item-middle)
					);
				}

				.inline-item-after {
					@include clay-css(
						map-deep-get($map, visited, inline-item-after)
					);
				}
			}

			&:hover {
				@include clay-css($hover);

				&::before {
					@include clay-css(map-deep-get($map, hover, before));
				}

				&::after {
					@include clay-css(map-deep-get($map, hover, after));
				}

				.inline-item {
					@include clay-css(map-get($hover, inline-item));
				}

				.inline-item-before {
					@include clay-css(map-get($hover, inline-item-before));
				}

				.inline-item-middle {
					@include clay-css(map-get($hover, inline-item-middle));
				}

				.inline-item-after {
					@include clay-css(map-get($hover, inline-item-after));
				}
			}

			&:focus {
				@include clay-css($focus);

				&::before {
					@include clay-css(map-deep-get($map, focus, before));
				}

				&::after {
					@include clay-css(map-deep-get($map, focus, after));
				}

				.inline-item {
					@include clay-css(map-get($focus, inline-item));
				}

				.inline-item-before {
					@include clay-css(map-get($focus, inline-item-before));
				}

				.inline-item-middle {
					@include clay-css(map-get($focus, inline-item-middle));
				}

				.inline-item-after {
					@include clay-css(map-get($focus, inline-item-after));
				}
			}

			&:active {
				@include clay-css($active);

				&::before {
					@include clay-css(map-deep-get($map, active, before));
				}

				&::after {
					@include clay-css(map-deep-get($map, active, after));
				}

				.inline-item {
					@include clay-css(map-get($active, inline-item));
				}

				.inline-item-before {
					@include clay-css(map-get($active, inline-item-before));
				}

				.inline-item-middle {
					@include clay-css(map-get($active, inline-item-middle));
				}

				.inline-item-after {
					@include clay-css(map-get($active, inline-item-after));
				}
			}

			&.active {
				@include clay-css($active-class);

				&::before {
					@include clay-css(map-deep-get($map, active-class, before));
				}

				&::after {
					@include clay-css(map-deep-get($map, active-class, after));
				}

				.inline-item {
					@include clay-css(map-get($active-class, inline-item));
				}

				.inline-item-before {
					@include clay-css(
						map-get($active-class, inline-item-before)
					);
				}

				.inline-item-middle {
					@include clay-css(
						map-get($active-class, inline-item-middle)
					);
				}

				.inline-item-after {
					@include clay-css(
						map-get($active-class, inline-item-after)
					);
				}
			}

			&:disabled,
			&.disabled {
				@include clay-css($disabled);

				&::before {
					@include clay-css(map-deep-get($map, disabled, before));
				}

				&::after {
					@include clay-css(map-deep-get($map, disabled, after));
				}

				&:active {
					@include clay-css($disabled-active);

					&::before {
						@include clay-css(
							map-deep-get($map, disabled, active, before)
						);
					}

					&::after {
						@include clay-css(
							map-deep-get($map, disabled, active, after)
						);
					}
				}

				.inline-item {
					@include clay-css(map-get($disabled, inline-item));
				}

				.inline-item-before {
					@include clay-css(map-get($disabled, inline-item-before));
				}

				.inline-item-middle {
					@include clay-css(map-get($disabled, inline-item-middle));
				}

				.inline-item-after {
					@include clay-css(map-get($disabled, inline-item-after));
				}
			}

			&[type] {
				&:focus {
					@include clay-css($btn-focus);
				}
			}

			&[aria-expanded='true'],
			&.show {
				@include clay-css($show);

				&::before {
					@include clay-css(map-deep-get($map, show, before));
				}

				&::after {
					@include clay-css(map-deep-get($map, show, after));
				}
			}

			@if (map-get($c-inner, enabled)) {
				> .c-inner {
					@include clay-css($c-inner);
				}
			}

			.inline-item {
				@include clay-css(map-get($map, inline-item));
			}

			.inline-item-before {
				@include clay-css(map-get($map, inline-item-before));
			}

			.inline-item-middle {
				@include clay-css(map-get($map, inline-item-middle));

				+ .inline-item-middle {
					@include clay-css(
						map-deep-get(
							$map,
							inline-item-middle,
							inline-item-middle
						)
					);
				}
			}

			.inline-item-after {
				@include clay-css(map-get($map, inline-item-after));
			}

			.lexicon-icon {
				@include clay-css($lexicon-icon);
			}
		}
	}
}

/// A mixin for styling a text element (e.g., h1, div, span). This is used in Clay CSS for `*-title`, `*-subtitle`, and `*-tertiary-title` elements.
/// @param {Map} $map - A map of `key: value` pairs. The keys and value types are listed below:
/// @example
/// enabled: {Bool}, // Set to false to prevent mixin styles from being output. Default: true
/// See Mixin `clay-css` for available keys to pass into the base selector
/// link: {Map | Null},  // See Mixin `clay-css` for available keys
/// -=-=-=-=-=- Deprecated -=-=-=-=-=-
/// clay-link: {Map | Null}, // deprecated after 3.9.0 maps to link
/// @todo
/// - Add @example
/// - Add @link to documentation

@mixin clay-text-typography($map) {
	@if (type-of($map) == 'map') {
		$enabled: setter(map-get($map, enabled), true);

		@if ($enabled) {
			$clay-link: setter(map-get($map, clay-link), ());

			$link: setter(map-get($map, link), ());
			$link: map-merge($link, $clay-link);

			$href: setter(map-get($map, href), ());
			$href: map-deep-merge($href, $link);

			@include clay-css($map);

			&::before {
				@include clay-css(map-get($map, before));
			}

			&::after {
				@include clay-css(map-get($map, after));
			}

			&:first-child {
				@include clay-css(map-get($map, first-child));
			}

			&:last-child {
				@include clay-css(map-get($map, last-child));
			}

			&[href],
			[href] {
				@include clay-link($href);
			}
		}
	}
}

/// Shortcut for mixin `clay-text-typography`
/// @param {Map} $map - A map of `key: value` pairs.

@mixin clay-title($map) {
	@include clay-text-typography($map);
}
