@use "../../../variables/index" as *;
@use "../../mixins/alert-variant";
@use "../../mixins/c8y-scrollbar";
@use "../../mixins/shadows-helper";

/**
 * Alerts - Alert/notification component styles
 *
 * Note: Uses $alert-* variables and $size-* tokens for spacing. Uses CSS custom properties for colors.
 *
 * Intentionally hardcoded values:
 * - Alert icon width (44px): Icon area specific size
 * - Alert widths (280px, 480px): Component-specific responsive widths
 * - Positioning offsets (-2px, -21px, 130px, 90px, 60px): Fine-tuning and breakpoint-specific positioning
 * - Line-height (2.2): Typography ratio for icon alignment
 * - Blur (3px): Backdrop filter effect
 * - Transition duration (0.35s): Animation timing
 * - Z-index values (1035): Stacking order
 * - Percentages (50%): Color mixing
 */

// Shared mixin for prompt icon coloring
@mixin prompt-icon-color($color) {
  h3 > i,
  h3 > [class^='dlt-c8y-icon-'],
  h3 > [class*=' dlt-c8y-icon-'] {
    color: $color;
  }
}

.alert {
  --c8y-btn-default-background-default: #{$alert-background};
  margin-bottom: $size-base;
  padding: $alert-padding;
  max-width: $alert-max-width;
  border-radius: $component-border-radius-base;
  word-wrap: break-word;

  overflow-wrap: break-word;
  @include shadows-helper.boxShadowHelper(sm);

  > span {
    white-space: pre-line;
  }

  &:before {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    display: inline-flex;
    justify-content: center;
    width: 44px;
    border-left: $alert-border-width $alert-border-style transparent;
    text-align: center;
    font-size: $alert-status-symbol-size;
    font-family: $alert-icon-font-family;
    line-height: 2.2;
    transform: translate(0, 0);

    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  // Headings for larger alerts
  h4 {
    margin-top: 0;
    color: inherit;
  }
  > p,
  > ul {
    margin-bottom: 0;
  }
  > p + p {
    margin-top: $size-base;
  }
  > .close {
    margin-left: $size-8;
  }

  &.c8y-prompt {
    margin-bottom: 0;
    padding: calc($size-base * 5);
    &:before {
      content: '' !important;
    }
    h3 {
      font-weight: 500;
      font-size: $size-20;
      > [class^='dlt-c8y-icon-'],
      > [class*=' dlt-c8y-icon-'] {
        margin-right: $size-4;
        font-size: $size-24;
      }
    }
    .alert-footer {
      padding: calc($size-base * 5) 0 0;
      text-align: right;
      button {
        margin-bottom: 0 !important;
      }
    }
    &.alert-success {
      @include prompt-icon-color($alert-success-border);
    }
    &.alert-warning {
      &:before {
        z-index: 10;
      }

      @include prompt-icon-color($alert-warning-border);
    }
    &.alert-danger {
      @include prompt-icon-color($alert-danger-border);
    }
    &.alert-info {
      @include prompt-icon-color($alert-info-border);
    }
  }
}

// Dismissible alerts
// Expand the right padding and account for the close button's positioning.
.alert-dismissable, // The misspelled .alert-dismissable was deprecated in 3.2.0.
.alert-dismissible {
  padding-right: calc($component-padding + $size-20); // Adjust close link position
  .close {
    position: relative;
    top: -2px;
    right: -21px; //color: inherit;
  }
}

// Alternate styles
// Generate contextual modifier classes for colorizing the alert.
.alert-success {
  @include alert-variant.alert-variant($alert-success-bg, $alert-success-border, $alert-success-text, $alert-success-icon);
}

.alert-info {
  @include alert-variant.alert-variant($alert-info-bg, $alert-info-border, $alert-info-text, $alert-info-icon);
}

.alert-system {
  @include alert-variant.alert-variant($alert-system-bg, $alert-system-border, $alert-system-text, $alert-system-icon);
}

.alert-warning {
  @include alert-variant.alert-variant($alert-warning-bg, $alert-warning-border, $alert-warning-text, $alert-warning-icon);
}

.alert-danger {
  @include alert-variant.alert-variant($alert-danger-bg, $alert-danger-border, $alert-danger-text, $alert-danger-icon);
}

// Alerts
.alerts {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: auto;
  z-index: $zindex-alerts;
  display: flex;
  flex-flow: column;
  max-width: 100vw;
  pointer-events: none;
  .static & {
    position: static;
    padding: 0;
  }

  > c8y-alert-outlet:not(:empty) {
    display: block;
    overflow-x: hidden;
    overflow-y: auto;
    margin-top: $headerHeight;
    padding: 0 $size-16 $size-16 $size-48;
    max-height: calc(100vh - $headerHeight);
    pointer-events: auto;

    @include c8y-scrollbar.c8y-scrollbar();
  }

  .alert {
    margin: $size-base $size-24 $size-16 auto;
    width: 280px;
    transition: width 0.35s ease-in-out;
    pointer-events: auto;
    @include shadows-helper.boxShadowHelper(md);
    &.expanded {
      width: 480px;
      @media (max-width: $screen-xs-max) {
        width: 280px;
      }
    }
  }
}

.navigator.open ~ .alerts {
  left: $navigatorWidth;
}

.overlay-center-vertically {
  position: absolute;
  top: 0;
  left: 0;
  z-index: $zindex-dropdown - 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background-color: color-mix(in srgb, var(--c8y-root-component-background-default), transparent 50%);
  backdrop-filter: blur(3px);
}

// prevent double scroll bars on widgets when the alerts overlay is displayed
.alerts-overlay {
  .card-inner-scroll {
    overflow: hidden !important;
  }
}

// container to hold alerts on widgets
.inner-alert {
  position: absolute;
  right: $size-16;
  left: $size-16;
  z-index: 1035;
  .alert {
    margin: 0 auto $size-10;
  } // on data-explorer
  .measurement-icon-bar & {
    top: 130px;
    @media (min-width: $screen-sm-min) {
      top: 90px;
    }
    @media (min-width: $screen-md-min) {
      top: 60px;
    }
  }
}