@use '@angular/material' as mat;
@import 'src/projects/core/src//components/search-bar/_search-bar.theme';
@import 'src/projects/core/src//components/core-toolbar/_core-toolbar.theme';
@import 'src/projects/core/src//components/list/_list.theme';
@import 'src/projects/core/src//scss/material-override/material-override.theme';
@import 'src/projects/core/src//scss/ag.theme';
@import 'src/projects/core/src//scss/scroll-bar';
@import 'src/projects/core/src//scss/dialog';

@mixin mw-core-theme($theme) {
  $primary: map-get($theme, primary);
  $is-dark-theme: map-get($theme, is-dark);

  $background: map-get($theme, background);
  $foreground: map-get($theme, foreground);

  $foreground: map_merge(
    $foreground,
    (
      secondary-text:
        mat.get-color-from-palette(
          $foreground,
          secondary-text,
          if($is-dark-theme, 0.7, 0.6)
        ),
      disabled-text:
        mat.get-color-from-palette(
          $foreground,
          disabled-text,
          if($is-dark-theme, 0.38, 0.26)
        ),
    )
  );

  $background: map-merge(
    $background,
    (
      card: if($is-dark-theme, var(--graphite800), white),
    )
  );

  $theme: map_merge(
    $theme,
    (
      foreground: $foreground,
    )
  );

  @include mw-material-theme($theme);
  @include mw-search-bar-theme($theme);
  @include mw-core-toolbar-theme($theme);
  @include mw-list-theme($theme);
  @include mw-material-override-theme($theme);
  @include mw-ag-grid-theme($theme);
  @include mw-create-css-palettes($theme);

  $text: if($is-dark-theme, white, rgba(black, 0.87));
  $text-light: white;
  $text-dark: rgba(black, 0.87);
  $secondary-text: rgba(if($is-dark-theme, white, black), 0.6);
  $secondary-text-light: rgba(white, 0.6);
  $secondary-text-dark: rgba(black, 0.6);
  $accent: map-get($theme, accent);
  $disabled-text: rgba(if($is-dark-theme, white, black), 0.26);
  $disabled-text-light: rgba(white, 0.26);
  $disabled-text-dark: rgba(black, 0.26);
  $placeholder-text: rgba(if($is-dark-theme, white, black), 0.26);
  $placeholder-text-light: rgba(white, 0.26);
  $placeholder-text-dark: rgba(black, 0.26);

  --mw-is-dark-theme: #{$is-dark-theme};
  --mw-divider-light: rgba(255, 255, 255, 0.12);
  --mw-divider-dark: rgba(0, 0, 0, 0.12);
  --mw-divider: #{if(
      $is-dark-theme,
      var(--mw-divider-light),
      var(--mw-divider-dark)
    )};
  --mw-accent: #{mat-color($accent)};
  --mw-primary: #{mat-color($primary)};
  --mw-card: #{map-get($background, card)};
  --mw-base: #{if($is-dark-theme, 255, 0)};
  --mw-text: #{$text};
  --mw-text-dark: #{$text-dark};
  --mw-text-light: #{$text-light};
  --mw-secondary-text: #{$secondary-text};
  --mw-secondary-text-light: #{$secondary-text-light};
  --mw-secondary-text-dark: #{$secondary-text-dark};
  --mw-disabled-text: #{$disabled-text};
  --mw-disabled-text-light: #{$disabled-text-light};
  --mw-disabled-text-dark: #{$disabled-text-dark};
  --mw-placeholder-text: #{$placeholder-text};
  --mw-placeholder-text-light: #{$placeholder-text-light};
  --mw-placeholder-text-dark: #{$placeholder-text-dark};
  --mw-primary-background: #{if($is-dark-theme, black, white)};
  --mw-secondary-background: #{if($is-dark-theme, black, var(--gray100))};

  background-color: map-get($background, card);
  color: var(--mw-text);

  .mw-dark-theme {
    --mw-card: var(--graphite800);
    --mw-text: var(--mw-text-light);
    --mw-secondary-text: var(--mw-secondary-text-light);
    --mw-disabled-text: var(--mw-disabled-text-light);
    --mw-placeholder-text: var(--mw-placeholder-text-light);
    --mw-divider: var(--mw-divider-light);
    color: var(--mw-text);
  }

  .mw-light-theme {
    --mw-card: white;
    --mw-text: var(--mw-text-dark);
    --mw-secondary-text: var(--mw-secondary-text-dark);
    --mw-disabled-text: var(--mw-disabled-text-dark);
    --mw-placeholder-text: var(--mw-placeholder-text-dark);
    --mw-divider: var(--mw-divider-dark);
    color: var(--mw-text);
  }

  .mw-card {
    background-color: var(--mw-card);
  }

  .mw-accent-text-color {
    color: mat.get-color-from-palette($accent);
  }

  .mw-text-color {
    color: var(--mw-text);
  }

  .mw-text-color-light {
    color: var(--mw-text-light);
  }

  .mw-text-color-dark {
    color: var(--mw-text-dark);
  }

  .mw-secondary-text-color {
    color: var(--mw-secondary-text);
  }

  .mw-secondary-text-color-light {
    color: var(--mw-secondary-text-light);
  }

  .mw-secondary-text-color-dark {
    color: var(--mw-secondary-text-dark);
  }

  .mw-disabled-text-color {
    color: var(--mw-disabled-text);
  }

  .mw-placeholder-text-color {
    color: var(--mw-placeholder-text);
  }

  .mw-default-text-color {
    color: var(--mw-text);
  }

  .mw-error,
  .mw-error .mat-icon {
    color: var(--red500);
  }
}
