@use 'sass:map';
@use 'sass:meta';
@use '../all-theme';
@use '../../m2/typography' as m2-typography;
@use '../../m2/palette' as m2-palette;
@use '../../m2/theming' as m2-theming;

// Recursively replaces all of the values inside a Sass map with a different value.
@function _replace-all-values($palette, $replacement) {
  $output: ();

  @each $key, $value in $palette {
    @if $key != _mat-theming-internals-do-not-access {
      @if (meta.type-of($value) == 'map') {
        $output: map.merge(($key: _replace-all-values($value, $replacement)), $output);
      }
 @else {
        $output: map.merge(($key: $replacement), $output);
      }
    }
  }

  @return $output;
}

// Theme used to test that our themes would compile if the colors were specified as CSS variables.
._demo-css-variables-theme {
  $palette: m2-theming.define-palette(m2-palette.$blue-grey-palette);
  $theme: m2-theming.define-dark-theme((
    color: (
      primary: $palette,
      accent: $palette,
      warn: $palette
    ),
    typography: m2-typography.define-typography-config(),
  ));
  $css-var-theme: _replace-all-values($theme, var(--test-var));
  @include all-theme.all-component-themes($css-var-theme);
}
