@use 'sass:map'
@use 'sass:math'
@use '../../styles/settings'
@use '../../styles/tools'

@mixin make-container($padding-x: settings.$container-padding-x)
  width: 100%
  padding: $padding-x
  margin-right: auto
  margin-left: auto

// For each breakpoint, define the maximum width of the container in a media query
@mixin make-container-max-widths($max-widths: settings.$container-max-widths, $breakpoints: settings.$grid-breakpoints)
  @each $breakpoint, $container-max-width in $max-widths
    @include tools.media-breakpoint-up($breakpoint, $breakpoints)
      max-width: $container-max-width

@mixin make-row($gutter: settings.$grid-gutter)
  display: flex
  flex-wrap: wrap
  flex: 1 1 auto
  margin: -$gutter * .5

@mixin make-col-ready($gutter: settings.$grid-gutter)
  // Prevent columns from becoming too narrow when at smaller grid tiers by
  // always setting `width: 100%;`. This works because we use `flex` values
  // later on to override this initial width.
  width: 100%
  padding: $gutter * .5

@mixin make-col($size, $columns: settings.$grid-columns)
  flex: 0 0 math.percentage(math.div($size, $columns))
  // Add a `max-width` to ensure content within each column does not blow out
  // the width of the column. Applies to IE10+ and Firefox. Chrome and Safari
  // do not appear to require this.
  max-width: math.percentage(math.div($size, $columns))

@mixin make-col-offset($size, $columns: settings.$grid-columns)
  $num: math.div($size, $columns)
  margin-inline-start: if($num == 0, 0, math.percentage($num))

@mixin make-grid-columns($columns: settings.$grid-columns, $gutter: settings.$grid-gutter, $breakpoints: settings.$grid-breakpoints)
  // Common properties for all breakpoints
  %grid-column
    width: 100%
    padding: $gutter * .5
  @each $breakpoint in map.keys($breakpoints)
    $infix: tools.breakpoint-infix($breakpoint, $breakpoints)
    // Allow columns to stretch full width below their breakpoints
    @for $i from 1 through $columns
      .v-col#{$infix}-#{$i}
        @extend %grid-column
    .v-col#{$infix},
    .v-col#{$infix}-auto
      @extend %grid-column
    @include tools.media-breakpoint-up($breakpoint, $breakpoints)
      // Provide basic `.col-{bp}` classes for equal-width flexbox columns
      .v-col#{$infix}
        flex-basis: 0
        flex-grow: 1
        max-width: 100%
      .v-col#{$infix}-auto
        flex: 0 0 auto
        width: auto
        max-width: 100% // Reset earlier grid tiers
      @for $i from 1 through $columns
        .v-col#{$infix}-#{$i}
          @include make-col($i, $columns)
      // `$columns - 1` because offsetting by the width of an entire row isn't possible
      @for $i from 0 through $columns - 1
        @if not ($infix == "" and $i == 0)
          // Avoid emitting useless .offset-0
          .offset#{$infix}-#{$i}
            @include make-col-offset($i, $columns)
