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

 // 74px refers to the total height of each toast: the content itself, plus the padding
 // and margin-top applied. 
 $-toast-height: 66px;

.nx-toast-container {
  grid-area: content;
  justify-self: end;
  padding-right: var(--nx-spacing-2x);
  width: 500px;
  z-index: var(--nx-z-index-toast);
  overflow: hidden;
  pointer-events: none;
}

// in legacy layouts where page scrolling is enabled, position: fixed helps keep
// NxToastContainer in place. Top refers to the set height of the the header
.nx-html--page-scrolling {
  .nx-toast-container {
    position: fixed;
    top: nx-header-variables.$main-header-height;
    right: 0;
  }
}

.nx-toast {
  position: relative;
  right: 0;
  opacity: 1;
  margin-top: var(--nx-spacing-2x);
  animation: nx-toast-animation-in 300ms ease-out;
  overflow: hidden;
  pointer-events: auto;

  &.nx-toast--closing {
    animation: nx-toast-animation-out 250ms ease-in;
  }

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

// Setting the max-height of each toast to $nx-toast-height in both animations allows for each 
// subsequent toast to smoothly move up or down as toasts are added and removed
@keyframes nx-toast-animation-in {
  0% {
    margin-top: 0;
    max-height: 0px;
    right: -100%;
    opacity: 0;
  }
  40% {
    margin-top: var(--nx-spacing-2x);
    right: -100%;
    opacity: 0;
    max-height: $-toast-height;
  }
}

@keyframes nx-toast-animation-out {
  75% {
    margin-top: var(--nx-spacing-2x);
    max-height: $-toast-height;
    right: -100%;
    opacity: 0;
  }
  100% {
    margin-top: 0;
    max-height: 0px;
    right: -100%;
    opacity: 0;
  }
}

/*
  If the user has expressed their preference for reduced motion,
  then only animate the fade effect.
*/
@media (prefers-reduced-motion: reduce) {
  .nx-toast {
    animation-name: nx-toast-reduced-animation-in;

    &.nx-toast--closing {
      animation-name: nx-toast-reduced-animation-out;
    }
  }
}

@keyframes nx-toast-reduced-animation-in {
  0% {
    opacity: 0;
  }
}

@keyframes nx-toast-reduced-animation-out {
  100% {
    opacity: 0;
  }
}
