/*!
 * Copyright (c) 2014-2025 Bjoern Kimminich & the OWASP Juice Shop contributors.
 * SPDX-License-Identifier: MIT
 */
@use '@angular/material' as mat;

@use 'sass:map';
@use 'sass:color';

@use './theme' as *;

@use './hacking-instructor/hacking-instructor.scss';

@mixin link-theme($theme) {
  a:link,
  a:visited {
    color: mat.m2-get-color-from-palette(map.get($theme, accent), lighter);
    text-decoration: none;
  }

  a:hover,
  a:focus,
  a:active {
    text-decoration: underline;
  }

  a {
    outline: none;
  }
}

@mixin deluxe-membership-theme($theme) {
  .deluxe-membership {
    background: linear-gradient(90deg, mat.m2-get-color-from-palette(map.get($theme, primary), 1) 0%, mat.m2-get-color-from-palette(map.get($theme, background), card) 100%);
  }
}

@mixin notification-theme($theme) {
  .confirmation {
    color: mat.m2-get-color-from-palette(map.get($theme, accent));
  }

  .ribbon::before {
    border: 5px solid mat.m2-get-color-from-palette(map.get($theme, accent));
  }

  .ribbon span {
    background-color: mat.m2-get-color-from-palette(map.get($theme, accent));
  }

  .error {
    color: mat.m2-get-color-from-palette(map.get($theme, warn));
  }

  .ribbon-sold::before {
    border: 5px solid mat.m2-get-color-from-palette(map.get($theme, warn));
  }

  .ribbon-sold span {
    background-color: mat.m2-get-color-from-palette(map.get($theme, warn));
  }

  .primary-notification {
    background-color: mat.m2-get-color-from-palette(map.get($theme, primary), darker);
  }

  .accent-notification {
    background-color: mat.m2-get-color-from-palette(map.get($theme, accent), darker);
  }

  .warn-notification {
    background-color: mat.m2-get-color-from-palette(map.get($theme, warn), darker);
  }
}

@mixin image-thumbnail-theme($theme) {
  .img-thumbnail {
    background-color: mat.m2-get-color-from-palette(map.get($theme, primary), 0.05);
    border: 1px solid mat.m2-get-color-from-palette(map.get($theme, primary));
    border-radius: 3px;
    padding: 3px;
  }
}

@mixin score-star-theme($theme) {
  .empty-star {
    stop-color: mat.m2-get-color-from-palette(map.get($theme, primary));
  }

  .filled-star {
    stop-color: mat.m2-get-color-from-palette(map.get($theme, accent));
  }

  .star-border {
    stroke: mat.m2-get-color-from-palette(map.get($theme, accent));
  }
}

// sets css variables to be used across components during runtime
@mixin css-vars($theme) {
  --theme-primary: #{mat.m2-get-color-from-palette(map.get($theme, primary))};
  --theme-primary-lighter: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, primary)), $lightness: 6%)};
  --theme-primary-light: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, primary)), $lightness: 10%)};
  --theme-primary-darker: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, primary)), $lightness: -6%)};
  --theme-primary-dark: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, primary)), $lightness: -10%)};
  --theme-primary-fade-10: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, primary)), $alpha: 0.1)};
  --theme-primary-fade-20: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, primary)), $alpha: 0.2)};
  --theme-primary-fade-30: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, primary)), $alpha: 0.3)};
  --theme-primary-fade-40: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, primary)), $alpha: 0.4)};
  --theme-primary-fade-50: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, primary)), $alpha: 0.5)};

  --theme-accent: #{mat.m2-get-color-from-palette(map.get($theme, accent))};
  --theme-accent-lighter: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, accent)), $lightness: 6%)};
  --theme-accent-light: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, accent)), $lightness: 10%)};
  --theme-accent-darker: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, accent)), $lightness: -6%)};
  --theme-accent-dark: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, accent)), $lightness: -10%)};
  --theme-accent-fade-10: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, accent)), $alpha: 0.1)};
  --theme-accent-fade-20: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, accent)), $alpha: 0.2)};
  --theme-accent-fade-30: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, accent)), $alpha: 0.3)};
  --theme-accent-fade-40: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, accent)), $alpha: 0.4)};
  --theme-accent-fade-50: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, accent)), $alpha: 0.5)};

  --theme-warn: #{mat.m2-get-color-from-palette(map.get($theme, warn))};
  --theme-warn-lighter: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, warn)), $lightness: 6%)};
  --theme-warn-light: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, warn)), $lightness: 10%)};
  --theme-warn-darker: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, warn)), $lightness: -6%)};
  --theme-warn-dark: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, warn)), $lightness: -10%)};
  --theme-warn-fade-10: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, warn)), $alpha: 0.1)};
  --theme-warn-fade-20: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, warn)), $alpha: 0.2)};
  --theme-warn-fade-30: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, warn)), $alpha: 0.3)};
  --theme-warn-fade-40: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, warn)), $alpha: 0.4)};
  --theme-warn-fade-50: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, warn)), $alpha: 0.5)};

  --theme-text: #{mat.m2-get-color-from-palette(map.get($theme, foreground), text)};
  --theme-text-lighter: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, foreground), text,), $lightness: 6%)};
  --theme-text-light: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, foreground), text,), $lightness: 10%)};
  --theme-text-darker: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, foreground), text,), $lightness: -10%)};
  --theme-text-dark: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, foreground), text,), $lightness: -25%)};
  --theme-text-fade-10: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, foreground), text,), $alpha: 0.1)};
  --theme-text-fade-20: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, foreground), text,), $alpha: 0.2)};
  --theme-text-fade-30: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, foreground), text,), $alpha: 0.3)};
  --theme-text-fade-40: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, foreground), text,), $alpha: 0.4)};
  --theme-text-fade-50: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, foreground), text,), $alpha: 0.5)};

  --theme-text-invert-15: #{color.invert(mat.m2-get-color-from-palette(map.get($theme, foreground), text,), 15%)};
  --theme-text-invert-30: #{color.invert(mat.m2-get-color-from-palette(map.get($theme, foreground), text,), 30%)};

  --theme-background: #{mat.m2-get-color-from-palette(map.get($theme, background), card)};
  --theme-background-lighter: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, background), card), $lightness: 6%)};
  --theme-background-light: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, background), card), $lightness: 10%)};
  --theme-background-darker: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, background), card), $lightness: -6%)};
  --theme-background-dark: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, background), card), $lightness: -10%)};
  --theme-background-darkest: #{color.adjust(mat.m2-get-color-from-palette(map.get($theme, background), card), $lightness: -14%)};

  // make background of search field transparent
  --mdc-filled-text-field-container-color: #0000;
  --mdc-filled-text-field-disabled-container-color: #0000;
}

