import { platform } from "@todesktop/client-core"; import type { IncomingMessage } from "http"; import { dir } from "i18next"; import type { DocumentContext, DocumentProps } from "next/document"; import Document, { Head, Html, Main, NextScript } from "next/document"; import { IS_PRODUCTION } from "@calcom/lib/constants"; import { applyTheme, applyToDesktopClass } from "./../lib/pages/document/_applyThemeForDocument"; type Props = Record & DocumentProps & { newLocale: string }; class MyDocument extends Document { static async getInitialProps(ctx: DocumentContext) { const getLocaleModule = ctx.req ? await import("@calcom/features/auth/lib/getLocale") : null; const newLocale = ctx.req && getLocaleModule ? // eslint-disable-next-line @typescript-eslint/no-explicit-any await getLocaleModule.getLocale(ctx.req as IncomingMessage & { cookies: Record }) : "en"; const asPath = ctx.asPath || ""; // Use a dummy URL as default so that URL parsing works for relative URLs as well. We care about searchParams and pathname only const parsedUrl = new URL(asPath, "https://dummyurl"); const isEmbedSnippetGeneratorPath = parsedUrl.pathname.startsWith("/event-types"); // FIXME: Revisit this logic to remove embedType query param check completely. Ideally, /embed should always be there at the end of the URL. Test properly and then remove it. const isEmbed = (parsedUrl.pathname.endsWith("/embed") || parsedUrl.searchParams.get("embedType") !== null) && !isEmbedSnippetGeneratorPath; const embedColorScheme = parsedUrl.searchParams.get("ui.color-scheme"); const initialProps = await Document.getInitialProps(ctx); return { isEmbed, embedColorScheme, ...initialProps, newLocale }; } render() { const { isEmbed, embedColorScheme } = this.props; const newLocale = this.props.newLocale || "en"; const newDir = dir(newLocale); const isDesktopApp = (() => { try { return platform.todesktop.isDesktopApp(); } catch { return false; } })(); return (