@use '@angular/material' as mat;
@mixin sc-alert-theme($theme) {
  $primary: map-get($theme, primary);
  $accent: map-get($theme, accent);
  $success: map-get($theme, success);
  $warning: map-get($theme, warning);
  $danger: map-get($theme, danger);
  $foreground: map-get($theme, foreground);
  $background: map-get($theme, background);
  $scForeground: map-get($theme, sc-foreground);
  $scBackground: map-get($theme, sc-background);
  $is-dark-theme: map-get($theme, is-dark);


  $danger-bg-color: if($is-dark-theme,  darken(desaturate(mat.get-color-from-palette($danger, 900), 30%), 15%), mat.get-color-from-palette($danger, 100));
  $danger-text-color: if($is-dark-theme,  mat.get-color-from-palette($danger, 200), mat.get-color-from-palette($danger, 900));
  $danger-border-color: if($is-dark-theme,  darken(desaturate(mat.get-color-from-palette($danger, 800), 30%), 15%), mat.get-color-from-palette($danger, 200));

  $warning-bg-color: if($is-dark-theme,  darken(desaturate(mat.get-color-from-palette($warning, 900), 30%), 15%), mat.get-color-from-palette($warning, 100));
  $warning-text-color: if($is-dark-theme,  mat.get-color-from-palette($warning, 200), mat.get-color-from-palette($warning, 900));
  $warning-border-color: if($is-dark-theme,  darken(desaturate(mat.get-color-from-palette($warning, 800), 30%), 15%), mat.get-color-from-palette($warning, 200));

  $success-bg-color: if($is-dark-theme,  desaturate(mat.get-color-from-palette($success, 900), 30%), mat.get-color-from-palette($success, 100));
  $success-text-color: if($is-dark-theme,  mat.get-color-from-palette($success, 200), mat.get-color-from-palette($success, 900));
  $success-border-color: if($is-dark-theme,  desaturate(mat.get-color-from-palette($success, 800), 30%), mat.get-color-from-palette($success, 200));


  .alert {
    background: map-get($background, card);
    border: 1px solid mat.get-color-from-palette($foreground, divider);
    border-radius: $alert-border-radius;

    //* Elements inside alerts

    &__link {
      color: inherit !important;
      text-decoration: underline solid map-get($foreground, text);
      font-weight: 500;

      &:hover {
        text-decoration: underline solid !important;
        opacity: 0.85;
        transition: all 0.3s ease;
      }
    }

    &__heading {
      color: inherit;
    }

    &__actions {
      border-color: mat.get-color-from-palette($foreground, divider);
    }

    //* Color variants

    &--inverted {
      background: map-get($scBackground, card-inverted);
      color: map-get($scForeground, text-inverted);
      border-color: rgba(
        map-get($scForeground, text-inverted),
        0.12
      ) !important;

      .alert__link {
        color: map-get($scForeground, text-inverted);
        text-decoration: underline solid mat.get-contrast-color-from-palette($primary, 500) !important;
      }

      .alert__actions,
      .mat-divider {
        color: map-get($scForeground, text-inverted);
        border-top-color: rgba(
          map-get($scForeground, text-inverted),
          0.12
        ) !important;

        .mat-stroked-button {
          border-color: rgba(
            map-get($scForeground, text-inverted),
            0.12
          ) !important;
        }
      }
    }

    &--primary {
      background: mat.get-color-from-palette($primary, 500);
      color: mat.get-contrast-color-from-palette($primary, 500);
      border-color: mat.get-color-from-palette($primary, 600);

      .alert__link {
        color: map-get($primary, 900);
        text-decoration: underline solid mat.get-contrast-color-from-palette($primary, 500) !important;
      }

      .alert__actions,
      .mat-divider {
        color: map-get($primary, 900);
        border-top-color: rgba(mat.get-contrast-color-from-palette($primary, 500), 0.24) !important;
      }

      .mat-button {
        color: mat.get-contrast-color-from-palette($primary, 500) !important;
      }

      .mat-flat-button {
        color: mat.get-color-from-palette($primary, 500) !important;
        background-color: mat.get-contrast-color-from-palette($primary, 500) !important;
      }

      .mat-stroked-button {
        color: mat.get-contrast-color-from-palette($primary, 500) !important;
        border-color: rgba(mat.get-contrast-color-from-palette($primary, 500), 0.24) !important;
      }
    }

    &--accent {
      background: mat.get-color-from-palette($accent, 300);
      color: mat.get-color-from-palette($accent, 900);
      border-color: map-get($accent, 400);

      .alert__link {
        color: map-get($accent, 900);
        text-decoration: underline solid map-get($accent, 400) !important;
      }

      .alert__actions,
      .mat-divider {
        color: map-get($accent, 900);
        border-top-color: rgba(mat.get-contrast-color-from-palette($accent, 500), 0.24) !important;
      }

      .mat-button {
        color: mat.get-color-from-palette($accent, 900) !important;
      }

      .mat-flat-button {
        color: mat.get-color-from-palette($accent, 300) !important;
        background-color: mat.get-color-from-palette($accent, 900) !important;
      }

      .mat-stroked-button {
        color: mat.get-color-from-palette($accent, 900) !important;
        border-color: mat.get-color-from-palette($accent, 400) !important;
      }
    }

    &--success {
      background: $success-bg-color;
      color: $success-text-color;
      border-color: $success-border-color;

      .alert__link {
        color: $success-text-color;
        text-decoration: underline solid $success-text-color !important;
      }

      .alert__actions,
      .mat-divider {
        color: $success-text-color;
        border-top-color: $success-border-color;
      }

      .mat-button {
        color: $success-text-color !important;
      }

      .mat-flat-button {
        color: $success-bg-color !important;
        background-color: $success-text-color !important;
      }

      .mat-stroked-button {
        color: $success-text-color !important;
        border-color: $success-border-color !important;
      }
    }

    &--warning {
      background: $warning-bg-color;
      color: $warning-text-color;
      border-color: $warning-border-color;

      .alert__link {
        color: $warning-text-color;
        text-decoration: underline solid $warning-text-color !important;
      }

      .alert__actions,
      .mat-divider {
        color: $warning-text-color;
        border-top-color: $warning-border-color;
      }

      .mat-button {
        color: $warning-text-color !important;
      }

      .mat-flat-button {
        color: $warning-bg-color !important;
        background-color: $warning-text-color !important;
      }

      .mat-stroked-button {
        color: $warning-text-color !important;
        border-color: $warning-border-color !important;
      }
    }

    &--danger {
      background: $danger-bg-color;
      color: $danger-text-color;
      border-color: $danger-border-color;

      .alert__link {
        color: $danger-text-color;
        text-decoration: underline solid $danger-text-color !important;
      }

      .alert__actions,
      .mat-divider {
        color: $danger-text-color;
        border-top-color: $danger-border-color;
      }

      .mat-button {
        color: $danger-text-color !important;
      }

      .mat-flat-button {
        color: $danger-bg-color !important;
        background-color: $danger-text-color !important;
      }

      .mat-stroked-button {
        color: $danger-text-color !important;
        border-color: $danger-border-color !important;
      }
    }
  }
}
