/** * rChoices applet definitions — Vote Tally. */ import type { AppletDefinition, AppletLiveData } from "../../shared/applet-types"; const voteTally: AppletDefinition = { id: "vote-tally", label: "Vote Tally", icon: "🗳️", accentColor: "#7c3aed", ports: [ { name: "session-in", type: "json", direction: "input" }, { name: "winner-out", type: "string", direction: "output" }, ], renderCompact(data: AppletLiveData): string { const { snapshot } = data; const question = (snapshot.question as string) || "Vote"; const totalVotes = (snapshot.totalVotes as number) || 0; const winner = (snapshot.winner as string) || "—"; const winPct = (snapshot.winnerPct as number) || 0; return `
${question}
${winner}
${winPct}% of ${totalVotes} votes
`; }, onInputReceived(portName, value, ctx) { if (portName === "session-in" && value && typeof value === "object") { const session = value as Record; ctx.emitOutput("winner-out", (session.winner as string) || ""); } }, }; export const choicesApplets: AppletDefinition[] = [voteTally];