{% extends "web/pages/base_page.js.jinja2" %}

{% 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}) {

  {% for hook in hooks %}
  {{ hook }}
  {% endfor %}

  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">
      <AppWrap>
        <StateProvider>
          <EventLoopProvider>
            <Component {...pageProps} />
          </EventLoopProvider>
        </StateProvider>
      </AppWrap>
    </ThemeProvider>
  );
}

{% endblock %}
