"use client";
import Link from "next/link";
import { useTransition } from "react";
import { cancelSandboxOrder, sandboxSell } from "@/app/actions";
import { eur, EXIT_REASONS, pct, price, shares, signedEur } from "@/lib/format";
import type { Order, Position, PositionView } from "@/lib/portfolio";
import { Delta, Empty, secondaryBtn } from "./ui";
export function PositionList({ positions, sellable = false }: { positions: PositionView[]; sellable?: boolean }) {
const [pending, start] = useTransition();
if (!positions.length) return Aucune position ouverte.;
return (
{positions.map((p) => (
-
{p.name}
{shares(p.shares)} × {price(p.entryPrice, p.currency)} → {p.price !== null ? price(p.price, p.currency) : "?"}
{eur(p.valueEur)}
{signedEur(p.pnlOpenEur)} ({pct(p.pnlOpenPct)})
{(p.stopPrice || p.targetPrice || p.maxExitDate) && (
{p.stopPrice ? `Stop ${price(p.stopPrice, p.currency)}` : ""}
{p.targetPrice ? ` · Objectif ${price(p.targetPrice, p.currency)}` : ""}
{p.maxExitDate ? ` · Sortie au plus tard le ${p.maxExitDate}` : ""}
)}
{sellable && (
)}
))}
);
}
export function PendingOrders({ orders, cancellable = false }: { orders: Order[]; cancellable?: boolean }) {
const [pending, start] = useTransition();
return (
{orders.map((o) => (
-
{o.side === "buy" ? "Achat" : "Vente"} {shares(o.shares)} {o.name}
{o.type === "limit" && o.limitPrice ? `limite ${price(o.limitPrice, o.currency)}` : "au marché"}
{o.validUntil ? ` · valable jusqu'au ${o.validUntil}` : ""}
{cancellable && (
)}
))}
);
}
export function ClosedList({ positions }: { positions: Position[] }) {
if (!positions.length) return Pas encore de trade terminé.;
return (
{positions.map((p) => (
-
{p.name}
{p.closedAt?.toLocaleDateString("fr-FR")} · {EXIT_REASONS[p.exitReason ?? ""] ?? p.exitReason}
{signedEur(p.pnlEur ?? 0)}
))}
);
}