import React, { useState, useEffect } from 'react'; import { AstroData } from '../types'; import { summarizeAstroData, extractErrorMessage } from '../services/geminiService'; import { VEDIC_KNOWLEDGE_BASE, MASTER_LIFE_LESSONS_PROMPT } from '../services/astroWorkflow'; import { Loader2, CheckCircle2, ShieldCheck, Copy, Check, ShieldAlert, Sparkles } from 'lucide-react'; import ReactMarkdown from 'react-markdown'; import { motion } from 'motion/react'; import { useAstroContext } from '../context/AstroContext'; import ModelSelector from './ModelSelector'; interface Props { userData: AstroData; onComplete: (summary: string) => void; } export default function TechnicalRoadmap({ userData, onComplete }: Props) { const { state, setScreen, setModelPreference, setStepError } = useAstroContext(); const [loading, setLoading] = useState(false); const [summary, setSummary] = useState(''); const [modelName, setModelName] = useState(''); const [copiedKey, setCopiedKey] = useState(null); const [masterPromptCopied, setMasterPromptCopied] = useState(false); const [auditVerified, setAuditVerified] = useState(false); const selectedModel = state.modelPreferences['screen2'] || 'gemini-2.5-flash'; const currentError = state.lastError['screen2']; const getSummary = async (retryModel?: string) => { try { setLoading(true); setStepError('screen2', null); const targetModel = retryModel || selectedModel; const result = await summarizeAstroData(userData, targetModel); setSummary(result.text); setModelName(result.model); onComplete(result.text); } catch (err: any) { console.error(err); setStepError('screen2', extractErrorMessage(err)); } finally { setLoading(false); } }; useEffect(() => { if (userData.summary) { setSummary(userData.summary); setLoading(false); return; } if (summary || loading || currentError) return; getSummary(); }, [userData, summary, onComplete]); const handleModelChange = (modelId: string) => { setModelPreference('screen2', modelId); // Automatically trigger reload if we had an error if (currentError) { getSummary(modelId); } }; const parseSections = (text: string) => { const findSection = (id: string) => { // Loosened regex to handle bolding, different spacing, and variant formatting const regex = new RegExp(`(?:^|\\n)(?:#+)?\\s*(?:\\*\\*)?\\s*(?:SECTION|Step)\\s*${id}\\b[\\s\\S]*?(?=\\n(?:#+)?\\s*(?:\\*\\*)?\\s*(?:SECTION|Step)|$)`, 'i'); const match = text.match(regex); return match ? match[0].trim() : ''; }; const sections = { step1: findSection('1'), step2_1: findSection('2\\.1'), step2_2: findSection('2\\.2'), step2_3: findSection('2\\.3'), step2_4: findSection('2\\.4'), }; // Fallback if no sections are found if (!sections.step1 && !sections.step2_1 && !sections.step2_2 && !sections.step2_3 && !sections.step2_4) { return { step1: text, step2_1: '', step2_2: '', step2_3: '', step2_4: '' }; } return sections; }; const sections = parseSections(summary); const handleCopyStep = (key: string, stepLabel: string, technicalData: string) => { const guidanceKey = `step${key}` as keyof typeof VEDIC_KNOWLEDGE_BASE; const guidanceText = VEDIC_KNOWLEDGE_BASE[guidanceKey]; const prompt = `You are the Vedic Astrology Spiritual Guide, you will explain the meaning of those vedic technological data into application & practical, still spiritual meaning for me. FOLLOWING THE GUIDANCE OF ${stepLabel.toUpperCase()}: ${guidanceText} TECHNICAL DATA FOR ANALYSIS: ${technicalData} `; navigator.clipboard.writeText(prompt); setCopiedKey(key); setTimeout(() => setCopiedKey(null), 2000); }; const handleCopyMasterPrompt = () => { const fullPrompt = `${MASTER_LIFE_LESSONS_PROMPT}\n\n${summary}`; navigator.clipboard.writeText(fullPrompt); setMasterPromptCopied(true); setTimeout(() => setMasterPromptCopied(false), 2000); }; if (loading) { return (

Distilling Your Karma...

Generating Technical Roadmap (Screen 2)

); } if (currentError) { return (

The stars are obscured...

{currentError}

This model might be overloaded or unavailable. Try switching to a different one:

); } const renderSection = (key: string, labelNumber: string, content: string, title: string) => { if (!content || content.trim().length === 0) return null; return (
{labelNumber}

{title}

{content}
); }; return (

Technical Roadmap

Foundation & Promise Analysis

AI Intelligence Engine

@VedicGuru Sequential Audit

Mandatory Technical Verification

setAuditVerified(e.target.checked)} />
{renderSection('1', '1', sections.step1, "Step 1: Foundational Self")} {renderSection('2_1', '2.1', sections.step2_1, "Step 2.1: Players & Yoga Producers")} {renderSection('2_2', '2.2', sections.step2_2, "Step 2.2: Structural Evaluation")} {renderSection('2_3', '2.3', sections.step2_3, "Step 2.3: Capacity & Dignity")} {renderSection('2_4', '2.4', sections.step2_4, "Step 2.4: Karaka Confluence")}
{!auditVerified && (

Locked: Complete the technical audit above to unlock Step 3

)}
{/* Master Life Lessons Prompt Section */} {auditVerified && summary && (

Takeaway: Master Life Lessons Prompt

Want a profound reading of your core karma and psychological architecture without an exact birth time? Copy this highly engineered prompt (which includes your verified data) and paste it into your favorite chat AI (like ChatGPT or Claude).

)}
{modelName && (

Technical extraction generated by: {modelName}

)}
); }