// ── Italian Mediterranean score — POC debug view ─────────────────────────────
function scoreColor(n) {
if (n == null) return "#999";
if (n >= 75) return "#1b7340";
if (n >= 50) return "#85BB2F";
if (n >= 25) return "#EE8100";
return "#E63312";
}
const ADDITIVE_COLOR = {
green: "#4caf50",
yellow: "#fbc02d",
orange: "#ff9800",
red: "#e53935",
};
const CAP_REASON_LABEL = {
red_additive: "Cap a 49 per additivo rosso",
nutriscore_d_e: "Cap a 49 per Nutri-Score D/E",
exempt_soften_d_e: "−10 pts (esente, non capped)",
};
function StatRow({ label, value, max, hint }) {
return (
{label}
{value == null ? "—" : value}
{max != null && /{max}}
{hint && {hint}}
);
}
function PointsBar({ label, points, max }) {
const pct = max > 0 ? (points / max) * 100 : 0;
return (
);
}
function ScoreCard({ score }) {
const [open, setOpen] = React.useState(false);
if (!score) return null;
const color = scoreColor(score.score);
const n = score.nutrition;
const p = score.processing;
const q = score.quality;
return (
{/* Header: big score */}
{score.score}
/100
{score.label_it}
Italian Mediterranean Score
{score.nutri_grade && (
Nutri {score.nutri_grade}
)}
{score.is_exempt && (
Mediterraneo
)}
{score.cap_reason && (
{CAP_REASON_LABEL[score.cap_reason] || score.cap_reason}
)}
{/* Component bars */}
{score.raw_total !== score.score && (
raw {score.raw_total} → {score.score}
)}
{/* Expandable debug breakdown */}
{open && (
{/* ── Nutrition ── */}
Nutrizione · {n.points}/50 · variante{" "}
{n.variant}
Input (per 100g/ml)
{n.inputs.sat_fat_ratio_pct != null && (
)}
N (neg − pos, range −15..40)
{n.n_score}
{/* ── Processing ── */}
Additivi & Processing · {p.points}/30
Additivi ({p.additives.length})
{p.additive_pts}/20
{p.additives.length > 0 ? (
{p.additives.map((a, i) => (
{a.tag.replace("en:", "").toUpperCase()}
))}
) : (
nessuno
)}
yellow −{p.yellow_penalty} · orange −{p.orange_penalty}
{p.has_red && " · red (cap 49)"}
{/* ── Quality ── */}
Qualità & Origine · {q.points}/20
{q.granted.length === 0 && (
nessun bonus
)}
{q.granted.map((g, i) => (
{g.name}
+{g.bonus}
))}
{/* ── Final math ── */}
nutrition
{n.points}
+ processing
{p.points}
+ quality
{q.points}
= raw total
{score.raw_total}
{score.cap_reason && (
{score.cap_reason}
→
)}
final
{score.score}
)}
);
}