/* See full documentation at:
** https://glennmccomb.com/articles/useful-sass-scss-media-query-mixins-for-bootstrap/
*/

//
//  MEDIA QUERIES
//––––––––––––––––––––––––––––––––––––––––––––––––––

// A map of breakpoints.
$breakpoints-up: (
  xs: 0,
  sm: 600px,
  md: 960px,
  lg: 1280px,
  xl: 1920px
);

$breakpoints-down: (
  xs: 600px,
  sm: 960px,
  md: 1280px,
  lg: 1920px
);


//
//  RESPOND ABOVE
//––––––––––––––––––––––––––––––––––––––––––––––––––

// @include respond-above(sm) {}
@mixin breakpoints-up($breakpoint) {

  // If the breakpoint exists in the map.
  @if map-has-key($breakpoints-up, $breakpoint) {

    // Get the breakpoint value.
    $breakpoint-value: map-get($breakpoints-up, $breakpoint);

    // Write the media query.
    @media (min-width: $breakpoint-value) {
      @content;
    }
  
  // If the breakpoint doesn't exist in the map.
  } @else {

    // Log a warning.
    @warn 'Invalid breakpoint: #{$breakpoint}.';
  }
}


//
//  RESPOND BELOW
//––––––––––––––––––––––––––––––––––––––––––––––––––

// @include respond-below(sm) {}
@mixin breakpoints-down($breakpoint) {

  // If the breakpoint exists in the map.
  @if map-has-key($breakpoints-down, $breakpoint) {

    // Get the breakpoint value.
    $breakpoint-value: map-get($breakpoints-down, $breakpoint);

    // Write the media query.
    @media (max-width: ($breakpoint-value - 1)) {
      @content;
    }
  
  // If the breakpoint doesn't exist in the map.
  } @else {

    // Log a warning.
    @warn 'Invalid breakpoint: #{$breakpoint}.';
  }
}


//
//  RESPOND BETWEEN
//––––––––––––––––––––––––––––––––––––––––––––––––––

// @include respond-between(sm, md) {}
@mixin breakpoints-between($lower, $upper) {

  // If both the lower and upper breakpoints exist in the map.
  @if map-has-key($breakpoints-up, $lower) and map-has-key($breakpoints-up, $upper) {

    // Get the lower and upper breakpoints.
    $lower-breakpoint: map-get($breakpoints-up, $lower);
    $upper-breakpoint: map-get($breakpoints-up, $upper);

    // Write the media query.
    @media (min-width: $lower-breakpoint) and (max-width: ($upper-breakpoint - 1)) {
      @content;
    }
  
  // If one or both of the breakpoints don't exist.
  } @else {

    // If lower breakpoint is invalid.
    @if (map-has-key($breakpoints, $lower) == false) {

      // Log a warning.
      @warn 'Your lower breakpoint was invalid: #{$lower}.';
    }

    // If upper breakpoint is invalid.
    @if (map-has-key($breakpoints-up, $upper) == false) {

      // Log a warning.
      @warn 'Your upper breakpoint was invalid: #{$upper}.';
    }
  }
}