@use "../abstracts/mixins";

$dropdown-border-radius: 1rem;
$dropdown-padding: 0.375rem;

.tippy-box[data-theme~="dropdown"] {
  border-radius: $dropdown-border-radius;
  box-shadow: var(--dropdown-box-shadow);
  outline: none !important;
  background: color-mix(in sRGB, var(--card-background) 85%, transparent);
  backdrop-filter: var(--dropdown-backdrop-filter);
  max-width: unset !important;
  max-height: 75vh;
  overflow-y: auto;

  .tippy-content {
    display: flex;
    flex-direction: column;
    padding: 0;

    .jenkins-spinner {
      margin: 1rem;
    }
  }
}

.tippy-box[data-animation="dropdown"][data-state="hidden"] {
  $translate: 5px;
  $scale: 0.99;

  opacity: 0;
  transform: scale($scale);

  &[data-placement^="top"] {
    transform-origin: bottom;
    transform: translateY($translate) scale($scale);
  }

  &[data-placement^="bottom"] {
    transform-origin: top;
    transform: translateY(-$translate) scale($scale);
  }

  &[data-placement^="left"] {
    transform-origin: right;
    transform: translateX($translate) scale($scale);
  }

  &[data-placement^="right"] {
    transform-origin: left;
    transform: translateX(-$translate) scale($scale);
  }
}

.jenkins-dropdown {
  display: flex;
  flex-direction: column;
  padding: $dropdown-padding;

  &--compact {
    > .jenkins-dropdown__item,
    > .jenkins-dropdown__disabled {
      padding: 0 0.6rem;
      min-height: 30px !important;
    }
  }

  &__filter {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--input-border);

    &-input {
      &:focus {
        outline: none;
      }

      width: 100%;
      border: none;
      color: var(--text-color-secondary);
      background-color: unset;
    }

    svg {
      margin-top: 2px;
    }
  }

  &__separator {
    position: relative;
    height: var(--jenkins-border-width);
    margin: $dropdown-padding calc($dropdown-padding * -1);
    border: none;
    background-color: var(--jenkins-border-color);
  }

  &__heading {
    color: var(--text-color-secondary) !important;
    margin: $dropdown-padding 0.65rem;
    font-size: 0.8125rem;
    font-weight: var(--font-bold-weight);
    opacity: 0.8;

    &:not(:first-of-type) {
      margin-top: 1rem;
    }
  }

  &__placeholder {
    color: var(--text-color-secondary) !important;
    margin: $dropdown-padding 0.55rem;
    font-size: 0.8125rem;
    opacity: 0.8;
  }

  &__disabled {
    color: var(--text-color-secondary) !important;
    font-size: 0.8125rem;
    opacity: 0.8;
    display: inline-flex;
    align-items: center;
    margin: 0;
    cursor: default;
  }

  &__item {
    --item-background--hover: var(--button-background--hover);
    --item-background--active: var(--button-background--active);
    --item-box-shadow--focus: var(--button-box-shadow--focus);

    @include mixins.item($border: false);

    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    border: none;
    outline: none;
    margin: 0;
    padding: $dropdown-padding 1.75rem $dropdown-padding 0.6rem;
    font-size: 0.8125rem;
    font-weight: normal;
    text-decoration: none !important;
    background: transparent;
    color: var(--text-color) !important;
    border-radius: calc($dropdown-border-radius - $dropdown-padding);
    cursor: pointer;
    min-height: 36px;
    white-space: nowrap;
    gap: 1.2ch;
    min-width: 180px;
    user-select: none;

    &__icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 1.125rem;
      height: 1.125rem;
      margin-right: 0.1rem;

      svg,
      img {
        width: 1.125rem;
        height: 1.125rem;
        color: inherit;
      }
    }

    &:disabled {
      pointer-events: none;
      opacity: 0.5;
      filter: saturate(0.6);
    }

    &[class*="color"] {
      background: transparent;
      color: var(--color) !important;

      &::before {
        background: currentColor !important;
        opacity: 0;
      }

      &::after {
        box-shadow: 0 0 0 0.66rem currentColor;
        opacity: 0;
      }

      &:hover {
        &::before {
          opacity: 0.15;
        }
      }

      &:active,
      &:focus {
        &::before {
          opacity: 0.2;
        }

        &::after {
          box-shadow: 0 0 0 0.33rem currentColor;
          opacity: 0.1;
        }
      }
    }

    &__badge {
      margin-left: auto;
      margin-right: -0.85rem;
    }

    &__chevron {
      position: absolute;
      top: 0;
      right: 0.1875rem;
      bottom: 0;
      background: var(--text-color-secondary);
      width: 1rem;
      mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'%3E%3Ctitle%3EChevron Forward%3C/title%3E%3Cpath fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M184 112l144 144-144 144'/%3E%3C/svg%3E");
      mask-size: contain;
      mask-repeat: no-repeat;
      mask-position: center;
      opacity: 0.6;
    }
  }

  &:hover {
    .jenkins-dropdown__item--selected {
      &::before {
        opacity: 0;
      }
    }
  }
}

.jenkins-dropdown__item--selected {
  &::before {
    background: var(--item-background--hover);
    border: var(--jenkins-border--subtle) !important;
    animation: pulse 1s ease-in-out forwards;
  }

  &:hover {
    &::before {
      opacity: 1 !important;
    }
  }

  @keyframes pulse {
    50% {
      background: var(--item-background--active);
    }
  }
}

.jenkins-overflow-button__ellipsis {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  width: 1.4rem;
  height: 1.1rem;
  margin-inline: -0.1rem;

  span {
    min-width: 0.3125rem;
    min-height: 0.3125rem;
    border: 1px solid currentColor;
    border-radius: 50%;
  }
}

.jenkins-jumplist-link {
  appearance: none;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;

  svg {
    width: 1.25rem;
    height: 1.25rem;
  }
}
