import { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import type { AutoRhythm, AutoWritingConfig, SettingEntry, WizardWritingConfig } from '@shared/types' import { ipcCall } from '@renderer/lib/ipc-client' import { useWizardStore } from '@renderer/stores/useWizardStore' import { ContextEditorModal } from '@renderer/components/ai/ContextEditorModal' import { useAiStore } from '@renderer/stores/useAiStore' interface WizardPanelProps { bookId: string sessionId: string | null disabled: boolean } const RHYTHMS: AutoRhythm[] = ['relaxed', 'tense', 'mixed'] export function WizardPanel({ bookId, sessionId, disabled }: WizardPanelProps): React.JSX.Element { const { t } = useTranslation() const { flow, previewHtml, streaming, streamBuffer, loadFlow, start, setGoal, setRhythm, setPov, confirmContext, buildPreview, startGenerate, mount, unmount } = useWizardStore() const [goal, setGoalText] = useState('') const [wordMin, setWordMin] = useState(2000) const [wordMax, setWordMax] = useState(4000) const [rhythm, setRhythmVal] = useState('mixed') const [styleNote, setStyleNote] = useState('') const [characters, setCharacters] = useState([]) const [povId, setPovId] = useState('') const [contextOpen, setContextOpen] = useState(false) useEffect(() => { mount() return () => unmount() }, [mount, unmount]) useEffect(() => { if (bookId && sessionId) void loadFlow(bookId, sessionId) }, [bookId, sessionId, loadFlow]) useEffect(() => { if (!bookId) return void ipcCall(() => window.electronAPI.setting.list(bookId)).then((list) => { setCharacters(list.filter((s) => s.type === 'character')) }) }, [bookId]) if (!sessionId || !flow) { return (

{t('ai.noSession')}

) } const step = flow.step const config = flow.modeConfig as WizardWritingConfig const handleContextClose = (): void => { setContextOpen(false) const session = useAiStore.getState().sessions.find( (s) => s.id === useAiStore.getState().activeSessionId ) if (session) void confirmContext(bookId, session.context) } return ( <>
{t('wizard.step.goal')} → {t('wizard.step.rhythm')} → {t('wizard.step.pov')} →{' '} {t('wizard.step.context')} → {t('wizard.step.preview')}
{step === 'wizard_goal' && (