{"size": 1413, "ext": "js", "max_stars_repo_path": "hyperglass/ui/components/HyperglassProvider.js", "max_stars_repo_name": "samip5/hyperglass", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hyperglass/ui/components/HyperglassProvider.js", "max_issues_repo_name": "samip5/hyperglass", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hyperglass/ui/components/HyperglassProvider.js", "max_forks_repo_name": "samip5/hyperglass", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.8604651163, "max_line_length": 79, "alphanum_fraction": 0.7027600849}
import * as React from "react";
import { createContext, useContext, useMemo, useState } from "react";
import dynamic from "next/dynamic";
import { CSSReset, ThemeProvider } from "@chakra-ui/core";
import _useMedia, { MediaProvider } from "~/components/MediaProvider";
import {
  StateProvider,
  useHyperglassState as _useHyperglassState
} from "~/components/StateProvider";
import { makeTheme, defaultTheme } from "~/theme";

// Disable SSR for ColorModeProvider
const ColorModeProvider = dynamic(
  () => import("@chakra-ui/core").then(mod => mod.ColorModeProvider),
  { ssr: false }
);

const HyperglassContext = createContext(null);

export const HyperglassProvider = ({ config, children }) => {
  const value = useMemo(() => config, [config]);
  const userTheme = value && makeTheme(value.web.theme);
  const theme = value ? userTheme : defaultTheme;
  return (
    <HyperglassContext.Provider value={value}>
      <ThemeProvider theme={theme}>
        <ColorModeProvider value={config.web.theme.default_color_mode ?? null}>
          <CSSReset />
          <MediaProvider theme={theme}>
            <StateProvider>{children}</StateProvider>
          </MediaProvider>
        </ColorModeProvider>
      </ThemeProvider>
    </HyperglassContext.Provider>
  );
};

export default () => useContext(HyperglassContext);

export const useHyperglassState = _useHyperglassState;

export const useMedia = _useMedia;
