import React, { Suspense } from "react"; import type { HighlightedCode, AnnotationHandler } from "codehike/code"; import { InnerLine, Pre } from "codehike/code"; import { Theme } from "@code-hike/lighter"; import { Text } from "../../writer/Text" import { CodeTheme, type CodeThemeBlockProps } from "../CodeTheme"; import * as cn from "./Code.styles"; import { CodeLoader } from "./CodeLoader"; import { Icon } from "src/writer/Icon"; import {useCodeSampleAnalytics} from "../CodeSample/CodeSampleAnalytics"; export interface CodeProps { codeblocks?: CodeThemeBlockProps[]; theme?: Theme children: React.ReactNode } export function Code(props: CodeProps) { return }> {props.children} } // TODO: fix any Code.LineNumber = function CodeLineNumber(props: any) { if (!props.children || !props.children.length) { return null } return ( {props.lineNumber} ) } // TODO: fix any Code.Mark = function CodeMark(props: any) { return } Code.MarkInline = function CodeMarkInline(props: any) { return ( {props.children} ) } // TODO: fix any Code.Bg = function CodeLine(props: any) { return {props.children} } Code.Pre = function CodePre(props: { codeblock: HighlightedCode, size?: "full", handlers: AnnotationHandler[], className?: string, descriptionHead?: string | React.ReactNode, descriptionContent?: string | React.ReactNode, descriptionIcon?: string } ) { const codeSampleAnalytics = useCodeSampleAnalytics() const { size, className, codeblock, handlers, } = props; fixLastToken(codeblock) // the
 is the element that scrolls, so it's the one that has to be focusable - name it
    // with the same `meta || lang` the tabs use, otherwise it reads as an unlabelled region
    const label = codeblock?.meta || codeblock?.lang

    let description: React.ReactNode | null = null
    
    if (props.descriptionHead || props.descriptionContent) {
        description = 
{props.descriptionIcon ? : <_DefaultDescriptionIcon />}
{props.descriptionHead} {props.descriptionContent}
} return

        {description}
    
}

/**
 * FOR SOME REASONS FOR SINGLE CODE BLOCKS LAST TOKEN IS EMPTY STRING
 * 
 * @todo: fix this
 */
function fixLastToken(codeblock: HighlightedCode) {
    const lastToken = codeblock.tokens[codeblock.tokens.length - 1]
    if (typeof lastToken === 'string' && (lastToken === ' ' || lastToken === '\n')) {
        codeblock.tokens.pop()
    }
}

function _DefaultDescriptionIcon() {
    return 
        
        
        
        
        
        
        
    
}