import { Box, useBoolean } from '@chakra-ui/react'
import dynamic from 'next/dynamic'
import theme from 'prism-react-renderer/themes/nightOwl'
import React, { useEffect } from 'react'
import CodeContainer from './code-container'
import CopyButton from './copy-button'
import Highlight from './highlight'
const ReactLiveBlock = dynamic(() => import('./react-live-block'))
function CodeBlock(props) {
const [isMounted, { on }] = useBoolean()
useEffect(
/**
* Lazily-load to save bundle size.
*/
on,
[on],
)
const {
className,
live = true,
manual,
render,
children,
viewlines,
ln,
mountStylesheet = false,
} = props.children.props
const _live = live === 'true' || live === true
const language = className?.replace(/language-/, '')
const rawCode = children.trim()
const reactLiveBlockProps = {
rawCode,
language,
theme,
noInline: manual,
mountStylesheet,
}
if (isMounted && language === 'jsx' && _live === true) {
return
}
if (isMounted && render) {
/**
* @TODO Not sure if this is even used?
*/
return (
)
}
return (
)
}
export default CodeBlock