'use client'; import { useState, type ReactNode } from 'react'; import Link from 'next/link'; import { TemplatePicker } from './TemplatePicker'; import { NameStep } from './NameStep'; import { QuickChat } from './QuickChat'; import { type BotTemplate, getTemplateById } from '@/lib/bot-templates'; type Step = 'pick' | 'name' | 'chat'; interface CreatedBot { template: BotTemplate; name: string; systemPrompt: string; } interface QuickCreateFlowProps { /** Shown above the progress bar while the reader is still choosing a template. */ intro?: ReactNode; /** Shown under the template picker while the reader is still choosing. */ outro?: ReactNode; } /** * The three-step "pick a template → name it → chat" flow. * * One component behind both /create and /personal — they differ only in the * copy around the picker, which the pages pass in. */ export function QuickCreateFlow({ intro, outro }: QuickCreateFlowProps) { const [step, setStep] = useState('pick'); const [selectedTemplate, setSelectedTemplate] = useState(null); const [createdBot, setCreatedBot] = useState(null); const handleTemplateSelect = (templateId: string) => { const template = getTemplateById(templateId); if (template) { setSelectedTemplate(template); setStep('name'); } }; const handleNameSubmit = (name: string, additionalContext?: string) => { if (!selectedTemplate) return; // Build the system prompt from template const systemPrompt = selectedTemplate.systemPromptTemplate .replace('{{name}}', name) .replace('{{additional_context}}', additionalContext || ''); setCreatedBot({ template: selectedTemplate, name, systemPrompt, }); setStep('chat'); }; const handleBack = () => { if (step === 'name') { setStep('pick'); setSelectedTemplate(null); } else if (step === 'chat') { setStep('name'); } }; const handleReset = () => { setStep('pick'); setSelectedTemplate(null); setCreatedBot(null); }; return (
{/* Background Effects */}
{/* Header */}
Back to Home {step !== 'pick' && ( )}
{step === 'pick' && intro} {/* Progress Indicator */}
1
Choose
2
Name
3
Chat
{/* Step Content */} {step === 'pick' && } {step === 'name' && selectedTemplate && ( )} {step === 'chat' && createdBot && } {step === 'pick' && outro}
); }