import { useState } from "react"; import { Link } from "react-router-dom"; import type { Opportunity, OpportunityRemovalReason } from "../../domain/types"; import { useI18n } from "../../i18n/I18nContext"; import { Badge, Button, Select, Textarea } from "../ui"; import { formatTimeAgo } from "../../lib/time"; const REASON_KEYS = [ "pain_mismatch", "provider_or_ad", "stale", "already_solved", "duplicate", "other", ] as const; type Props = { opportunity: Opportunity; onOpen: (opportunity: Opportunity) => void; onAccept: (opportunity: Opportunity) => void; onComplete: (opportunity: Opportunity) => void; onRemove: (opportunity: Opportunity, input: { reason: OpportunityRemovalReason; note?: string }) => void; onRestore: (opportunity: Opportunity) => void; busy?: boolean; }; export function OpportunityInboxCard({ opportunity, onOpen, onAccept, onComplete, onRemove, onRestore, busy = false }: Props) { const { t } = useI18n(); const [removeOpen, setRemoveOpen] = useState(false); const [reason, setReason] = useState("pain_mismatch"); const [note, setNote] = useState(""); const reviewState = opportunity.review_state ?? (opportunity.status === "accepted" ? "completed" : opportunity.status === "dismissed" ? "removed" : "pending"); const pending = reviewState === "pending"; const score = opportunity.priority_score ?? opportunity.intent_score; const evidence = opportunity.demand_evidence?.[0] ?? opportunity.product_matches?.[0]?.reasons?.[0]?.reason; const accepted = opportunity.status === "accepted" || Boolean(opportunity.contact_id); const priorityLabel = opportunity.priority_band === "high" ? t("radar.card.priority.high") : opportunity.priority_band === "review" ? t("radar.card.priority.review") : opportunity.priority_band === "low" ? t("radar.card.priority.low") : opportunity.intent_band === "high" ? t("radar.inbox.band.high") : opportunity.intent_band === "mid" ? t("radar.inbox.band.mid") : t("radar.inbox.band.low"); function submitRemove() { if (reason === "other" && !note.trim()) return; onRemove(opportunity, { reason, note: note.trim() || undefined }); setRemoveOpen(false); setNote(""); } return (
{priorityLabel} · {score} {opportunity.primary_product_label ? {t("radar.card.fitProduct", { label: opportunity.primary_product_label })} : {t("radar.card.noProduct")}} {t("radar.card.intent", { n: opportunity.intent_score })} · {formatTimeAgo(opportunity.posted_at)}

{opportunity.text}

{evidence ?

{t("radar.card.why")}{evidence}

: null}
@{opportunity.author_handle || t("radar.card.unknownAuthor")} {t("radar.card.openOriginal")}
{pending ? : null} {pending ? : null} {(pending || reviewState === "completed") && !accepted ? ( ) : null} {reviewState === "removed" ? : null} {reviewState === "completed" && accepted && opportunity.contact_id ? ( {t("radar.inbox.goCrm")} ) : null} {reviewState === "completed" ? {accepted ? t("radar.card.accepted") : t("radar.card.done")} : null}
{removeOpen ? (
{t("radar.card.removeTitle")}

{t("radar.card.removeHint")}

{reason === "other" ?