import React, { useState, useEffect } from 'react'; import { Search, ArrowRight, Loader2, Globe, Link as LinkIcon, Languages, Upload, FileText, X, FolderOpen, FileUp, History, Clock, Trash2 } from 'lucide-react'; import { Language, AnalysisResult, SearchStrategy } from '../types'; import { parseMarkdownReport } from '../utils/reportParser'; import { listProjects, loadProject, deleteProject } from '../services/geminiService'; interface StepInputProps { onSearch: (url: string, context: string, market: string, language: Language) => void; onLoadReport: (strategy: SearchStrategy, results: AnalysisResult[]) => void; isLoading: boolean; } const COUNTRIES = [ "Germany", "Austria", "Switzerland", "United Kingdom", "France", "Spain", "Italy", "Netherlands", "Europe (General)", "USA" ]; export const StepInput: React.FC = ({ onSearch, onLoadReport, isLoading }) => { const [activeMode, setActiveMode] = useState<'new' | 'load'>('new'); const [url, setUrl] = useState(''); const [fileContent, setFileContent] = useState(''); const [fileName, setFileName] = useState(''); const [market, setMarket] = useState(COUNTRIES[0]); const [language, setLanguage] = useState('de'); const [recentProjects, setRecentProjects] = useState([]); const [isLoadingProjects, setIsLoadingProjects] = useState(false); const [showHistory, setShowHistory] = useState(false); const fetchProjects = async () => { setIsLoadingProjects(true); try { const projects = await listProjects(); setRecentProjects(projects); } catch (e) { console.error("Failed to load projects", e); } finally { setIsLoadingProjects(false); } }; useEffect(() => { if (showHistory) { fetchProjects(); } }, [showHistory]); const handleProjectSelect = async (projectId: string) => { try { const projectData = await loadProject(projectId); // Check for full project data first if (projectData && (projectData.strategy || projectData.competitors)) { onLoadReport(projectData, []); // Pass full object, let App.tsx handle hydration logic } else { alert("Project data is incomplete or corrupted."); } } catch (e) { console.error(e); alert("Failed to load project."); } }; const handleDeleteProject = async (e: React.MouseEvent, projectId: string) => { e.stopPropagation(); // Prevent loading the project if (confirm("Are you sure you want to delete this project?")) { try { await deleteProject(projectId); fetchProjects(); // Refresh list } catch (error) { console.error("Failed to delete", error); alert("Failed to delete project."); } } }; const handleFileUpload = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (file) { const reader = new FileReader(); reader.onload = (event) => { setFileContent(event.target?.result as string); setFileName(file.name); }; reader.readAsText(file); } }; const handleLoadReport = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (file) { const reader = new FileReader(); reader.onload = (event) => { const content = event.target?.result as string; const parsed = parseMarkdownReport(content); if (parsed) { onLoadReport(parsed.strategy, parsed.results); } else { alert("Could not parse report. Please make sure it's a valid ProspectIntel MD file."); } }; reader.readAsText(file); } }; const handleRemoveFile = () => { setFileContent(''); setFileName(''); }; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (url.trim() && fileContent.trim()) { onSearch(url.trim(), fileContent.trim(), market, language); } }; return (

Market Intelligence Agent

{activeMode === 'new' ? (

Upload your Strategy Document to let AI design the perfect market audit.

) : (

Select an exported .md Report to continue working on an existing analysis.

)}
{activeMode === 'new' ? (
{/* Form Fields (kept same) */}
{!fileContent ? (
) : (

{fileName}

Context loaded successfully

)}
setUrl(e.target.value)} placeholder="e.g. https://www.reference-customer.com" className="w-full pl-12 pr-4 py-3 rounded-xl border border-slate-200 focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 outline-none transition-all text-lg" required />

Used to calibrate the search and find lookalikes.

) : (

Note:

Loading an existing audit will take you directly to the Report view. You can then trigger new outreach campaigns for any company in the list.

)}
{/* History Modal */} {showHistory && (

Project History

{isLoadingProjects ? (
) : recentProjects.length > 0 ? ( recentProjects.map((p) => ( )) ) : (
No past projects found.
)}
)}
); };