@import '../settings';
@import '../colours';
@import '../common/z-index';
@import '../mixins';

// For legacy dropdown (using borders)
.button.dropdown::after {
  border-top-color: currentColor;
}

.dropdown {
  position: relative;
  display: inline-block;
  white-space: nowrap;

  /* Specificity fight with foundation */
  & > button.button {
    &:first-child {
      margin-inline-end: 1rem;
      /* A bit of space for the dropdown indicator */
      padding-inline-end: 1.5ch;
    }

    &.primary,
    &.secondary {
      &:first-child {
        /* A bit more space for the dropdown indicator for non-tertiary */
        padding-inline-end: 2.5ch;
      }
    }
  }

  & > :first-child::after {
    content: '▾';
    position: absolute;
    margin-inline-start: 0.5ch;
  }

  /* Override of franklin patterns when used within */
  /* try to keep as little as possible, watch out of specificity wars */
  .button {
    margin-block-end: 0;
    margin-inline-end: 0;
  }

  ul {
    margin-inline-start: 0;
    margin-block-end: 0;
  }
}

.dropdown__content {
  @include box-shadow();
  overflow-y: auto;
  width: max-content;
  z-index: $z-index-high;
  animation: 200ms reveal;
  background: #fff;
  position: absolute;
  padding: 0.5 * $global-padding;
  border-radius: 0 0 0.2rem 0.2rem;

  button.button,
  a,
  a.button {
    display: inline-block;
    color: $colour-yankees-blue;
    margin: 0;
    padding: 0.25em 1ch;
    width: 100%;
    line-height: 2;
    border: none;
    font-weight: normal;

    &:hover,
    &:focus-visible {
      background: $colour-platinum;
    }
  }
}

.dropdown-container {
  position: relative;
  display: inline-block;
}

.hover {
  color: $colour-yankees-blue;
  border: none;
  background: $colour-platinum;
}

.dropdown-content,
.dropdown-menu {
  --main-button-color: black;

  input {
    margin: 0;
  }

  @include box-shadow();
  display: none;
  overflow-y: auto;
  white-space: nowrap;
  position: absolute;
  background: #fff;
  z-index: $z-index-high;

  .dropdown-menu__content {
    padding: 1rem;
  }

  .dropdown-menu__panel {
    overflow-y: auto;
  }

  ul {
    display: block;
    list-style: none;
    margin: 0;
    padding: 0;

    // overflow-y: hidden;
    // height: auto !important;
    li {
      float: none !important;
      display: block;
      line-height: 1.6rem;
      background-color: $white !important;

      button,
      a {
        &,
        &.primary,
        &.secondary,
        &.tertiary {
          cursor: pointer;
          line-height: 1.6rem;
          width: 100%;
          text-align: left;
          font-weight: normal;
          padding: 0.5rem !important; // These two !important's are required to ensure the BLAST button is ...
          margin: 0 !important; // styled in the same way as the <a> tags in the Sequence component
          position: relative;
          display: block;
          border: none;
          padding-right: 1rem;
          text-decoration: none;
          white-space: nowrap;

          &:hover {
            @extend .hover;
          }

          &.active {
            font-weight: bold;
          }
        }
      }
    }
  }

  // The autocomplete has a dropdown-menu inside a dropdown-menu
  // so needs to have position set to relative so its width can
  // follow its container's
  .dropdown-menu {
    position: relative;
    top: 0;
  }
}

.dropdown-menu-open {
  display: block;
  animation: 200ms reveal;
}

@keyframes reveal {
  from {
    clip-path: circle(0% at 50% 0%);
  }
  to {
    clip-path: circle(100% at 50% 0%);
  }
}
