
@use "variables" as _variables;
@use "sass:map";
@use "sass:math";

// --------------------------------------------------------------------------
//  Fluid font and fluid width functions
// --------------------------------------------------------------------------

@function get-breakpoint($bp) {
   @if type-of($bp) == "string" {
      // if breakpoint string
      @if (map.has-key(_variables.$s-breakpoints, #{$bp})) {
         $breakpoint: map.get(_variables.$s-breakpoints, $bp) !global;
      } @else {
         @error "The s-breakpoints map do not have the #{$bp} key. Use existing breakpoint key or pixels.";
      }
   } @else {
      // else if pixel
      $breakpoint: $bp !global;
   }
   @return $breakpoint;
}


@function strip-unit($value) {
   @return math.div($value, $value * 0 + 1);
}


// --------------------------------------------------------------------------
//  Media queries functions
// --------------------------------------------------------------------------

// Returns a blank string if smallest breakpoint, otherwise returns the name with a dash in front.
// Useful for making responsive utilities.
@function breakpoint-prefix($name, $breakpoints: _variables.$s-breakpoints) {
   $separator: "\\#{_variables.$s-responsive-prefix-separator}";
   @return if(breakpoint-min($name, $breakpoints) == null, "", "#{$name + $separator}");
}


@function breakpoint-next($name, $breakpoints: _variables.$s-breakpoints, $breakpoint-names: map-keys(_variables.$s-breakpoints)) {
   $n: index($breakpoint-names, $name);
   @return if($n != null and $n < length($breakpoint-names), nth($breakpoint-names, $n + 1), null);
}

// Minimum breakpoint width. Null for the smallest (first) breakpoint.
@function breakpoint-min($name, $breakpoints: _variables.$s-breakpoints) {
   $min: map-get($breakpoints, $name);
   @return if($min != 0, $min, null);
}

@function breakpoint-max($name, $breakpoints: _variables.$s-breakpoints) {
   $next: breakpoint-next($name, $breakpoints);
   @return if($next, breakpoint-min($next, $breakpoints) - 0.02, null);
}
