/*
 * Copyright (c) 2019-present Sonatype, Inc.
 * This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License 2.0 which accompanies this
 * distribution and is available at https://www.eclipse.org/legal/epl-2.0/.
 */
@use '../../scss-shared/nx-dropdown-variables';
@use '../../scss-shared/nx-container-helpers';
@use '../../scss-shared/nx-text-helpers';
@use '../../scss-shared/nx-button-helpers';

.nx-dropdown-menu {
  background: var(--nx-color-dropdown-menu-background);
  border-radius: var(--nx-border-radius);
  box-shadow: var(--nx-box-shadow-dropdown);
  box-sizing: border-box;
  display: block;
  max-height: 328px;
  margin: var(--nx-spacing-base) 0 0 0;
  overflow-y: auto;
  padding: var(--nx-spacing-base) 0;
  position: absolute;
  top: 100%;
  width: nx-dropdown-variables.$dropdown-width;
  z-index: 1;

  @include nx-container-helpers.container-vertical;
}

.nx-dropdown-link, .nx-dropdown-button {
  @include nx-text-helpers.truncate-ellipsis;
  @include nx-text-helpers.regular;

  background: none;
  box-sizing: border-box;
  border: none;
  cursor: pointer;
  display: block;
  font-size: var(--nx-font-size);
  line-height: var(--nx-line-height);
  padding: var(--nx-spacing-base) var(--nx-spacing-4x);
  text-align: left;
  text-decoration: none;
  width: 100%;

  @include nx-container-helpers.container-horizontal;
}

.nx-dropdown-button {
  background-color: transparent;
  border-radius: 0;
  box-sizing: border-box;
  color: var(--nx-color-text);
  outline: none;
  text-align: left;
  width: 100%;

  &:hover {
    background-color: var(--nx-color-dropdown-menu-background-hover);
    color: var(--nx-color-dropdown-menu-text-hover);
  }

  &:focus {
    outline-offset: calc(0px - var(--nx-focus-outline-offset));
    outline: var(--nx-focus-outline-width) solid var(--nx-color-interactive-border-focus);
  }

  &:active {
    background-color: var(--nx-color-dropdown-menu-background-active);
    color: var(--nx-color-text-stark);
    outline: none;
  }

  &.disabled {
    &, &:hover, &:focus {
      background-color: transparent;
      color: var(--nx-color-text-disabled);
      cursor: default;
      outline: none;
      text-decoration: none;
    }
  }
}

.nx-dropdown-link {
  color: var(--nx-color-link);

  // Text links within the dropdown menu should use the interaction states of Text Links,
  // to implement the correct style for focus state, we need to use margins instead of paddings
  margin: var(--nx-spacing-base) var(--nx-spacing-4x);
  max-width: calc(100% - var(--nx-spacing-8x));
  padding: 0;
  text-decoration: underline;
  width: min-content;

  &:hover {
    color: var(--nx-color-link-hover);
  }

  &:active {
    color: var(--nx-color-link-active);
    outline: none;
  }

  &.disabled {
    &, &:hover, &:focus {
      color: var(--nx-color-link-disabled);
      cursor: default;
    }
  }

  &:focus {
    border-radius: var(--nx-border-radius);
    outline: var(--nx-focus-outline-width) solid var(--nx-color-interactive-border-focus);
  }

  &:first-child {
    margin-top: var(--nx-spacing-base);
  }

  &:last-child {
    margin-bottom: var(--nx-spacing-base);
  }

  + .nx-dropdown-link {
    margin-top: var(--nx-spacing-2x)
  }
}

.nx-dropdown__divider {
  background-color: var(--nx-color-border);
  border: none;
  height: 1px;
  margin: var(--nx-spacing-2x) var(--nx-spacing-6x) var(--nx-spacing-2x) var(--nx-spacing-4x);

  .nx-dropdown-link + &, + .nx-dropdown-link  {
    margin-top: var(--nx-spacing-3x);
  }
}

.nx-dropdown-button-content {
  @include nx-text-helpers.truncate-ellipsis;
  display: block;
  line-height: var(--nx-spacing-8x);
}

.nx-dropdown-right-button {
  @include nx-button-helpers.small-icon-btn;
  float: right;
  margin-right: var(--nx-spacing-2x);
  margin-left: var(--nx-spacing-6x);

  // take off a px to make room for the button border
  margin-top: calc(var(--nx-spacing-base) - 1px);
  margin-bottom: calc(var(--nx-spacing-base) - 1px);

  + .nx-dropdown-button {
    display: block;
    padding-right: 0;
    overflow: visible;
  }
}
