"use client"; import Link from "next/link"; import { useMemo, useState } from "react"; import type { Poll } from "@/lib/api"; import { cls, dateShort, int, modeLabel } from "@/lib/format"; import { PARTY_IDS, partyLabel, partyVar } from "@/lib/parties"; import { PollRowMobile } from "./forecast-blocks"; export function PollsTable({ polls }: { polls: Poll[] }) { const [firm, setFirm] = useState("all"); const [year, setYear] = useState("all"); const [onlyPrimary, setOnlyPrimary] = useState(false); const [shown, setShown] = useState(25); const firms = useMemo(() => Array.from(new Map(polls.map((p) => [p.pollster.id, p.pollster.name])).entries()), [polls]); const years = useMemo(() => Array.from(new Set(polls.map((p) => p.fieldworkEnd.slice(0, 4)))).sort().reverse(), [polls]); const rows = polls.filter((p) => (firm === "all" || p.pollster.id === firm) && (year === "all" || p.fieldworkEnd.startsWith(year)) && (!onlyPrimary || p.sourceTier === "primary")); return (
| Firme | Terrain | n | {PARTY_IDS.map((id) =>{partyLabel(id)} | )}Autres | Poids | Source |
|---|---|---|---|---|---|---|
| {p.pollster.name}{p.sponsor && {p.sponsor} } |
{p.fieldworkStart ? `${dateShort(p.fieldworkStart)} – ` : ""}{dateShort(p.fieldworkEnd)} | {int(p.sampleSize)} | {PARTY_IDS.map((id) =>{p.results[id] !== undefined ? p.results[id].toFixed(p.results[id] % 1 ? 1 : 0).replace(".", ",") : "—"} | )}{p.results["aut"] !== undefined ? p.results["aut"].toFixed(0) : "—"} | {p.weight ? p.weight.weight.toFixed(2) : "—"} | {p.sourceTier === "primary" ? PDF archivé : index}{p.excluded && exclu} |