@use "sass:map";

$spacing_directions: (
  l: left,
  r: right,
  b: bottom,
  t: top
);
$spacer_size: px_to_rem(2px, $body_font_size) !default;
$spacer_size_x: $spacer_size !default;
$spacer_size_y: $spacer_size !default;
$spacer_size_map: (
  none: (x: 0, y: 0),
  xs-3: (
    x: $spacer_size_x,
    y: $spacer_size_y
  ),
  xs-2: (
    x: ($spacer_size_x * 2),
    y: ($spacer_size_y * 2)
  ),
  xs: (
    x: ($spacer_size_x * 4),
    y: ($spacer_size_y * 4)
  ),
  sm: (
    x: ($spacer_size_x * 6),
    y: ($spacer_size_y * 6)
  ),
  md: (
    x: ($spacer_size_x * 8),
    y: ($spacer_size_y * 8)
  ),
  lg: (
    x: ($spacer_size_x * 10),
    y: ($spacer_size_y * 10)
  ),
  xl: (
    x: ($spacer_size_x * 12),
    y: ($spacer_size_y * 12)
  ),
  xl-2: (
    x: ($spacer_size_x * 16),
    y: ($spacer_size_y * 16)
  ),
  xl-3: (
    x: ($spacer_size_x * 20),
    y: ($spacer_size_y * 20)
  ),
  xl-4: (
    x: ($spacer_size_x * 24),
    y: ($spacer_size_y * 24)
  ),
  xl-5: (
    x: ($spacer_size_x * 36),
    y: ($spacer_size_y * 36)
  ),
  xl-6: (
    x: ($spacer_size_x * 48),
    y: ($spacer_size_y * 48)
  )
) !default;

@each $prop, $abbrev in (margin: m, padding: p) {
  @each $size, $lengths in $spacer_size_map {
    $length_x: map.get($lengths, x);
    $length_y: map.get($lengths, y);

    .#{$abbrev}t-#{$size} { #{$prop}-#{map.get($spacing_directions, "t")}: $length_y; }
    .#{$abbrev}r-#{$size} { #{$prop}-#{map.get($spacing_directions, "r")}: $length_x; }
    .#{$abbrev}b-#{$size} { #{$prop}-#{map.get($spacing_directions, "b")}: $length_y; }
    .#{$abbrev}l-#{$size} { #{$prop}-#{map.get($spacing_directions, "l")}: $length_x; }

    // По вертикали и горизонтали
    .#{$abbrev}-#{$size} { #{$prop}: $length_y $length_x; }

    // По вертикали
    .#{$abbrev}v-#{$size} {
      #{$prop}-#{map.get($spacing_directions, "t")}: $length_y;
      #{$prop}-#{map.get($spacing_directions, "b")}: $length_y;
    }

    // По горизонтали
    .#{$abbrev}h-#{$size} {
      #{$prop}-#{map.get($spacing_directions, "r")}: $length_x;
      #{$prop}-#{map.get($spacing_directions, "l")}: $length_x;
    }
  }
}

.p-none {
  padding: 0;
}

.m-none {
  margin: 0;
}
