import React, { useState } from 'react'
import Svg from './svg'
import Defs from './defs'
import Part from './part'
import theme from 'pkgs/plugin-theme/src/index.js'
import Robot from 'shared/components/robot/index.js'
import Error from './error.js'
import Events from './events.js'
import Json from 'shared/components/json.js'
import Yaml from 'shared/components/yaml.js'
import { capitalize } from 'shared/utils.js'
const tabClasses = active => `
tab tab-bordered font-bold text-4xl pb-12 capitalize
${active && 'text-base-content tab-active'}
`
const Wrap = props =>
{props.children}
const LabDraft = props => {
const { app, pattern, gist, updateGist, unsetGist } = props
const [tab, setTab] = useState(props.pattern.config.name)
const patternInstance = new pattern(gist)
const eprops = { ...props, patternInstance }
if (gist?.renderer === 'svg') patternInstance.use(theme)
// Catch errors
try { patternInstance.draft() }
catch(error) {
console.log('Failed to draft pattern', error)
return
}
// Render as SVG
let svg
try { svg = patternInstance.render() }
catch(error) {
console.log('Failed to render pattern', error)
return
}
if (gist?.renderer === 'svg')
return
// Render as React
let patternProps = {}
try { patternProps = patternInstance.draft().getRenderProps() }
catch(error) {
console.log('Failed to get render props for pattern', error)
return
}
return (
{[props.pattern.config.name, 'events', 'yaml', 'json'].map(name => )}
{tab === 'events' &&
}
{tab === 'json' &&
{JSON.stringify(props.gist, null, 2)}}
{tab === 'yaml' &&
}
{tab === props.pattern.config.name && (
)}
)
}
export default LabDraft