import type { PlausibilityWarning } from "@/lib/warnings/types"; import { formatWaterContent } from "./format"; import { WATER_CONTENT_ABOVE_LEGAL } from "./types"; /** * The server words its warnings for the time before saving ("... Abfüllen nur * mit Bestätigung."). After a confirmed save that text is out of date, so the * confirmed finding is worded as the fact it now is. */ export function postSaveWarnings( warnings: readonly PlausibilityWarning[], confirmedWaterContent: number | null, ): PlausibilityWarning[] { return warnings.map((warning) => warning.code === WATER_CONTENT_ABOVE_LEGAL ? { ...warning, message: confirmedWaterContent === null ? "Wassergehalt über der Grenze – mit Bestätigung abgefüllt." : `Wassergehalt ${formatWaterContent(confirmedWaterContent)} über der Grenze – mit Bestätigung abgefüllt.`, } : warning, ); }