//===========================
// Additional breakpoints
//
// Moved here from b-variables file so that we can load this partial
// after USWDS variables and before other partials.
//===========================
// @media single-keyword helpers

// This is an override to fix a variable-naming collision between USWDS and Foundation.
// Foundation declares these variables for legacy purposes, while USWDS uses them throughout
// the whole codebase. This is a problem because Foundation's and USWDS's corresponding variables are
// not the same units/types (Foundation's is defined in "em"'s), so USWDS is not able to compile.
// Based on the order of our imports, USWDS should override Foundation's declarations and everything should be fine.
// However, USWDS defines its variables using the "!default" flag, so Foundation's take precedence anyway.
// These next lines redeclare USWDS's variables without that flag, so that the override works as we would expect.

$grid-columns-small: 1 !default;
$grid-columns-medium: 6 !default;
$grid-columns-large: 12 !default;

// Breakpoint variables from USWDS 1.4.2
/* 
ADDED TO CSS-LIBRARY
file: tokens/breakpoints.json
issue: vets-design-system-documentation#2042
*/
$small-screen:  481px !default;

$medium-screen: 600px !default;

/* 
ADDED TO CSS-LIBRARY
file: tokens/breakpoints.json
issue: vets-design-system-documentation#2042
*/
$large-screen:  1201px !default;

$small: new-breakpoint(min-width $small-screen $grid-columns-small);
$medium: new-breakpoint(min-width $medium-screen $grid-columns-medium);
$large: new-breakpoint(min-width $large-screen $grid-columns-large);

/* 
ADDED TO CSS-LIBRARY
file: tokens/breakpoints.json
issue: vets-design-system-documentation#2334
*/
// We do a custom override here, setting our site's medium breakpoint to 768 instead of how USWDS defines it at 600.
$xsmall-screen:       320px; // QVGA display
$medium-large-screen: 768px;
$medium-screen:       $medium-large-screen;
$small-desktop-screen: 1008px;

$medium: new-breakpoint(min-width $medium-large-screen 6);


$breakpoints: (
  xsmall-screen:        $xsmall-screen,
  small-screen:         $small-screen,
  medium-screen:        $medium-screen,
  small-desktop-screen: $small-desktop-screen,
  large-screen:         $large-screen
);

// This is an override on Neat's media mixin to create media queries for both screen and print
// https://github.com/thoughtbot/neat/blob/v1.8.0/app/assets/stylesheets/grid/_media.scss

// Define default feature:
$default-feature: min-width;

@mixin media($query: $feature $value $columns, $total-columns: $grid-columns) {
  @if length($query) == 1 {
    @media screen and ($default-feature: nth($query, 1)), print and ($default-feature: nth($query, 1)) {
      $default-grid-columns: $grid-columns;
      $grid-columns: $total-columns !global;
      @content;
      $grid-columns: $default-grid-columns !global;
    }
  } @else {
    $loop-to: length($query);
    $media-query: "screen and ";
    $default-grid-columns: $grid-columns;
    $grid-columns: $total-columns !global;

    @if is-not(is-even(length($query))) {
      $grid-columns: nth($query, $loop-to) !global;
      $loop-to: $loop-to - 1;
    }

    $i: 1;
    @while $i <= $loop-to {
      $media-query: $media-query + "(" + nth($query, $i) + ": " + nth($query, $i + 1) + ") ";

      @if ($i + 1) != $loop-to {
        $media-query: $media-query + "and ";
      }

      $i: $i + 2;
    }

    // Append "print" at the end so that grid layouts always take effect on print.
    $media-query: $media-query + ", print";

    @media #{$media-query} {
      @content;
      $grid-columns: $default-grid-columns !global;
    }
  }
}
