/*
 * 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-container-helpers';

.nx-search-dropdown {
  display: inline-block;
  position: relative;

  &__menu {
    // Only show when the component is focused. When hidden, just move offscreen so still in the tab order
    position: fixed;
    right: 100%;
    width: 100%;

    &--error {
      padding: 0;
    }
  }

  &__empty-message {
    padding: var(--nx-spacing-base) var(--nx-spacing-4x);
    text-align: center;

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

  &--dropdown-showable {
    @mixin show-menu {
      .nx-search-dropdown__menu {
        position: absolute;
        right: initial;
      }
    }

    &:focus-within {
      @include show-menu;
    }

    // Hack to detect Safari. In Safari, focus seems to be intended to strictly be a keyboard nav thing,
    // and when you click a button, focus does NOT go to that button, it goes to the <body>. This messes up our idea
    // of only showing the menu when something within the component has focus, because this means that the
    // component loses focus in the middle of the click, causing the menu to hide while the user is in the middle
    // of clicking, causing the click not to register at all. As a workaround, in Safari we remove the behavior
    // where the menu is only visible when the component has focus.
    @supports (overflow: -webkit-paged-x) {
      @include show-menu;
    }
  }

  .nx-loading-spinner {
    padding-top: var(--nx-spacing-6x);
    padding-bottom: var(--nx-spacing-6x);
    text-align: center;
  }
}
