import React, { useState } from “react”;
import { AssessmentForm, AdvisorBlueprint } from “../types”;
import { Cpu, ShieldAlert, CheckCircle, ChevronRight, ChevronLeft, Loader2, Sparkles, AlertCircle, Info, Heart } from “lucide-react”;

export default function StepFormAdvisor() {
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const [blueprint, setBlueprint] = useState(null);
const [step, setStep] = useState(1);

const [form, setForm] = useState({
name: “”,
age: 35,
dependents: 0,
maritalStatus: “single”,
yearlyIncome: 75000,
healthLifestyle: “average”,
smoker: false,
ownsHome: “rent”,
ownsCar: true,
riskTolerance: “medium”,
primaryGoal: “Comprehensive overall security with deductible savings strategies”,
});

const nextStep = () => setStep((prev) => Math.min(prev + 1, 4));
const prevStep = () => setStep((prev) => Math.max(prev – 1, 1));

const handleFormChange = (fields: Partial) => {
setForm((prev) => ({ …prev, …fields }));
};

const handleFormSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError(null);

try {
const response = await fetch(“/api/advisor”, {
method: “POST”,
headers: { “Content-Type”: “application/json” },
body: JSON.stringify(form),
});

if (!response.ok) {
throw new Error(“Failed to receive structured advisor analysis.”);
}

const data = await response.json();
setBlueprint(data);
} catch (err: any) {
console.error(err);
setError(err.message || “An unexpected error occurred during analysis.”);
} finally {
setLoading(false);
}
};

const handleReset = () => {
setBlueprint(null);
setStep(1);
setError(null);
};

return (

{/* Title */}


AI Risk & Security Advisor

Complete our short anonymous diagnostic to generate a specialized, custom Insurance Security Blueprint powered by the Gemini 3.5 model.

{error && (

Error Processing Profile: {error}

Make sure you have specified your GEMINI_API_KEY environment variable securely in AI Studio Secrets panel.

)}

{/* Main Container */}

{!blueprint ? (
/* Multi-step diagnostic questionnaire */

{/* Step indicators */}

Step {step} of 4

{[1, 2, 3, 4].map((s) => (
= s ? “bg-indigo-600 w-4” : “bg-slate-200”
}`}
/>
))}

{/* STEP 1: Basic Demographics */}
{step === 1 && (

1. Tell us about yourself


handleFormChange({ name: e.target.value })}
placeholder=”Enter name or keep anonymous”
className=”w-full bg-slate-50 border border-gray-200 rounded-xl px-4 py-3 text-sm focus:bg-white focus:outline-none focus:ring-1 focus:ring-indigo-500 transition duration-150″
/>

handleFormChange({ age: parseInt(e.target.value) || 35 })}
className=”w-full bg-slate-50 border border-gray-200 rounded-xl px-4 py-3 text-sm focus:bg-white focus:outline-none focus:ring-1 focus:ring-indigo-500 transition duration-150″
/>

handleFormChange({ dependents: parseInt(e.target.value) || 0 })}
className=”w-full bg-slate-50 border border-gray-200 rounded-xl px-4 py-3 text-sm focus:bg-white focus:outline-none focus:ring-1 focus:ring-indigo-500 transition duration-150″
/>

{([“single”, “married”, “divorced”] as const).map((ms) => (

))}

)}

{/* STEP 2: Lifestyle & Income */}
{step === 2 && (

2. Financial & Lifestyle Factors

$

handleFormChange({ yearlyIncome: parseInt(e.target.value) || 0 })}
className=”w-full bg-slate-50 border border-gray-200 rounded-xl pl-8 pr-4 py-3 text-sm focus:bg-white focus:outline-none focus:ring-1 focus:ring-indigo-500 transition duration-150″
/>

{[
{ id: “excellent”, label: “Excellent Wellness” },
{ id: “average”, label: “Average Wellness” },
{ id: “needs-improvement”, label: “Needs Improvement” },
].map((hl) => (

))}

handleFormChange({ smoker: e.target.checked })}
className=”h-4 w-4 rounded text-indigo-600 accent-indigo-600″
/>

)}

{/* STEP 3: Assets & Exposure */}
{step === 3 && (

3. Assets & Liability Exposures

{[
{ id: “own”, label: “Own My Home” },
{ id: “rent”, label: “Rent Apartment” },
{ id: “none”, label: “None / Shared” },
].map((ho) => (

))}

handleFormChange({ ownsCar: e.target.checked })}
className=”h-4 w-4 rounded text-indigo-600 accent-indigo-600″
/>

)}

{/* STEP 4: Risk Profile Goals */}
{step === 4 && (

4. Risk Management Strategy

{([“low”, “medium”, “high”] as const).map((tol) => (

))}