@use "../../../css/mixins" as m;

.global-alert {
  --focus-colour: var(--#{$prefix}neutral-darkest);

  line-height: 1.25rem;
  border-radius: 0;
  border-top-style: solid;
  border-width: 0;
  padding-block: 0.75rem;

  &:first-child:not(:only-child) {
    border-top-width: 1px;
  }

  & + & {
    border-top-width: 1px;
  }

  .qld-global-alert-main {
    display: flex;
    column-gap: 1rem;
    align-items: flex-start;
    width: 100%;
    margin-inline: auto;
    box-sizing: border-box;
  }

  .global-alert-icon {
    width: 1.25rem;
    height: 1.25rem;
    padding: 0.5rem 0;
  }

  .global-alert-content {
    --qld-focus-color: #000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
    padding: 0.5rem 0;

    // Link styling placed outside the 'action link', to include all links within the content as well.
    a,
    a:visited {
      color: inherit;
      text-decoration-color: inherit;
      text-underline-offset: 0.3rem;
    }

    a {
      @include m.focusable($outlineWidth: 2px);
    }

    .global-alert-action {
      display: flex;
      gap: 0.5rem;
    }
    // Action link styling
    .global-alert-action a {
      display: flex;
      column-gap: 0.5rem;
      align-items: center;
      font-weight: 600;
      text-wrap: nowrap;
    }
  }

  .global-alert-close {
    display: inline-flex;
    justify-content: center;
    flex-shrink: 0;
    box-sizing: border-box;
    align-items: center;

    .btn-close {
      position: relative;
      top: 0;
      right: 0;
      background-color: rgba(19, 18, 18, 0.1);
      border-radius: 50%;
      width: 2rem;
      height: 2rem;
      background-image: none; // Overriding default Bootstrap close icon
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 1;
      padding: 0;
      transition: transform 0.2s ease;

      &::before {
        content: "";
        display: block;
        width: 1.25rem;
        height: 1.25rem;
        background-color: #000000;
        mask-image: var(--qgds-icon-close);
        -webkit-mask-image: var(--qgds-icon-close);
        mask-position: center center;
        mask-repeat: no-repeat;
        mask-size: contain;
      }

      @include m.focusable($outlineWidth: 2px);
      box-shadow: none;
      &:focus {
        outline-color: var(--focus-colour);
      }

      @include media-breakpoint-down(lg) {
        &:hover {
          transform: scale(1.25);
        }
      }
    }
  }

  &.global-alert-critical {
    --#{$prefix}icon-color: #{$core-default-color-neutral-white};
    --focus-colour: var(--#{$prefix}neutral-white);

    background-color: $qld-notify-warning;
    color: var(--#{$prefix}white);
    font-size: 0.875em;
    border-top-color: var(--#{$prefix}core-default-color-status-error-darker);

    .qld-icon {
      background-color: var(--#{$prefix}white);
    }

    .global-alert-action a {
      color: var(--#{$prefix}white);
      text-decoration-color: var(--#{$prefix}white);

      &:after {
        background-color: var(--#{$prefix}white);
      }
    }

    .global-alert-close .btn-close {
      &::before {
        background-color: #ffffff;
      }
    }

    a {
      --qld-focus-color: #ffffff;
    }
  }

  &.global-alert-warning {
    --#{$prefix}icon-color: #{$core-default-color-neutral-black};

    background-color: $qld-notify-alert;
    color: var(--#{$prefix}body-color);
    font-size: 0.875em;
    border-top-color: var(--#{$prefix}core-default-color-status-caution-darker);

    .global-alert-action a {
      color: var(--#{$prefix}body-color);
      text-decoration-color: var(--#{$prefix}body-color);
    }
  }

  &.global-alert-info {
    --#{$prefix}icon-color: #{$core-default-color-neutral-black};

    background-color: $qld-general-info-alert;
    color: var(--#{$prefix}body-color);
    font-size: 0.875em;
    border-top-color: var(--#{$prefix}core-default-color-status-info-darker);

    .global-alert-action a {
      color: var(--#{$prefix}body-color);
      text-decoration-color: var(--#{$prefix}body-color);
    }
  }
}

@include media-breakpoint-up(md) {
  .global-alert {
    .global-alert-content {
      gap: 1rem;
      flex-direction: row;
      align-items: flex-start;
    }

    &.global-alert-message {
      padding: 0 3rem 0 1rem; // Also: 0 48px 0 16px, according to Health DS
    }

    &.global-alert-action {
      flex-shrink: 0; //  Prevent action link from shrinking/collapsing
      margin-left: 2rem;
    }
  }
}
@include media-breakpoint-down(lg) {
  .global-alert {
    .global-alert-content .global-alert-action {
      margin-inline-end: 2rem;
    }
  }
}

@include media-breakpoint-down(md) {
  .global-alert {
    .global-alert-content {
      padding: 0;

      .global-alert-action {
        margin-inline-end: 0.5rem;

        a {
          text-wrap: auto;
        }

        .qld-icon {
          min-width: var(--icon-size);
        }
      }
    }
  }
}
@include media-breakpoint-up(lg) {
  .global-alert {
    .global-alert-close {
      .btn-close {
        width: 2.5rem;
        height: 2.5rem;

        &::before {
          width: 1.5rem;
          height: 1.5rem;
        }

        &:hover {
          transform: scale(1.2);
          transition: transform 0.2s ease;
        }
      }
    }
  }
}