@mixin snackbar($theme) {
  .mat-mdc-snack-bar-container {
    --mdc-snackbar-container-color: var(--theme-background-lighter);
    --mdc-snackbar-supporting-text-color: var(--theme-text);
  }

  .mat-mdc-snack-bar-container.errorBar {
    --mdc-snackbar-supporting-text-color: var(--theme-warn);
  }

  .mat-mdc-snack-bar-container.confirmBar {
    --mdc-snackbar-supporting-text-color: var(--theme-accent);
  }
}

@mixin google-button($theme) {
  .google-button {
    background-color: mat.m2-get-color-from-palette(map.get($theme, accent), darker) !important;
  }
}

@mixin overlay-theme($theme) {
  .overlay {
    background: mat.m2-get-color-from-palette(map.get($theme, primary), darker, 0.7);
  }
}

@mixin custom-components-theme($theme) {
  @include link-theme($theme);
  @include notification-theme($theme);
  @include image-thumbnail-theme($theme);
  @include score-star-theme($theme);
  @include snackbar($theme);
  @include google-button($theme);
  @include deluxe-membership-theme($theme);
  @include overlay-theme($theme);
}

$bg-hacking-instructor: rgba(0, 0, 0, 0.3);

.deeppurple-amber-theme {
  @include custom-components-theme($deeppurple-amber-theme);
  @include css-vars($deeppurple-amber-theme);
}

.indigo-pink-theme {
  @include custom-components-theme($indigo-pink-theme);
  @include css-vars($indigo-pink-theme);
}

.pink-bluegrey-theme {
  @include custom-components-theme($pink-bluegrey-theme);
  @include css-vars($pink-bluegrey-theme);
}

.purple-green-theme {
  @include custom-components-theme($purple-green-theme);
  @include css-vars($purple-green-theme);
}

.bluegrey-lightgreen-theme {
  @include custom-components-theme($bluegrey-lightgreen-theme);
  @include css-vars($bluegrey-lightgreen-theme);
}

.blue-lightblue-theme {
  @include custom-components-theme($blue-lightblue-theme);
  @include css-vars($blue-lightblue-theme);
}

.deeporange-indigo-theme {
  @include custom-components-theme($deeporange-indigo-theme);
  @include css-vars($deeporange-indigo-theme);
}

.lime-green-theme {
  @include custom-components-theme($lime-green-theme);
  @include css-vars($lime-green-theme);
}

.close-dialog {
  float: right;
  width: fit-content;
}

[hidden] {
  display: none !important;
}

.mat-expansion-panel-header {
  // If the panel, that the header is in, is inside an element being animated by Angular,
  // the default behavior is to block all child animations. This means that the header's
  // height won't kick in until the parent animation is done. We add a fallback to the
  // header's default height. If the animations aren't blocked, these styles will be overridden
  // by the inline styles from the animations module.
  .ng-animating .mat-expansion-panel & {
    min-height: 48px;
  }

  .ng-animating .mat-expansion-panel.mat-expanded & {
    min-height: 64px;
  }
}

.mat-expansion-panel-content {
  // If the expansion panel is inside an element being animated by Angular,
  // the default behavior is to block all child animations. This means that the
  // default `height: 0` won't kick in until the parent animation is over, which
  // will cause the panel to appear open, before it snaps into place. We don't want
  // to set the default height to zero, because it'll break the `height: '*'` from
  // the animation definitions. Instead we add a fallback that only applies only if
  // it's inside a parent that is mid-animation.
  .ng-animating .mat-expansion-panel:not(.mat-expanded) & {
    height: 0;
    overflow: hidden;
  }
}

#hacking-instructor code {
  background-color: $bg-hacking-instructor;
  border-radius: 1px;
  font-family: monospace;
  padding: 0 4px;
}

.CodeMirror {
  border-radius: 16px;
  height: 600px !important;
}

div.mdc-card {
  padding: 16px;
}

.mat-mdc-button {
  white-space: nowrap;
}
