/**
 * Bootstrap navbar
 */

@use "sass:math";

@use "../settings" as *;
@use "../tools" as *;
@use "hamburger";

@import "bootstrap/scss/navbar";

.navbar {
  --#{$prefix}hamburger-color: #{$dark};
}

.navbar-nav {
  --#{$prefix}nav-link-padding-x: #{$navbar-nav-link-padding-x};
  --#{$prefix}nav-link-padding-y: #{$navbar-nav-link-padding-y};
  border-left: $navbar-nav-item-border;
  .nav-item {
    border-right: $navbar-nav-item-border;
  }
}

.nav-link {
  white-space: nowrap;
  background-color: rgba(255, 255, 255, .03);
  &:hover,
  &:focus {
    text-decoration: underline;
  }
}

/* Modify the navbar-expand series to wrap nav-items */
.navbar-expand {
  $pcs: (
    xs: percentage(math.div(1, 2)),
    sm: percentage(math.div(1, 3)),
    md: percentage(math.div(1, 4)),
    lg: percentage(math.div(1, 5)),
    xl: percentage(math.div(1, 6)),
    xxl: percentage(math.div(1, 7)),
  );
  $lower: ();

  @each $breakpoint, $pc in $pcs {
    $lower: append($lower, $breakpoint);
    $infix: breakpoint-infix($breakpoint, $grid-breakpoints);

    // stylelint-disable-next-line scss/selector-no-union-class-name
    &#{$infix} {
      @include media-breakpoint-down($breakpoint) {
        .navbar-nav {
          flex-direction: row;
          flex-wrap: wrap;
          margin-bottom: space(1);
          border-top: $navbar-nav-item-border;
        }

        .nav-item {
          border-bottom: $navbar-nav-item-border;
        }

        .nav-link {
          white-space: normal;
        }
      }

      .nav-item {
        $key: nth(map_keys($grid-breakpoints), 1);
        @while $key and $key != $breakpoint {
          @include media-breakpoint-only($key) {
            width: map-get($pcs, $key);
          }

          $key: breakpoint-next($key, $grid-breakpoints);
        }
      }
    }
  }
}

.navbar-toggler {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: edgel-px-rem(50);
  min-height: edgel-px-rem(33);
  margin: space(1) 0 space(1) auto;

  &:hover {
    background-color: $navbar-dark-toggler-hover-bg;
    --#{$prefix}hamburger-color: #{$light};
  }
}

.navbar-toggler-icon.navbar-toggler-icon {
  @extend .hamburger;
}
[aria-expanded="true"] > .navbar-toggler-icon {
  @extend .hamburger-expanded;
}

.navbar-dark {
  --#{$prefix}hamburger-color: #{$white};

  .navbar-toggler:hover {
    background-color: $navbar-light-toggler-hover-bg;
    --#{$prefix}hamburger-color: #{$dark};
  }

  .nav-link:hover,
  .nav-link:focus,
  .nav-link.show,
  .nav-link.active {
    color: $navbar-dark-active-color;
    background: $navbar-dark-active-bg;
  }
}
