"use client"; import { useState } from "react"; import { Sparkles, X } from "lucide-react"; import type { Currency, BiasPhase } from "@/lib/types"; interface Props { currency: Currency; phase: BiasPhase; macroScore: number; } export default function NarrativeButton({ currency, phase, macroScore }: Props) { const [open, setOpen] = useState(false); const [analysis, setAnalysis] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const run = async () => { setLoading(true); setError(null); try { const res = await fetch("/api/narrative", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ mode: "summary", currency, data: { phase, macroScore }, }), }); const data = await res.json(); if (data.error) throw new Error(data.error); setAnalysis(data.analysis); setOpen(true); } catch (err) { setError(String(err)); } finally { setLoading(false); } }; return ( <> {error && ( ⚠ {error.replace(/^Error:\s*/i, "").slice(0, 40)} )} {open && analysis && (
setOpen(false)}>
e.stopPropagation()} >
Analyse {currency} — Groq AI

{analysis}

Powered by Groq · Llama 3.1 8B
)} ); }