/*
 * 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-text-helpers';
@use '../../scss-shared/nx-container-helpers';
@use '../../scss-shared/nx-button-helpers';
@use '../../scss-shared/nx-dropdown-variables';

.nx-dropdown {
  display: inline-block;
  position: relative;
  width: nx-dropdown-variables.$dropdown-width;

  .nx-icon:not(
    .nx-icon--colorful,
    .nx-dropdown-link .nx-icon,
    .nx-filter-dropdown__reset .nx-icon,
    .nx-dropdown :is(.disabled, [disabled]) .nx-icon,
    .nx-navigation-dropdown .nx-icon
  ) {
    color: var(--nx-color-text-stark);
  }
}

.nx-dropdown-icon {
  color: var(--nx-color-text-stark);
}

.nx-dropdown--short {
  width: 150px;

  .nx-dropdown-menu {
    width: 100%;
  }
}

.nx-dropdown__toggle {
  border: 1px solid var(--nx-color-interactive-border);
  color: var(--nx-color-text);
  display: flex;
  margin: 0;
  outline: none;
  padding: calc(var(--nx-spacing-2x) - 1px) calc(var(--nx-spacing-4x) - 1px);
  text-align: left;
  width: 100%;

  &:hover {
    background: transparent;
    border-color: var(--nx-color-interactive-border-hover);
    color: var(--nx-color-text);
  }

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

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

  .nx-dropdown__toggle-label {
    @include nx-text-helpers.truncate-ellipsis;

    flex-grow: 1;

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

  .nx-dropdown__toggle-caret {
    align-self: center;
  }

  &.disabled {
    &, &:hover, &:focus {
      background-color: var(--nx-color-interactive-background-disabled);
      color: var(--nx-color-text-disabled);
    }
  }

  &:active {
    background-color: transparent;
  }

  &.open {
    border-color: var(--nx-color-interactive-border-hover);

    &:focus {
      border-color: var(--nx-color-interactive-border);
    }
  }
}
