import { useState, useCallback, useEffect } from 'react' import { Sparkles, ArrowRight, PencilRuler, Wand2, X } from 'lucide-react' import { networkDiagramsApi } from '@/api' import type { AIGenerateResponse } from '@/types' const EXAMPLE_PROMPTS = [ 'Small office with firewall and core switch', 'Azure hybrid cloud with VPN gateway', 'Branch office connected to HQ via MPLS', 'Data center with redundant core switches', 'Remote workforce with Meraki and cloud apps', ] interface CanvasEmptyPromptProps { onGenerate: (result: AIGenerateResponse, mode: 'replace' | 'merge') => void } export function CanvasEmptyPrompt({ onGenerate }: CanvasEmptyPromptProps) { const [mode, setMode] = useState<'choice' | 'ai' | 'manual'>('choice') const [description, setDescription] = useState('') const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const switchToManual = useCallback(() => { if (loading) return setMode('manual') setError(null) }, [loading]) const handleGenerate = useCallback(async (text?: string) => { const desc = (text ?? description).trim() if (!desc) return setLoading(true) setError(null) try { const result = await networkDiagramsApi.aiGenerate({ description: desc, mode: 'replace', existingBounds: null, }) onGenerate(result, 'replace') } catch (err: unknown) { setError(err instanceof Error ? err.message : 'Generation failed. Please try again.') } finally { setLoading(false) } }, [description, onGenerate]) useEffect(() => { if (mode === 'manual') return const handleKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape') { event.preventDefault() switchToManual() } } window.addEventListener('keydown', handleKeyDown) return () => window.removeEventListener('keydown', handleKeyDown) }, [mode, switchToManual]) if (mode === 'manual') { return (

Manual mode is on

Drag devices from the left panel onto the canvas, or reopen AI whenever you want.

) } return (
{ if (event.target === event.currentTarget) { switchToManual() } }} >
{mode === 'choice' ? ( <>

Start a network map

Generate a topology with AI or start with a blank canvas and build it manually.

Press Esc or click outside to skip AI and start dragging devices.

) : ( <>

Describe your network

AI will generate the topology in seconds, or you can go back and switch to manual creation.

Press Esc, click outside, or use the close button to build manually instead.