@import "./../variables";
$spacing: (
  '0': 0,
  '1': 1rem,
  '2': 2rem,
  '3': 3rem,
  '4': 4rem,
  '5': 5rem,
  '6': 6rem,
  '7': 7rem,
  '8': 8rem,
  '9': 9rem,
  '10': 10rem,
  '12': 12rem,
  '16': 16rem,
  '20': 20rem,
  '24': 24rem,
);

// generates margin and padding utilities classes
//@each $prop, $abbrev in (margin: m, padding: p) {
//  @each $size, $length in $spacing {
//    .#{$abbrev}-#{$size} { #{$prop}: $length !important; }
//    .#{$abbrev}t-#{$size}, .#{$abbrev}y-#{$size} {
//      #{$prop}-top: $length !important;
//    }
//    .#{$abbrev}r-#{$size}, .#{$abbrev}x-#{$size} {
//      #{$prop}-right: $length !important;
//    }
//    .#{$abbrev}b-#{$size}, .#{$abbrev}y-#{$size} {
//      #{$prop}-bottom: $length !important;
//    }
//    .#{$abbrev}l-#{$size}, .#{$abbrev}x-#{$size} {
//      #{$prop}-left: $length !important;
//    }
//  }
//}

// We generates now the negative margins only because negative padding doesn't exist
// Negative margins (e.g., where `.mb-n1` is negative version of `.mb-1`)

//@each $size, $length in $spacing {
//  @if $size != 0 {
//    .m-n#{$size} { margin: -$length !important; }
//    .mt-n#{$size}, .my-n#{$size} {
//      margin-top: -$length !important;
//    }
//    .mr-n#{$size}, .mx-n#{$size} {
//      margin-right: -$length !important;
//    }
//    .mb-n#{$size}, .my-n#{$size} {
//      margin-bottom: -$length !important;
//    }
//    .ml-n#{$size}, .mx-n#{$size} {
//      margin-left: -$length !important;
//    }
//  }
//}

// Some special margin utils
//.m-auto { margin: auto !important; }
//.mt-auto, .my-auto {
//  margin-top: auto !important;
//}
//.mr-auto, .mx-auto {
//  margin-right: auto !important;
//}
//.mb-auto, .my-auto {
//  margin-bottom: auto !important;
//}
//.ml-auto, .mx-auto {
//  margin-left: auto !important;
//}

// Minimum breakpoint width. Null for the smallest (first) breakpoint.
//
//    >> breakpoint-min(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
//    576px
@function breakpoint-min($name, $bp: $breakpoints) {
  $min: map-get($bp, $name);
  @return if($min != 0, $min, null);
}

@mixin media-breakpoint-up($name, $bp: $breakpoints) {
  $min: breakpoint-min($name, $bp);
  @if $min {
    @media (min-width: $min) {
      @content;
    }
  } @else {
    @content;
  }
}

// Returns a blank string if smallest breakpoint, otherwise returns the name with a dash in front.
// Useful for making responsive utilities.
//
//    >> breakpoint-infix(xs, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
//    ""  (Returns a blank string)
//    >> breakpoint-infix(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
//    "-sm"
@function breakpoint-infix($name, $bp: $breakpoints) {
  @return if(breakpoint-min($name, $bp) == null, "", "-#{$name}");
}

@each $bp in map-keys($breakpoints) {
  @include media-breakpoint-up($bp) {
    $infix: breakpoint-infix($bp, $breakpoints);

    @each $prop, $abbrev in (margin: m, padding: p) {
      @each $size, $length in $spacing {
        .#{$abbrev}#{$infix}-#{$size} { #{$prop}: $length !important; }
        .#{$abbrev}t#{$infix}-#{$size},
        .#{$abbrev}y#{$infix}-#{$size} {
          #{$prop}-top: $length !important;
        }
        .#{$abbrev}r#{$infix}-#{$size},
        .#{$abbrev}x#{$infix}-#{$size} {
          #{$prop}-right: $length !important;
        }

        .#{$abbrev}b#{$infix}-#{$size},
        .#{$abbrev}y#{$infix}-#{$size} {
          #{$prop}-bottom: $length !important;
        }
        .#{$abbrev}l#{$infix}-#{$size},
        .#{$abbrev}x#{$infix}-#{$size} {
          #{$prop}-left: $length !important;
        }
      }
    }

    // Negative margins (e.g., where `.mb-n1` is negative version of `.mb-1`)
    @each $size, $length in $spacing {
      @if $size != 0 {
        .m#{$infix}-n#{$size} { margin: -$length !important; }
        .mt#{$infix}-n#{$size},
        .my#{$infix}-n#{$size} {
          margin-top: -$length !important;
        }
        .mr#{$infix}-n#{$size},
        .mx#{$infix}-n#{$size} {
          margin-right: -$length !important;
        }
        .mb#{$infix}-n#{$size},
        .my#{$infix}-n#{$size} {
          margin-bottom: -$length !important;
        }
        .ml#{$infix}-n#{$size},
        .mx#{$infix}-n#{$size} {
          margin-left: -$length !important;
        }
      }
    }

    // Some special margin utils
    .m#{$infix}-auto { margin: auto !important; }
    .mt#{$infix}-auto,
    .my#{$infix}-auto {
      margin-top: auto !important;
    }
    .mr#{$infix}-auto,
    .mx#{$infix}-auto {
      margin-right: auto !important;
    }
    .mb#{$infix}-auto,
    .my#{$infix}-auto {
      margin-bottom: auto !important;
    }
    .ml#{$infix}-auto,
    .mx#{$infix}-auto {
      margin-left: auto !important;
    }
  }
}

