import { useState, useCallback } from 'react' import { useRouter } from 'next/router' import { AnimatePresence, motion } from 'framer-motion' import { ArrowLeft, Database } from 'lucide-react' import { Button, cn } from 'ui' import { AiIconAnimation } from 'ui' import { useQuickstart } from '../legacy/useQuickstart' import { AiTableGenerator } from './AiTableGenerator' import { TemplateSelector } from './TemplateSelector' import { TablePreviewGrid } from './TablePreviewGrid' import { expandVariants, collapseVariants } from './animations' import type { TableSuggestion } from '../legacy/types' interface InlineTableQuickstartProps { variant: 'ai' | 'templates' projectRef: string onComplete?: () => void className?: string } type ViewState = 'collapsed' | 'expanded' | 'preview' export function InlineTableQuickstart({ variant, projectRef, onComplete, className, }: InlineTableQuickstartProps) { const router = useRouter() const [viewState, setViewState] = useState('collapsed') const [selectedVariant, setSelectedVariant] = useState<'ai' | 'templates' | null>(null) const { currentStep, candidates, loading, error, userInput, isGenerating, onTablesReady, handleAiGenerate, handleSelectTable: originalHandleSelect, handleBack, } = useQuickstart() // Handle expanding the card const handleExpand = useCallback((selectedVariant: 'ai' | 'templates') => { setSelectedVariant(selectedVariant) setViewState('expanded') }, []) // Handle collapsing back const handleCollapse = useCallback(() => { setViewState('collapsed') setSelectedVariant(null) }, []) // Handle table selection with completion callback const handleSelectTable = useCallback( async (table: TableSuggestion) => { await originalHandleSelect(table) onComplete?.() // Collapse the card first, then navigate setViewState('collapsed') setTimeout(() => { router.push(`/project/${projectRef}/editor`) }, 300) }, [originalHandleSelect, onComplete, projectRef, router] ) // Handle AI generation const handleAiGenerateWithTransition = useCallback( async (prompt: string) => { await handleAiGenerate(prompt) setViewState('preview') }, [handleAiGenerate] ) // Handle template selection const handleTemplateSelect = useCallback( (tables: TableSuggestion[], templateName: string) => { onTablesReady(tables, templateName) setViewState('preview') }, [onTablesReady] ) // Handle back from preview const handleBackFromPreview = useCallback(() => { handleBack() setViewState('expanded') }, [handleBack]) return (
{viewState === 'collapsed' && ( )} {viewState === 'expanded' && ( {selectedVariant === 'ai' ? ( ) : ( )} {error && (

{error}

)}
)} {viewState === 'preview' && candidates.length > 0 && (
{userInput && (

{isGenerating ? 'Generating tables for:' : 'Generated tables for:'}

{selectedVariant === 'templates' ? userInput : `"${userInput}"`}

)}
)}
) }