import 'core-js/modules/es.array.iterator.js';
import 'core-js/modules/web.dom-collections.iterator.js';
import { createTheme } from '@mui/material';
import { createPalette } from './colors.js';
import { breakpoints } from './breakpoints.js';
import { overrideComponents } from './components.js';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const ThemeCache = new Map();
const createAppTheme = colorMode => {
  if (ThemeCache.has(colorMode)) {
    return ThemeCache.get(colorMode);
  }
  const theme = createTheme({
    palette: createPalette(colorMode),
    breakpoints
  });
  theme.shadows[1] = '0px 0px 20px rgba(0, 0, 0, 0.15)';
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  //@ts-ignore
  theme.components = overrideComponents(theme);
  ThemeCache.set(colorMode, theme);
  return theme;
};

export { createAppTheme as default };
