import { type ReactNode, useEffect, useState } from "react"
import { type InitCustomBlockOptions, NotInIframeError } from "../index.js"
import { DebugMessageLog } from "./DebugMessageLog.js"
import { seedStandalonePreviewState } from "./standalonePreview.js"
import { useCustomBlockAutoResize } from "./useCustomBlockAutoResize.js"
import { useCustomBlockInit } from "./useCustomBlockInit.js"
import { useCustomBlockHost } from "./useHostState.js"
import "./NotionCustomBlock.css"
/**
* Props accepted by {@link NotionCustomBlock}.
*/
export type NotionCustomBlockProps = InitCustomBlockOptions & {
children: ReactNode
/**
* Rendered while the SDK ↔ host handshake is in progress. Defaults to
* `null` (nothing).
*/
fallback?: ReactNode
/**
* Rendered when the handshake fails. Either a node, or a function that
* receives the `Error`. When omitted, a friendly default error card is
* rendered with developer details — replace it for production templates.
*/
errorFallback?: ReactNode | ((error: Error) => ReactNode)
/**
* Whether the provider should automatically post resize messages so the
* host iframe matches the content height of `#root`. Defaults to `true`.
* Pass `false` when you want to use the default block size and are ok
* with scrollbars within the Notion client.
*
* @default true
*/
autoResize?: boolean
}
/**
* Top-level wrapper that runs the SDK ↔ host handshake and gates `children`
* until it resolves. Passes `timeoutMs` straight through to
* {@link initCustomBlock}.
*
* Templates that prefer not to write a `Root` gating component (or top-level
* `await`) can mount their app entirely inside this provider:
*
* ```tsx
* ReactDOM.createRoot(root).render(
*
This custom block loaded, but the setup handshake didn't finish. Try again from Notion. If this keeps happening, check the browser console for SDK details.
{error.message}