// Animate drop appearance
// @link https://github.com/twbs/bootstrap/issues/33185
@keyframes dropdownAnimation {
  from {
    opacity: 0;
    margin-top: calc(var(--bs-dropdown-spacer, 0.125) * var(--dropdown-animation-factor));
  }

  to {
    opacity: 1;
    margin-top: calc(var(--bs-dropdown-spacer, 0.125) * var(--dropdown-animation-end-factor));
  }
}

@keyframes dropupAnimation {
  from {
    opacity: 0;
    margin-bottom: calc(var(--bs-dropdown-spacer, 0.125) * var(--dropdown-animation-factor));
  }

  to {
    opacity: 1;
    margin-bottom: calc(var(--bs-dropdown-spacer, 0.125) * var(--dropdown-animation-end-factor));
  }
}

@media (prefers-reduced-motion: no-preference) {

  .dropdown,
  .dropup {
    .dropdown-menu.show {
      --dropdown-animation-factor: -2;
      --dropdown-animation-end-factor: 1;
      animation-name: dropdownAnimation;
      animation-duration: 0.25s;
      animation-iteration-count: 1;
      animation-timing-function: ease-out;
      animation-fill-mode: forwards;
    }

    // With popper, don't have any margin at all
    .dropdown-menu[data-popper-placement] {
      --dropdown-animation-end-factor: 0;
    }
  }

  .dropup {
    .dropdown-menu.show {
      --dropdown-animation-factor: 2;
      --dropdown-animation-end-factor: -1;
    }

    // With popper, don't have any margin at all
    .dropdown-menu[data-popper-placement].show {
      --dropdown-animation-factor: -2;
      --dropdown-animation-end-factor: 0;
      animation-name: dropupAnimation;
    }
  }
}

// Fixed positioning for simple js
// @link https://mtsknn.fi/blog/breaking-css-position-fixed/
.dropdown-fixed {
  position: fixed;
}

// Always enable shadow in header
header .dropdown-menu {
  box-shadow: $dropdown-box-shadow;
}

// Restyle the caret icon
.dropdown,
.dropup {
  .dropdown-toggle:after {
    border: solid;
    border-width: 0 2px 2px 0;
    margin-left: 8px;
    display: inline-block;
    padding: 2px;
    transform: rotate(45deg);
  }
}

.dropup {
  .dropdown-toggle:after {
    vertical-align: middle;
    transform: rotate(225deg);
  }
}

// Badges alignement
.dropdown-item {
  .badge {
    vertical-align: text-top;
  }
}

// Allow large dropdown menus
.dropdown-menu-lg {
  min-width: $dropdown-min-width * 2;
}

// List group in drops
.dropdown .list-group .list-group-item {
  border-width: 0;
  border-bottom-width: 1px;
  margin-bottom: 0;

  &:first-child {
    border-top-width: 1px;
  }

  &:first-child,
  &:last-child {
    border-radius: 0;
  }

  &:hover {
    background: $gray-100;
  }

  l-i {
    --size: 24px;
  }
}

// Headers & footers
.dropdown-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: $dropdown-header-padding;
  margin-bottom: 0; // for headers
  color: $dropdown-header-color;
  white-space: nowrap;

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    font-weight: $font-weight-bold;
    margin-bottom: 0; // for headers
  }
}

.dropdown-menu-footer {
  display: block;
  padding: $dropdown-header-padding;
  @include font-size($font-size-sm);
  color: $dropdown-header-color;
  white-space: nowrap; // as with > li > a
  text-align: center;
  font-weight: $font-weight-bold;

  &:hover {
    background-color: $list-group-hover-bg;
    color: $dropdown-header-color;
    text-decoration: none;
  }
}

.dropdown-alias {
  cursor: pointer;
}