@import 'settings';

//
// Dropdown menus
// --------------------------------------------------

// Dropdown arrow/caret
.caret {
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 2px;
  vertical-align: middle;
  border-top: $caret-width-large dashed;
  border-top: $caret-width-large solid \9
; // IE8
  border-right: $caret-width-large solid transparent;
  border-left: $caret-width-large solid transparent;
}

// The dropdown wrapper (div)
.dropup,
.dropdown {
  position: relative;

  @include for-phone-only {
    &.has-alert > a:before {
      content: '';
      position: absolute;
      top: 11px;
      right: 7px;
      width: 12px;
      height: 12px;
      background-color: $gray-light;
      border-radius: 50%;
    }
  }

  // There are now items that don't have their own top level icon so these
  // should show notifications in the user menu also on desktop.
  &.has-alert.has-alert--desktop > a:before {
    content: '';
    position: absolute;
    top: 11px;
    right: 7px;
    width: 12px;
    height: 12px;
    background-color: $gray-light;
    border-radius: 50%;
  }
}

// The dropdown menu (ul)
.dropdown-menu {
  position: absolute;
  top: 0;
  left: 0;
  z-index: $zindex-dropdown;
  display: none; // none by default, but block on "open" of the menu
  float: left;
  min-width: 185px;
  max-width: 500px;
  padding: 5px 0;
  margin: 2px 0 0; // override default ul
  list-style: none;
  font-size: 0.875rem;
  text-align: left; // Ensures proper alignment if parent has it changed (e.g., modal footer)
  background-color: $dropdown-bg;
  @include z-depth-4;
  background-clip: padding-box;

  @include for-tablet-landscape-up {
    top: 100%;
  }

  [dir='rtl'] & {
    text-align: right; // Ensures proper alignment if parent has it changed (e.g., modal footer)
  }

  // Aligns the dropdown menu to right
  //
  // Deprecated as of 3.1.0 in favor of `.dropdown-menu-[dir]`
  &.pull-right {
    right: 0;
    left: auto;
  }

  // Dividers (basically an hr) within the dropdown
  .divider {
    @include nav-divider($dropdown-divider-bg);
    &.mobile {
      @include for-tablet-portrait-up {
        display: none;
      }
    }
  }
  li {
    &.mobile {
      @include for-tablet-portrait-up {
        display: none;
      }
    }
    .badge {
      margin: 0;
    }
  }

  // Links within the dropdown menu

  li {
    > a,
    > span {
      padding: 8px 10px;
      display: block;
      clear: both;
      line-height: $line-height-base;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      color: $gray;

      &:hover {
        background-color: $gray-lightest;
      }

      @include for-tablet-portrait-up {
        padding: 4px 10px 4px 15px;
      }
    }

  }

}

// DropDown Menu styles inside the table.
.table-responsive {
  tr {
    td:last-child {
      .dropdown-menu {
        left: auto;
        right: 0;
      }
    }
  }
}

// Dropdown menu with the popover behavior.
.dropdown-menu.dropdown-popover {
  max-width: 187px;

  li {
    a {
      font-size: 1rem;
      line-height: 24px;
      font-weight: 500;
    }
  }
}

// Hover/Focus state
.dropdown-menu > li > a {
  &:hover,
  &:focus {
    text-decoration: none;
  }
}

// Active state
.dropdown-menu > .active > a {
  &,
  &:hover,
  &:focus {
    text-decoration: none;
    outline: 0;
  }
}

// Disabled state
//
// Gray out text and ensure the hover/focus state remains gray

.dropdown-menu > .disabled {
  > a,
  > span {
    // Nuke hover/focus effects
    &:hover,
    &:focus {
      text-decoration: none;
      background-color: transparent;
      background-image: none; // Remove CSS gradient
      cursor: $cursor-disabled;
    }
  }
}

// Open state for the dropdown
.open {
  // Show the menu
  > .dropdown-menu {
    display: block;
  }
}

// Menu positioning
//
// Add extra class to `.dropdown-menu` to flip the alignment of the dropdown
// menu with the parent.
.dropdown-menu-right {
  left: auto; // Reset the default from `.dropdown-menu`
  right: 0;

  [dir='rtl'] & {
    right: auto;
    left: 0;
  }
}

