/*
 * 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';
@use '../scss-shared/nx-dark-mode-helpers';

/*
  #Alerts
*/

.nx-alert {
  align-items: first baseline;
  background-color: var(--nx-color-component-background);
  border: 1px solid var(--nx-color-text-stark);
  border-radius: var(--nx-border-radius);
  box-sizing: border-box;
  color: var(--nx-color-text);
  display: flex;
  margin: 16px 0 24px 0;
  padding: var(--nx-spacing-4x);
  text-align: initial;
  max-width: var(--nx-width-text-wrapping);

  @each $type in warning, error, info, success {
    &--#{$type} {
      border-color: var(--nx-color-alert-#{$type}-border);
      background-color: var(--nx-color-alert-#{$type}-background);
      color: var(--nx-color-alert-text);

      > .nx-icon {
        color: var(--nx-color-alert-#{$type}-icon);
      }

      > .nx-btn--close {
        color: var(--nx-color-alert-close-btn);

        &:hover {
          background-color: var(--nx-color-alert-#{$type}-close-btn-hover);
          color: var(--nx-color-alert-close-btn);
        }

        &:focus:not(:active) {
          outline-color: var(--nx-color-alert-close-btn-focus);
        }

        &:active {
          background-color: var(--nx-color-alert-#{$type}-close-btn-active);
          color: var(--nx-color-alert-close-btn);
        }
      }
    }
  }

  > .nx-icon {
    // replicate the vertical-alignment that fontawesome icons usually have.  vertical-align itself has
    // no effect here so we use relative positioning instead
    bottom: -0.125em;
    flex-shrink: 0;
    height: 1em;
    margin-right: var(--nx-spacing-4x);
    position: relative;
  }

  > .nx-btn--close {
    flex-shrink: 0;
    margin-left: auto;
  }

  // This "strut" has the same height as the close button and ensures that the alert content stays vertically centered
  // when the close button is not present
  &::before {
    // zero-width space
    content: '\200b';
    margin: var(--nx-spacing-base) 0;
  }

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

.nx-alert__content-wrap {
  align-items: center;
  display: flex;
  flex-grow: 1;
  min-height: 32px;

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

.nx-alert__content {
  flex-grow: 1;
  overflow-wrap: anywhere;

  .nx-text-link {
    color: var(--nx-color-alert-link);

    &:focus {
      outline-color: var(--nx-color-alert-link-focus);
      color: var(--nx-color-alert-link);
    }

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

    &:active, &:active:focus {
      color: var(--nx-color-alert-link-active);
    }
  }

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

footer, .nx-footer {
  .nx-alert {
    margin-left: auto;
    margin-right: auto;
  }
}
