/*
 * Copyright (c) 2016-2025 Broadcom. All Rights Reserved.
 * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
 * This software is released under MIT license.
 * The full license information can be found in LICENSE in the root directory of this project.
 */
@use 'sass:list';
@use 'sass:map';
@use '../../../utils/variables/variables.layout';

@function clr-breakpoint-next(
  $name,
  $breakpoints: variables.$clr-grid-breakpoints,
  $breakpoint-names: map.keys($breakpoints)
) {
  $n: list.index($breakpoint-names, $name);
  @if not $n {
    @error 'breakpoint `#{$name}` not found in `#{$breakpoints}`';
  }
  @return if($n < list.length($breakpoint-names), list.nth($breakpoint-names, $n + 1), null);
}

@function clr-breakpoint-min($name, $breakpoints: variables.$clr-grid-breakpoints) {
  $min: map.get($breakpoints, $name);
  @return if($min != 0, $min, null);
}

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

@function clr-breakpoint-infix($name, $breakpoints: variables.$clr-grid-breakpoints) {
  @return if(clr-breakpoint-min($name, $breakpoints) == null, '', '-#{$name}');
}

// Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
// Makes the @content apply to the given breakpoint and wider.
@mixin clr-media-breakpoint-up($name, $breakpoints: variables.$clr-grid-breakpoints) {
  $min: clr-breakpoint-min($name, $breakpoints);
  @if $min {
    @media (min-width: $min) {
      @content;
    }
  } @else {
    @content;
  }
}

// Media of at most the maximum breakpoint width. No query for the largest breakpoint.
// Makes the @content apply to the given breakpoint and narrower.
@mixin clr-media-breakpoint-down($name, $breakpoints: variables.$clr-grid-breakpoints) {
  $max: clr-breakpoint-max($name, $breakpoints);
  @if $max {
    @media (max-width: $max) {
      @content;
    }
  } @else {
    @content;
  }
}
