var _style, _style2, _style3, _style4;
import * as React from 'react';
import { documentGetInitialProps } from '@mui/material-nextjs/v13-pagesRouter';
import createEmotionCache from "../DocsApp/createEmotionCache.js";
import { pathnameToLanguage } from "../helpers/helpers.js";
import { jsx as _jsx } from "react/jsx-runtime";
export function createGetInitialProps({
  setupStyledComponents = false
}) {
  async function getInitialPropsDocument(ctx) {
    const styledComponentsSheet = setupStyledComponents ? new (await import('styled-components')).ServerStyleSheet() : null;
    try {
      const finalProps = await documentGetInitialProps(ctx, {
        emotionCache: createEmotionCache(),
        plugins: styledComponentsSheet ? [{
          enhanceApp: App => props => styledComponentsSheet.collectStyles(/*#__PURE__*/_jsx(App, {
            ...props
          })),
          resolveProps: async initialProps => ({
            ...initialProps,
            styles: [styledComponentsSheet.getStyleElement(), ...React.Children.toArray(initialProps.styles)]
          })
        }] : []
      });

      // All the URLs should have a leading /.
      // This is missing in the Next.js static export.
      let url = ctx.req?.url;
      if (url && url[url.length - 1] !== '/') {
        url += '/';
      }
      const isProd = process.env.DEPLOY_ENV === 'production' || process.env.DEPLOY_ENV === 'staging';
      const google = isProd ? 'G-5NXDQLC2ZK' : 'G-XJ83JQEK7J';
      const apollo = isProd ? '691c2e920c5e20000d7801b6' : 'dev-id';
      return {
        ...finalProps,
        canonicalAsServer: pathnameToLanguage(url ?? '').canonicalAsServer,
        analytics: {
          google,
          apollo
        },
        userLanguage: ctx.query.userLanguage || 'en',
        styles: [_style || (_style = /*#__PURE__*/_jsx("style", {
          id: "material-icon-font"
        }, "material-icon-font")), _style2 || (_style2 = /*#__PURE__*/_jsx("style", {
          id: "font-awesome-css"
        }, "font-awesome-css")), ...finalProps.emotionStyleTags, _style3 || (_style3 = /*#__PURE__*/_jsx("style", {
          id: "app-search"
        }, "app-search")), _style4 || (_style4 = /*#__PURE__*/_jsx("style", {
          id: "prismjs"
        }, "prismjs")), ...React.Children.toArray(finalProps.styles)]
      };
    } finally {
      if (styledComponentsSheet) {
        styledComponentsSheet.seal();
      }
    }
  }
  return getInitialPropsDocument;
}