@import "../../../../../Base/Content/sass/compass";
@import "../../../../../Base/Content/sass/bootstrap/variables";

// Base left-to-right mixin definition.
@mixin ms-LTR {
  [dir='ltr'] & {
    @content;
  }
}

// Base right-to-left mixin definition.
@mixin ms-RTL {
  [dir='rtl'] & {
    @content;
  }
}

// Use baseRTL to set the default direction to right-to-left on
// a root element (e.g. page or region) that needs RTL support.
@mixin ms-base-RTL {
  @include ms-RTL {
    direction: rtl;
    unicode-bidi: bidi-override;
  }
}

// Replace or remove a portion of a string.
// Thanks to https://www.sassmeister.com/gist/1b4f2da5527830088e4d
@function ms-string-replace($string, $search, $replace: '') {
	$index: str-index($string, $search);

	@if $index {
		@return str-slice($string, 1, $index - 1) + $replace + ms-string-replace(str-slice($string, $index + str-length($search)), $search, $replace);
	}

	@return $string;
}

@mixin ms-icon-classes($icons) {

	$dedupedIcons: $icons;

	@each $iconName, $code in $dedupedIcons {
		@if str-index($iconName, 'GallatinLogo') {
			$dedupedIcons: map-remove($dedupedIcons, $iconName);
		}
	}
	// Go through icon list and create a class for each icon.
	@each $iconName, $iconCode in $dedupedIcons {
		// Class for both LTR and RTL.
		.ms-Icon--#{$iconName}::before {
			content: $iconCode;
		}
	}
	//ms-Icon--GallatinLogo
}



@mixin ms-icon-classesWithDirectionSupport($icons) {
	// De-dupe the map by removing the LTR icon for every RTL icon.
	// For example, remove 'Export' after finding 'ExportMirrored'.
	// This assumes that RTL icons will contain 'Mirrored' and that
	// they are sorted so that the mirrored icon comes later.
	$dedupedIcons: $icons;

	@each $iconName, $code in $dedupedIcons {
		@if str-index($iconName, 'Mirrored') {
			$duplicateIcon: ms-string-replace($iconName, 'Mirrored');
			$dedupedIcons: map-remove($dedupedIcons, $duplicateIcon);
		}
	}
	// Go through icon list and create a class for each icon.
	@each $iconName, $iconCode in $dedupedIcons {
		@if str-index($iconName, 'Mirrored') {
			// Create different classes for LTR and RTL layouts.
			$ltrIconName: ms-string-replace($iconName, 'Mirrored');
			$ltrIconCode: map-get($icons, $ltrIconName);

			// Classes for the regular icon.
			.ms-Icon--#{$ltrIconName}::before {
				@include ms-LTR {
					content: $ltrIconCode;
				}

				@include ms-RTL {
					content: $iconCode;
				}
			}
			// Classes for the mirrored icon.
			.ms-Icon--#{$iconName}::before {
				@include ms-LTR {
					content: $iconCode;
				}

				@include ms-RTL {
					content: $ltrIconCode;
				}
			}
		}
		@else {
			// Class for both LTR and RTL.
			.ms-Icon--#{$iconName}::before {
				content: $iconCode;
			}
		}
	}
}

