@use "sass:math";

.navbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  min-height: $toolbar-height;
  padding: $toolbar-padding-y $toolbar-padding-x;
  position: relative;

  .navbar-brand {
    height: $toolbar-element-height;
  }

  // Vertically align some elements normally placed in `.navbar`

  .form-control {
    @include border-radius($toolbar-element-border-radius);
    @include transition-standard(opacity);

    border: 0;
    opacity: $toolbar-element-opacity;
    padding: (($textfield-height - $textfield-font-size * $textfield-line-height) * 0.5) $toolbar-inner-spacer-x;

    @include focus-hover {
      box-shadow: none;
      opacity: 1;
    }
  }

  .form-control-lg {
    padding-top: (($textfield-height-lg - $textfield-font-size-lg * $textfield-line-height-lg) * 0.5);
    padding-bottom: (($textfield-height-lg - $textfield-font-size-lg * $textfield-line-height-lg) * 0.5);
  }

  .form-control-sm {
    padding-top: (($textfield-height-sm - $textfield-font-size-sm * $textfield-line-height-sm) * 0.5);
    padding-bottom: (($textfield-height-sm - $textfield-font-size-sm * $textfield-line-height-sm) * 0.5);
  }

  .input-group {
    @include border-radius($toolbar-element-border-radius);
    @include transition-standard(opacity);

    opacity: $toolbar-element-opacity;

    @include focus-hover {
      opacity: 1;
    }

    .form-control {
      background-color: transparent;
      opacity: 1;

      &:not(:first-child) {
        padding-left: 0;
      }

      &:not(:last-child) {
        padding-right: 0;
      }
    }

    .input-group-append {
      margin-left: 0;
      min-width: 0;
    }

    .input-group-prepend {
      margin-right: 0;
      min-width: 0;
    }

    .input-group-text {
      margin-right: $toolbar-inner-spacer-x;
      margin-left: $toolbar-inner-spacer-x;
    }
  }

  .input-group-lg > .form-control {
    padding-top: (($textfield-height-lg - $textfield-font-size-lg * $textfield-line-height-lg) * 0.5);
    padding-bottom: (($textfield-height-lg - $textfield-font-size-lg * $textfield-line-height-lg) * 0.5);
  }

  .input-group-sm > .form-control {
    padding-top: (($textfield-height-sm - $textfield-font-size-sm * $textfield-line-height-sm) * 0.5);
    padding-bottom: (($textfield-height-sm - $textfield-font-size-sm * $textfield-line-height-sm) * 0.5);
  }

  .nav-tabs {
    margin-top: ($toolbar-padding-y * -1);
    margin-bottom: ($toolbar-padding-y * -1);

    .nav-link {
      min-height: $toolbar-height;
      padding-top: (($toolbar-height - $nav-tab-font-size * $nav-tab-line-height) * 0.5);
      padding-bottom: (($toolbar-height - $nav-tab-font-size * $nav-tab-line-height) * 0.5);
    }
  }

  > .container {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
  }
}

.navbar-fixed-bottom,
.navbar-fixed-top {
  box-shadow: map-get($toolbar-elevation-shadow, shadow);
  position: fixed;
  right: 0;
  left: 0;
  z-index: map-get($toolbar-elevation-shadow, elevation);
}

.navbar-fixed-bottom {
  bottom: 0;
}

.navbar-fixed-top {
  top: 0;
}

.navbar-full {
  box-shadow: map-get($toolbar-elevation-shadow, shadow);
  z-index: map-get($toolbar-elevation-shadow, elevation);
}

.navbar-sticky-top {
  @supports (position: sticky) {
    box-shadow: map-get($toolbar-elevation-shadow, shadow);
    position: sticky;
    top: 0;
    z-index: map-get($toolbar-elevation-shadow, elevation);
  }
}

.toolbar-waterfall {
  @include transition-standard(background-color, box-shadow);

  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: map-get($toolbar-elevation-shadow, elevation);

  &.waterfall {
    box-shadow: map-get($toolbar-elevation-shadow, shadow);
    position: fixed;
  }
}

// Misc

.navbar-brand {
  @include typography-title;

  align-items: center;
  display: block;
  position: relative;
  white-space: nowrap;

  @include active-focus-hover {
    text-decoration: none;
  }

  &::before {
    @include transition-standard(opacity);

    content: '';
    display: block;
    opacity: 0;
    position: absolute;
    top: 0;
    right: math.div($toolbar-inner-spacer-x, -2);
    bottom: 0;
    left: math.div($toolbar-inner-spacer-x, -2);
  }

  &:focus {
    outline: 0;

    &::before {
      opacity: 1;
    }
  }

  &:not(:first-child) {
    margin-left: $toolbar-inner-spacer-x;
  }

  &:not(:last-child) {
    margin-right: $toolbar-inner-spacer-x;
  }
}

.navbar-text {
  align-items: center;
  display: inline-flex;
  flex-wrap: wrap;
  height: $toolbar-element-height;
}

// Nav

.navbar-nav {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  margin-bottom: 0;
  padding-left: 0;

  .nav-link {
    @include border-radius($toolbar-element-border-radius);
    @include transition-standard(background-color, opacity);

    font-size: $toolbar-link-font-size;
    height: $toolbar-link-height;
    line-height: $toolbar-link-line-height;
    opacity: $toolbar-element-opacity;
    padding: $toolbar-link-padding-y $toolbar-link-padding-x;

    @include active-focus-hover {
      opacity: 1;
    }

    &.active,
    &.disabled {
      opacity: 1;
    }

    &.disabled {
      background-color: transparent;
    }

    &:focus {
      outline: 0;
    }
  }

  .active > .nav-link,
  .show > .nav-link {
    opacity: 1;
  }
}

// Toggleable

.navbar-collapse {
  align-items: center;
  flex-basis: 100%;
  flex-grow: 1;
}

.navbar-expand {
  @each $breakpoint in map-keys($grid-breakpoints) {
    $next: breakpoint-next($breakpoint);
    $infix: breakpoint-infix($next);

    &#{$infix} {
      @include media-breakpoint-down($breakpoint) {
        > .container,
        > .container-fluid {
          padding-right: 0;
          padding-left: 0;
        }
      }

      @include media-breakpoint-up($next) {
        flex-flow: row nowrap;
        justify-content: flex-start;

        .navbar-collapse {
          display: flex !important; // stylelint-disable-line declaration-no-important
          flex-basis: auto;
        }

        .navbar-toggler {
          display: none;

          &:first-child + .navbar-brand {
            margin-left: 0;
          }
        }

        > .container,
        > .container-fluid {
          flex-wrap: nowrap;
        }
      }
    }
  }
}

.navbar-toggler {
  align-items: center;
  background-color: transparent;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  flex-shrink: 0;
  height: $toolbar-element-height;
  justify-content: center;
  line-height: 1;
  padding: 0;
  position: relative;
  width: $toolbar-element-height;

  @include active-focus-hover {
    text-decoration: none;

    &::before {
      opacity: 1;
    }
  }

  &::before {
    @include transition-standard(opacity);

    border-radius: 50%;
    content: '';
    display: block;
    opacity: 0;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }

  &:focus {
    outline: 0;
  }

  &:not(:disabled):not(.disabled) {
    cursor: pointer;
  }
}

.navbar-toggler-icon {
  display: block;
  @include setup-material-icons-bg();
}
