@use "bootstrap-sass-modules/scss/mixins/breakpoints";
@use "bootstrap-sass-modules/scss/mixins/utilities";
@use "bootstrap-sass-modules/scss/vendor/rfs";
@use "./bcq-breakpoints";
@use "./bcq-utilities";

@mixin generate-containers($grid-breakpoints, $container-queries-breakpoints) {
  // Loop over each breakpoint
  @each $breakpoint in map-keys($grid-breakpoints) {
    // Generate container query if needed
    @include bcq-breakpoints.container-breakpoint-up(
      $breakpoint,
      $container-queries-breakpoints
    ) {
      $infix: breakpoints.breakpoint-infix($breakpoint, $grid-breakpoints);

      @for $i from 1 through 12 {
        .bcq#{$infix}-#{$i} {
          width: calc((100 / 12) * $i * 1cqw);
        }
      }

      // Loop over each utility property
      @each $key, $utility in bcq-utilities.$bcq-utilities {
        // The utility can be disabled with `false`, thus check if the utility is a map first
        // Only proceed if responsive container queries are enabled or if it's the base container query
        @if type-of($utility) ==
          "map" and
          (map-get($utility, responsive) or $infix == "")
        {
          @include utilities.generate-utility($utility, $infix);
        }
      }
    }
  }

  // RFS rescaling
  @media (min-width: rfs.$rfs-mq-value) {
    @each $breakpoint in map-keys($grid-breakpoints) {
      $infix: breakpoints.breakpoint-infix($breakpoint, $grid-breakpoints);

      @if map-get($grid-breakpoints, $breakpoint) < rfs.$rfs-breakpoint {
        // Loop over each utility property
        @each $key, $utility in bcq-utilities.$bcq-utilities {
          // The utility can be disabled with `false`, thus check if the utility is a map first
          // Only proceed if responsive media queries are enabled or if it's the base media query
          @if type-of($utility) ==
            "map" and
            map-get($utility, rfs) and
            (map-get($utility, responsive) or $infix == "")
          {
            @include generate-utility($utility, $infix, true);
          }
        }
      }
    }
  }
}
