////////////////////////
// Default the Breakpoints variable
////////////////////////
$breakpoints: () !default;

////////////////////////
// Respond-to API Mixin
////////////////////////

@mixin respond-to($context, $no-query: false) {
  @if type-of($breakpoints) != 'list' {
    // Just in case someone writes gibberish to the $breakpoints variable.
    @warn "Your breakpoints aren't a list! See https://github.com/snugug/respond-to#api if you'd like a reminder on how to use Respond-to";
  }
  @if length($breakpoints)  != 0 {
    // If there's only one breakpoint, SASS will think it's a space separated list :P
    @if length($breakpoints) == 2 and type-of(nth($breakpoints, 1)) != 'list' {
      $breakpoints: append((), (nth($breakpoints, 1), nth($breakpoints, 2)));
    }
    @each $bkpt in $breakpoints {
      @if $context == nth($bkpt, 1) {
        $length: length($bkpt);
        $mq: false !default;

        @for $i from 2 through $length {
          // If it's the first item, override $mq
          @if $i == 2 {
            $mq: nth($bkpt, $i);
          }
          // Else, join $mq
          @else {
            $mq: join($mq, nth($bkpt, $i));
          }
        }

        @include breakpoint($mq, $no-query) {
          @content;
        }
      }
    }
  }
  @else {
    @warn "You haven't created any breakpoints yet! Make some already! See https://github.com/snugug/respond-to#api if you'd like a reminder on how to use Respond-to";
    @content;
  }
}

//////////////////////////////
// Add Breakpoint to Breakpoints
//////////////////////////////
@function add-breakpoint($name, $bkpt) {
  $bkpt: $name $bkpt;
  $output: append($breakpoints, $bkpt, 'comma');
  @return $output;
}