{% extends "web/pages/base_page.js.jinja2" %}
{% from "web/pages/macros.js.jinja2" import renderHooks %}

{% block early_imports %}
import '$/styles/styles.css'
{% endblock %}

{% block declaration %}
import { EventLoopProvider, StateProvider, defaultColorMode } from "$/utils/context.js";
import { ThemeProvider } from 'next-themes'
{% for library_alias, library_path in  window_libraries %}
import * as {{library_alias}} from "{{library_path}}";
{% endfor %}

{% for custom_code in custom_codes %}
{{custom_code}}
{% endfor %}
{% endblock %}

{% block export %}
function AppWrap({children}) {
  {{ renderHooks(hooks) }}

  return (
    {{utils.render(render, indent_width=0)}}
  )
}

export default function MyApp({ Component, pageProps }) {
  React.useEffect(() => {
    // Make contexts and state objects available globally for dynamic eval'd components
    let windowImports = {
{% for library_alias, library_path in  window_libraries %}
      "{{library_path}}": {{library_alias}},
{% endfor %}
    };
    window["__reflex"] = windowImports;
  }, []);
  return (
    <ThemeProvider defaultTheme={ defaultColorMode } attribute="class">
      <StateProvider>
        <EventLoopProvider>
            <AppWrap>
              <Component {...pageProps} />
            </AppWrap>
        </EventLoopProvider>
      </StateProvider>
    </ThemeProvider>
  );
}

{% endblock %}