// With v3, we enabled auto-flipping if you have a dropdown within a right
// aligned nav component. To enable the undoing of that, we provide an override
// to restore the default dropdown menu alignment.
//
// This is only for left-aligning a dropdown menu within a `.navbar-right` or
// `.pull-right` nav component.
.dropdown-menu-left {
  left: 0;
  right: auto;
}

// Dropdown section headers
.dropdown-header {
  display: block;
  padding: 3px 20px;
  font-size: $font-size-small;
  line-height: $line-height-base;
  color: $dropdown-header-color;
  white-space: nowrap; // as with > li > a
}

// Backdrop to catch body clicks on mobile, etc.
.dropdown-backdrop {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  z-index: ($zindex-dropdown - 10);
}

// Right aligned dropdowns
.pull-right > .dropdown-menu {
  right: 0;
  left: auto;

  [dir='rtl'] & {
    right: auto;
    left: 0;
  }
}

// Allow for dropdowns to go bottom up (aka, dropup-menu)
//
// Just add .dropup after the standard .dropdown class and you're set, bro.
// TODO: abstract this so that the navbar fixed styles are not placed here?

.dropup,
.navbar-fixed-bottom .dropdown {
  // Reverse the caret
  .caret {
    border-top: 0;
    border-bottom: $caret-width-base dashed;
    border-bottom: $caret-width-base solid \9
  ; // IE8
    content: "";
  }
  // Different positioning for bottom up menu
  .dropdown-menu {
    top: auto;
    bottom: 100%;
    margin-bottom: 2px;
  }
}

// Component alignment
//
// Reiterate per navbar.less and the modified component alignment there.

@include for-tablet-landscape-up {
  .navbar-right {
    .dropdown-menu {
      right: 0;
      left: auto;

      [dir='rtl'] & {
        right: auto;
        left: 0;
      }
    }
    // Necessary for overrides of the default right aligned menu.
    // Will remove come v4 in all likelihood.
    .dropdown-menu-left {
      left: 0;
      right: auto;
    }
  }
}

.dropdown-menu {

  .divider {
    margin: 6px 0;
  }

  .media {
    min-width: 250px;
  }

  .media-left {
    flex-shrink: 0;

    @include for-tablet-portrait-up {
      padding-right: 8px;
    }

    img {
      vertical-align: top;
    }

  }

  .media-body {
    white-space: normal;

    a {
      white-space: nowrap; // prevent links from randomly breaking onto new lines
    }

  }

}

.dropdown-menu--visibility {
  min-width: 240px;
  left: auto;
  right: -70px;
  padding: 0;

  @include for-tablet-portrait-up {
    right: 0;
  }
}

.dropdown {

  &.profile .header-nav-current-user {
    padding: 4px 10px 0;
  }

}

.dropdown-header {
  padding: 7px 20px;
  background: $dropdown-header-bg;
}

.scrollable-menu {

  // heights of navbar-fixed, dropdown padding, dropdown-header (2x), dividers (2x) not to be subtracted to get accurate height
  height: calc(100vh - 156px);

  overflow-x: hidden;
  list-style-type: none;
  padding: 0;
  margin: 0;

  // When the screen is taller, the dropdown can be taller
  @include for-tablet-portrait-up {
    height: auto;
    max-height: 450px;
  }

  li {
    margin: 2px 0;
  }

  p {
    margin-bottom: 0;
  }
}

// Dropdown without js.
html:not(.js) {

  .dropdown:focus .dropdown-menu,
  .dropdown:hover .dropdown-menu,
  .comment__actions:hover .dropdown-menu,
  .comment__actions:hover .dropdown-menu,
  .dropdown-menu:hover {
    display: block;
  }

  .dropdown {
    cursor: pointer;

    &:focus {
      outline: none;
    }

    .dropdown-toggle {
      pointer-events: none;
      z-index: -1;
    }
  }
}

/* IE11 */
@media (min-width: 600px) and (-ms-high-contrast:none) {
  *::-ms-backdrop, .dropdown-menu .media-body { padding-right: 17px; }
}

// Behaviors arrow on the dropdown menu
.dropdown,
.enroll-action-form,
.hero-footer__cta {
  .caret {
    transition: transform 0.1s;
  }

  &.open .caret,
  .open .caret {
    transform: rotate(180deg);
  }
}
