import Document, { DocumentContext, Head, Html, Main, NextScript, DocumentProps } from "next/document"; type Props = Record & DocumentProps; function toRunBeforeReactOnClient() { const calEmbedMode = location.search.includes("embed="); try { // eslint-disable-next-line @calcom/eslint/avoid-web-storage window.sessionStorage.setItem("calEmbedMode", String(calEmbedMode)); } catch (e) {} window.isEmbed = () => { try { // eslint-disable-next-line @calcom/eslint/avoid-web-storage return window.sessionStorage.getItem("calEmbedMode") === "true"; } catch (e) {} // If we can't use sessionStorage to retrieve embed mode, just use the variable. It would fail to detect embed if page in iframe reloads without embed query param in it. return calEmbedMode; }; window.resetEmbedStatus = () => { try { // eslint-disable-next-line @calcom/eslint/avoid-web-storage window.sessionStorage.removeItem("calEmbedMode"); } catch (e) {} }; window.getEmbedTheme = () => { const url = new URL(document.URL); return url.searchParams.get("theme") as "dark" | "light"; }; window.getEmbedNamespace = () => { const url = new URL(document.URL); const namespace = url.searchParams.get("embed"); return namespace; }; } class MyDocument extends Document { static async getInitialProps(ctx: DocumentContext) { const initialProps = await Document.getInitialProps(ctx); return { ...initialProps }; } render() { const { locale } = this.props.__NEXT_DATA__; const dir = locale === "ar" || locale === "he" ? "rtl" : "ltr"; return ( {/* Define isEmbed here so that it can be shared with App(embed-iframe) as well as the following code to change background and hide body Persist the embed mode in sessionStorage because query param might get lost during browsing. */}