// QLD Desing System Bootstrap 5 library
// Extends: https://getbootstrap.com/docs/5.3/components/alerts/#variables
@use "../../../css/mixins" as m;

//All alerts have the same text and background color, even on darker themes
//To account for this, we redefine the global vars at the .alert scope

.alert {
  @extend %qld-palette-default;
  --qld-headings-color: var(--#{$prefix}light-text-text);
  --qld-alert-color: var(--#{$prefix}light-text-text);
  --qld-alert-bg: #fff;
}

.alert {
  position: relative;
  padding-left: 4rem;
  overflow-wrap: break-word;

  .alert-heading {
    line-height: 1.5;
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 1rem 0;
    padding: 0;
    color: var(--qld-color-default-color-light-text-heading);
  }

  p,
  ul,
  ol {
    line-height: 1.5;
  }

  &> :last-child {
    margin-bottom: 0;
  }
  // Close button for dismissible alerts
  .btn-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    height: 2rem;
    width: 2rem;
    background: url("data:image/svg+xml,%3Csvg width='32' height='32' viewBox='0 0 32 32' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cg style='mix-blend-mode:multiply'%3E%3Ccircle cx='16' cy='16' r='16' fill='%23F5F5F5'/%3E%3C/g%3E%3Cpath d='M17.2871 15.9004L21.3105 11.916L22.1309 11.0957C22.248 10.9785 22.248 10.7832 22.1309 10.627L21.2715 9.76758C21.1152 9.65039 20.9199 9.65039 20.8027 9.76758L15.998 14.6113L11.1543 9.76758C11.0371 9.65039 10.8418 9.65039 10.6855 9.76758L9.82617 10.627C9.70898 10.7832 9.70898 10.9785 9.82617 11.0957L14.6699 15.9004L9.82617 20.7441C9.70898 20.8613 9.70898 21.0566 9.82617 21.2129L10.6855 22.0723C10.8418 22.1895 11.0371 22.1895 11.1543 22.0723L15.998 17.2285L19.9824 21.252L20.8027 22.0723C20.9199 22.1895 21.1152 22.1895 21.2715 22.0723L22.1309 21.2129C22.248 21.0566 22.248 20.8613 22.1309 20.7441L17.2871 15.9004Z' fill='%231D1D1D'/%3E%3C/svg%3E")
      no-repeat center center;
  }

  //alerts color map with icons
  $alert-icons-map: (
    "success": (
      "color": var(--#{$prefix}success),
      "icon": "alert-success",
    ),
    "info": (
      "color": var(--#{$prefix}info),
      "icon": "alert-information",
    ),
    "warning": (
      "color": var(--#{$prefix}warning),
      "icon": "alert-warning",
			"icon-color": var(--#{$prefix}neutral-black),
    ),
    "danger": (
      "color": var(--#{$prefix}danger),
      "icon": "alert-danger",
    ),
    "error": (
      "color": var(--#{$prefix}danger),
      "icon": "alert-danger",
    ),
    "light": (
      "color": var(--#{$prefix}light-grey),
      "icon": null,
    ),
    "dark": (
      "color": var(--#{$prefix}dark-grey),
      "icon": null,
    ),
  );

  &:before,
  &:after {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
  }

  &:before {
    width: 3rem;
  }

  //Sets border color and icon for each alert type
  @each $key, $values in $alert-icons-map {
    &-#{$key} {
      border-color: map-get($values, "color");
      border-width: 2px;

      &:before {
        background-color: map-get($values, "color");
      }

      @if map-get($values, "icon") {
        @include m.make-icon(
          $name: map-get($values, "icon"),
          $size: "md",
          $pseudo: "after"
        ) {
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: center;
          margin: 0 0.75rem;

          // <-- Conditional color logic starts here
          @if map-has-key($values, "icon-color") {
            color: map-get($values, "icon-color");
          } @else {
            color: var(--#{$prefix}neutral-white);
          }
          // <-- Conditional color logic ends here
        }
      }
    }
  }
}
