@use "sass:map";
@use "@theholocron/config/src" as config;
@use "@theholocron/css-syntaxes/src" as syntaxes;
@use "@theholocron/scss-mixins/src/at-rules/breakpoints" as *;
@use "@theholocron/scss-mixins/src/backgrounds-borders/" as *;

/// The border property
/// @since 0.1.0
/// @link https://developer.mozilla.org/en-US/docs/Web/CSS/border
/// @param {String} $className ["border"] - a CSS class name that will prefix all helpers
/// @param {Map} $breakpoints [config.$breakpoints] - a map of grid breakpoints
/// @example scss
///   @include border($className: bs, $breakpoints: ("sm": 480px));
@mixin borders($className: "border", $breakpoints: config.$breakpoints, $widths: config.$border-widths, $styles: syntaxes.$border-style, $colors: config.$border-colors) {
	.#{$className} {
		@each $size, $width in $widths {
			@each $style in $styles {
				@each $name, $color in $colors {
					@each $abbrev, $direction in config.$box-directions {
						@if $abbrev == "all" {
							&-#{$size}-#{$style}-#{$name} {
								@include border($width: $width, $style: $style, $color: $color, $direction: $abbrev);
							}

							@each $breakpoint in map.keys($breakpoints) {
								@include media-breakpoint-up($name: $breakpoint, $breakpoints: $breakpoints) {
									&-#{$size}-#{$style}-#{$name}-#{$breakpoint},
									&-#{$size}-#{$style}-#{$name}-#{$breakpoint}-up {
										@include border($width: $width, $style: $style, $color: $color, $direction: $abbrev);
									}
								}

								@include media-breakpoint-down($name: $breakpoint, $breakpoints: $breakpoints) {
									&-#{$size}-#{$style}-#{$name}-#{$breakpoint}-down {
										@include border($width: $width, $style: $style, $color: $color, $direction: $abbrev);
									}
								}

								@include media-breakpoint-only($name: $breakpoint, $breakpoints: $breakpoints) {
									&-#{$size}-#{$style}-#{$name}-#{$breakpoint}-only {
										@include border($width: $width, $style: $style, $color: $color, $direction: $abbrev);
									}
								}
							}
						} @else {
							&-#{$abbrev}-#{$size}-#{$style}-#{$name} {
								@include border($width: $width, $style: $style, $color: $color, $direction: $abbrev);
							}

							@each $breakpoint in map.keys($breakpoints) {
								@include media-breakpoint-up($name: $breakpoint, $breakpoints: $breakpoints) {
									&-#{$abbrev}-#{$size}-#{$style}-#{$name}-#{$breakpoint},
									&-#{$abbrev}-#{$size}-#{$style}-#{$name}-#{$breakpoint}-up {
										@include border($width: $width, $style: $style, $color: $color, $direction: $abbrev);
									}
								}

								@include media-breakpoint-down($name: $breakpoint, $breakpoints: $breakpoints) {
									&-#{$abbrev}-#{$size}-#{$style}-#{$name}-#{$breakpoint}-down {
										@include border($width: $width, $style: $style, $color: $color, $direction: $abbrev);
									}
								}

								@include media-breakpoint-only($name: $breakpoint, $breakpoints: $breakpoints) {
									&-#{$abbrev}-#{$size}-#{$style}-#{$name}-#{$breakpoint}-only {
										@include border($width: $width, $style: $style, $color: $color, $direction: $abbrev);
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
