@use 'sass:math';

// Row
//
// Rows contain your columns.

@if $enable-grid-classes {
  .row {
    @include make-row();

    > * {
      @include make-col-ready();
    }
  }
}

@if $enable-cssgrid {
  .grid {
    display: grid;
    grid-template-rows: repeat(var(--#{$prefix}rows, 1), 1fr);
    grid-template-columns: repeat(var(--#{$prefix}columns, #{$grid-columns}), 1fr);
    gap: var(--#{$prefix}gap, #{$grid-gutter-width});

    @include make-cssgrid();
  }
}

// Columns
//
// Common styles for small and large grid columns

@if $enable-grid-classes {
  @include make-grid-columns();
}

@mixin make-variable-gutters($gutter-widths: $grid-gutter-widths, $breakpoints: $grid-breakpoints) {
  margin-right: math.div($grid-gutter-width, -2);
  margin-left: math.div($grid-gutter-width, -2);

  > .col,
  > [class*='col-'] {
    padding-right: ($grid-gutter-width * 0.5);
    padding-left: ($grid-gutter-width * 0.5);
  }

  @each $breakpoint, $grid-gutter-width in $gutter-widths {
    @include media-breakpoint-up($breakpoint, $breakpoints) {
      margin-right: math.div($grid-gutter-width, -2);
      margin-left: math.div($grid-gutter-width, -2);

      > .col,
      > [class*='col-'] {
        padding-right: ($grid-gutter-width * 0.5);
        padding-left: ($grid-gutter-width * 0.5);
      }
    }
  }
}

// Bootstrap Italia personalizza la griglia di Bootstrap impostando un gutter variabile se viene usato .variable-gutters
@if $enable-grid-classes {
  .row.variable-gutters {
    @include make-variable-gutters();
  }
}

.row {
  &.row-column-border {
    & > [class^='col-'] {
      padding-top: 2rem;
      padding-bottom: 2rem;
      border-top: 1px solid $border-color;

      &:first-child {
        border: none;
      }

      .navbar {
        padding: 0;

        .menu-wrapper {
          .nav-link {
            padding-right: 0;
          }
        }
      }
    }
  }

  &.row-column-menu-left {
    & > [class^='col-']:first-child {
      padding: 1rem 0;
    }
  }

  &.row-column-menu-right {
    & > [class^='col-']:last-child {
      padding: 1rem 0;
    }
  }

  &.row-card {
    background-color: $white;
  }

  // Desktop
  @include media-breakpoint-up(lg) {
    &.row-column-border {
      margin-top: 1rem;
      border-top: 1px solid $border-color;

      & > [class^='col-'] {
        padding: 3rem 3rem;
        border-top: none;
        border-left: 1px solid $border-color;

        &:first-child {
          border: none;
          padding-left: 0;
        }

        .navbar {
          padding: 8px 0;
          .menu-wrapper {
            padding: 0;
          }
        }
      }
    }

    &.row-column-menu-left {
      & > [class^='col-']:first-child {
        padding: 0;
      }
    }

    &.row-column-menu-right {
      & > [class^='col-']:last-child {
        padding: 0;
      }
    }
  }

  // Wrapper full width even if in a container
  &.row-full-width {
    max-width: calc(100vw);
    margin: 0 calc(-50vw + 50%);

    & > * {
      width: 100%;
      display: flex;
      flex-direction: column;

      img {
        width: 100%;
        height: 100%;
        max-height: 600px;
        object-fit: cover;
      }
    }
  }

  &.row-title {
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    // Tablet portrait
    @include media-breakpoint-up(sm) {
      flex-direction: row;
      align-items: flex-start;
    }
  }

  &.row-border {
    @for $i from 1 through 6 {
      h#{$i} {
        border-bottom: 1px solid $border-color;
        padding-bottom: 1rem;
        margin-bottom: 1rem;
      }
    }

    @include media-breakpoint-up(sm) {
      border-bottom: 1px solid $border-color;
      padding-bottom: 1rem;
      margin-bottom: 1rem;

      @for $i from 1 through 6 {
        h#{$i} {
          border: none;
          margin: 0;
          padding: 0;
        }
      }
    }
  }

  // Create row wrapper for sliding calendar
  &.row-calendar {
    display: block;
  }
}

// Sticky wrapper feature
.sticky-wrapper {
  &.is-sticky {
    position: fixed;

    &.navbar-wrapper {
      z-index: 1;
      left: 0;
      right: 0;
      width: auto;

      .navbar {
        padding-top: 1rem;
        padding-bottom: 1rem;
        // border-bottom: 1px solid $border-color;

        // &.it-bottom-navscroll {
        border-top: 1px solid $border-color;
        // border-bottom: none;
        // }
      }

      &.sticky-expanded {
        z-index: auto;
      }
    }

    // Desktop
    @include media-breakpoint-up(lg) {
      &.navbar-wrapper {
        z-index: auto;
        left: auto;
        right: auto;
        width: unset;

        .navbar {
          border: none;
          background-color: transparent;
          padding: 0;

          .menu-wrapper {
            padding: 0;

            .nav-link {
              padding-right: 0;
            }
          }

          &.it-bottom-navscroll {
            border: none;
          }
        }

        &.at-bottom {
          position: absolute;
          top: auto !important;
          bottom: 0;
        }
      }
    }
  }

  &.navbar-wrapper {
    .navbar {
      // reset position when in sticky mode
      &.it-top-navscroll,
      &.it-bottom-navscroll {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        bottom: auto;
      }
    }
  }
}
