import { BookOpen, Code2, MousePointer2, Play, SlidersHorizontal, X } from 'lucide-react' import { Dialog, DialogClose, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import { useStudioLanguage } from '@/i18n' const runtimeInstallExample = 'npm install @bible-strong/avatar-react react react-dom' const webInstallExample = 'npm install @bible-strong/avatar-web' const webAvatarExample = ( animationKey: string | undefined ) => `import { createAvatar } from '@bible-strong/avatar-web' import definition from './avatar.avatar.json' const avatar = createAvatar('#avatar', { definition, ${animationKey ? `defaultAnimation: '${animationKey}',` : `defaultExpression: 'neutral',`} }) avatar.play(${animationKey ? `'${animationKey}'` : `'idle'`}) avatar.pause() avatar.setExpression('neutral') avatar.stop()` const nativeBrowserExample = `
` const createAvatarExample = ( animationKey: string | undefined ) => `import { createAvatar } from '@bible-strong/avatar-react' import '@bible-strong/avatar-react/styles.css' import avatarJson from './avatar.avatar.json' const StrobiAvatar = createAvatar(avatarJson) export function Strobi() { return }` const genericAvatarExample = `import { Avatar } from '@bible-strong/avatar-react' import type { AvatarDefinition, ExpressionKey } from '@bible-strong/avatar-core' import '@bible-strong/avatar-react/styles.css' export function DynamicAvatar({ definition, expression, }: { definition: AvatarDefinition expression: ExpressionKey }) { return ( console.error(error)} /> ) }` const imperativeExample = ( animationKey: string | undefined ) => `import { createAvatar, type AvatarController } from '@bible-strong/avatar-react' import { useRef } from 'react' import avatarJson from './avatar.avatar.json' const StrobiAvatar = createAvatar(avatarJson) export function Controls() { const avatar = useRef(null) return <> ${ animationKey ? ` ` : '' } }` const codeTokenPattern = /(\/\/.*|'.*?'|".*?"|@[a-z0-9-/]+|<\/?[A-Z][A-Za-z]*|\b(?:npm|install|import|from|const|if|throw|new|export|function|return|onClick|ref|useRef)\b)/g const highlightedCode = (source: string) => source.split(codeTokenPattern).map((token, index) => { if (!token) return null const kind = token.startsWith('//') ? 'comment' : token.startsWith("'") || token.startsWith('"') || token.startsWith('@') ? 'string' : token.startsWith('<') ? 'tag' : /^(?:npm|install|import|from|const|if|throw|new|export|function|return|onClick|ref|useRef)$/.test( token ) ? 'keyword' : 'plain' return ( {token} ) }) function GuideCode({ children }: { children: string }) { return (
      {highlightedCode(children)}
    
) } function PropRow({ name, type, description }: { name: string; type: string; description: string }) { return (
{name} {type}
{description}
) } export function RuntimeGuideDialog({ animationKey, integration = 'react', onOpenChange, open, }: { animationKey?: string integration?: 'react' | 'javascript' onOpenChange: (open: boolean) => void open: boolean }) { const { t } = useStudioLanguage() return (
{t('Guide d’utilisation')}
{t( integration === 'react' ? 'Guide d’utilisation de l’avatar React' : 'Guide d’utilisation de l’avatar JavaScript' )} {t( integration === 'react' ? 'Installe le package, crée ton composant et choisis le niveau de contrôle adapté.' : 'Installe le module ESM, charge la définition JSON et monte l’avatar dans un élément du DOM.' )} } />
{integration === 'react' ? ( <>

{t('Installation')}

{t('Ajoute le package React et ses dépendances.')}

{runtimeInstallExample}

{t( 'Les packages sont encore privés. Cette commande fonctionnera après leur publication ; utilise le workspace ou les tarballs pour les tests locaux.' )}

{t('API recommandée : créer un avatar concret')}

{t( 'createAvatar valide le JSON et retourne un composant dédié dont les clés d’animations sont typées.' )}

{createAvatarExample(animationKey)}

{t('Props de l’avatar')}

{t( 'Référence complète : type, valeur par défaut, comportement et contraintes de chaque prop.' )}

{t('Cible et lecture')}
{t('Présentation')}
{t('Callbacks de lecture')}

{t('Avatar générique')}

{t( 'Utilise Avatar directement lorsque la définition est chargée à l’exécution ou change entre plusieurs avatars.' )}

{genericAvatarExample}

{t('API impérative')}

{t('La ref expose les commandes de lecture et l’état courant de l’avatar.')}

{t( 'Les commandes de cible sont disponibles en mode non contrôlé ; sinon utilise les props.' )}

{imperativeExample(animationKey)}
) : ( <>

{t('Installation')}

{t('Ajoute le renderer DOM, qui utilise automatiquement avatar-core.')}

{webInstallExample}

{t( 'Les packages sont encore privés. Cette commande fonctionnera après leur publication ; utilise le workspace ou les tarballs pour les tests locaux.' )}

{t('Utilisation avec un bundler ESM')}

{t( 'Vite et les bundlers modernes résolvent le package et importent le même fichier .avatar.json que React.' )}

{webAvatarExample(animationKey)}

{t('Options de createAvatar')}

{t('Référence des valeurs acceptées lors du montage dans le DOM.')}

{t('API du contrôleur DOM')}

{t('createAvatar retourne immédiatement ces commandes impératives.')}

{t('Navigateur sans bundler')}

{t( 'Utilise une URL ESM via un CDN ou une import map, puis charge la définition avec fetch.' )}

{nativeBrowserExample}
)}
{t('Fermer le guide')}} />
) }