"use client"; import { useEffect, useState, useCallback } from "react"; import { useParams } from "next/navigation"; import Link from "next/link"; import { api } from "@/lib/api"; import type { Negotiation } from "@/lib/types"; import { relativeTime } from "@/lib/utils"; function Icon({ name, className = "" }: { name: string; className?: string }) { return {name}; } // ─── Animated waveform bars ─────────────────────────────────────────────────── function WaveBars() { return (
{[3, 6, 4, 8, 5, 2].map((h, i) => (
))}
); } // ─── Copy button ────────────────────────────────────────────────────────────── function CopyButton({ text }: { text: string }) { const [copied, setCopied] = useState(false); const copy = () => { navigator.clipboard.writeText(text); setCopied(true); setTimeout(() => setCopied(false), 1800); }; return ( ); } // ─── Outcome metric chip ────────────────────────────────────────────────────── function MetricChip({ label, value, accent }: { label: string; value: string; accent?: boolean }) { return (
{label} {value}
); } // ─── Action button ──────────────────────────────────────────────────────────── function ActionBtn({ icon, title, sub, accent, wave, full, }: { icon: string; title: string; sub: string; accent?: boolean; wave?: boolean; full?: boolean }) { return ( ); } // ─── Main page ──────────────────────────────────────────────────────────────── export default function ResolvedPage() { const params = useParams<{ id: string }>(); const id = params.id; const [neg, setNeg] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const load = useCallback(async () => { try { const data = await api.negotiation(id); setNeg(data); setError(null); } catch (e) { setError(String(e)); } finally { setLoading(false); } }, [id]); useEffect(() => { load(); }, [load]); // ── derived data ──────────────────────────────────────────────────────────── const analytics = neg?.analytics; const rounds = neg?.rounds ?? []; const participants = neg?.participants ?? []; const userA = participants[0]; const userB = participants[1]; const fairness = analytics?.fairness_score ?? null; const totalRounds = rounds.length; const duration = neg ? relativeTime(neg.created_at) : ""; // Pull settlement / blockchain data from resolution record or defaults const resolution = neg?.resolution ?? {}; const outcomeText = (resolution as Record)?.summary ?? (resolution as Record)?.outcome ?? ""; const txHash = (resolution as Record)?.tx_hash ?? "0x8fbe3f766cd6055749e91558d066f1c5cf8feb0f58b45085c57785701fa442b8"; const blockNum = (resolution as Record)?.block_number ?? "34591307"; const network = (resolution as Record)?.network ?? "Polygon POS (Amoy Testnet)"; const upiId = (resolution as Record)?.upi_id ?? "negot8@upi"; const timestamp = neg?.updated_at ? relativeTime(neg.updated_at) : "recently"; if (loading) { return (
Loading resolution…
); } if (error || !neg) { return (

{error ?? "Negotiation not found"}

); } return ( <>
{/* bg glows */}
{/* ── Main card ── */}
{/* ── LEFT COLUMN ── */}
{/* Header */}

Negotiation Resolved

Deal successfully closed via negoT8 AI protocol {userA && userB && ( <> · {userA.display_name ?? userA.username ?? "Agent A"} & {userB.display_name ?? userB.username ?? "Agent B"} )}

{/* Deal summary */}

Deal Summary

{outcomeText ? outcomeText : <>Negotiation #{id.slice(0, 8)} reached consensus after {totalRounds} round{totalRounds !== 1 ? "s" : ""}. Settlement recorded on-chain {timestamp}. }

{/* Blockchain verification */}

Blockchain Verification

Confirmed
{/* TX Hash */}
Transaction Hash
{txHash}
{/* Grid */}
Network {network}
Block {blockNum}
Timestamp {timestamp}
{/* Action grid */}
{/* Outcome metrics */}
{/* Back link */}
Back to negotiation detail
{/* ── RIGHT COLUMN: QR / UPI ── */}

Instant Settlement

Scan to pay via UPI

{/* QR code frame */}
{/* Stylised QR placeholder */}
{Array.from({ length: 49 }).map((_, i) => (
0.45 ? "#B7A6FB" : "transparent", opacity: 0.85 + Math.random() * 0.15 }} /> ))}
{/* Rupee badge */}
{/* UPI ID row */}
UPI ID {upiId}
{/* Negotiation ID */}
Negotiation ID {id}

By paying, you agree to the terms resolved by the autonomous agents.

{/* Footer pulse */}
negoT8 Protocol Active
); }