"use client"; import Link from "next/link"; import { useState, useTransition } from "react"; import { respondCard } from "@/app/actions"; import type { ActionPayload } from "@/lib/db/schema"; import { Badge, inputCls, primaryBtn, secondaryBtn } from "./ui"; type Props = { id: number; kind: string; training: boolean; status: string; symbol?: string | null; payload: ActionPayload; }; /** Lien vers la fiche de l'action, formulaire d'achat pré-rempli avec la recette. */ function sandboxHref(symbol: string, p: ActionPayload) { const q = new URLSearchParams(); if (p.amountEur) q.set("montant", String(Math.min(p.amountEur, 198))); if (p.stopPct) q.set("stop", String(p.stopPct)); if (p.targetPct) q.set("objectif", String(p.targetPct)); return `/actions/${encodeURIComponent(symbol)}?${q}`; } export function ActionCard({ id, kind, training, status, symbol, payload }: Props) { const [pending, start] = useTransition(); const [open, setOpen] = useState(false); const [priceVal, setPrice] = useState(payload.limitPrice?.toString() ?? ""); const [sharesVal, setShares] = useState(payload.shares?.toString() ?? ""); const [error, setError] = useState(null); const needsFill = !training && (kind === "buy" || kind === "sell"); const answer = (a: "done" | "skipped") => start(async () => { setError(null); try { await respondCard(id, a, needsFill ? Number(priceVal.replace(",", ".")) : undefined, needsFill ? Number(sharesVal.replace(",", ".")) : undefined); } catch (e) { setError(e instanceof Error ? e.message : "Erreur"); } }); const icon = { buy: "🟢", sell: "🔴", move_stop: "🛡️", to_pea: "🏦" }[kind] ?? "•"; return (
{training ? Entraînement : Argent réel} {status !== "pending" && {status === "done" ? (training ? "Tu l'aurais pris" : "Fait") : "Passé"}}

{icon} {payload.title}

{open &&

{payload.why}

}
    {payload.steps.map((s) => (
  1. {s}
  2. ))}
{kind === "buy" && symbol && ( 🧪 Essayer dans mon bac à sable )} {status === "pending" && (
{needsFill && (
)}
{error &&

{error}

}
)}
); }