'use client'

import { createContext, useContext } from 'react'

interface DocsPageContext {
    markdown: string | null
    atUri: string | null
}

const DocsMarkdownContext = createContext<DocsPageContext>({ markdown: null, atUri: null })

export function DocsMarkdownProvider({ markdown, atUri, children }: { markdown: string; atUri?: string; children: React.ReactNode }) {
    return (
        <DocsMarkdownContext.Provider value={{ markdown, atUri: atUri ?? null }}>
            {children}
        </DocsMarkdownContext.Provider>
    )
}

export function useDocsMarkdown() {
    return useContext(DocsMarkdownContext).markdown
}

export function useDocsAtUri() {
    return useContext(DocsMarkdownContext).atUri
}