"use client"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { api, errorText } from "@/lib/api"; /** Compares two charts (or opens their existing comparison). */ export function CompareButton({ chart1, chart2, label = "Összevetés velem", className = "btn btn-sm btn-ghost", }: { chart1: string; chart2: string; label?: string; className?: string; }) { const router = useRouter(); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); async function compare() { setBusy(true); setError(null); try { const s = await api<{ id: string }>("/synastries", { body: { chart1_id: chart1, chart2_id: chart2 } }); router.push(`/osszevetesek/${s.id}`); } catch (e) { setError(errorText(e)); setBusy(false); } } return ( <> {error && (

{error}

)} ); }