/**
* 📊 IHK NUTZWERTANALYSE-KALKULATOR (NWA) 📊
* ==========================================
* Interaktiver Nutzwertanalyse-Trainer für AP1 (LF 2) & AP2 (LF 12):
* - Gewichtete Kriterienmatrix (Prüfung auf 100% Summe)
* - Live-Berechnung der Teil- und Gesamtnutzwerte
* - Empfehlung & Rangfolge nach IHK-Standard
*/
class NwaCalculator {
constructor(containerId) {
this.container = document.getElementById(containerId);
this.criteria = [
{ name: "Anschaffungspreis / TCO", weight: 30, scoreA: 8, scoreB: 5 },
{ name: "Performance & Skalierbarkeit", weight: 25, scoreA: 6, scoreB: 9 },
{ name: "Garantie & Support-SLA (24/7)", weight: 20, scoreA: 7, scoreB: 8 },
{ name: "Energieeffizienz (Stromverbrauch)", weight: 15, scoreA: 9, scoreB: 6 },
{ name: "Lieferzeit & Verfügbarkeit", weight: 10, scoreA: 5, scoreB: 10 }
];
this.init();
}
init() {
if (!this.container) return;
this.render();
this.calculate();
}
render() {
this.container.innerHTML = `
`;
this.container.querySelectorAll(".nwa-weight, .nwa-score-a, .nwa-score-b").forEach(el => {
el.addEventListener("input", () => this.calculate());
});
}
calculate() {
let totalWeight = 0;
let totalScoreA = 0;
let totalScoreB = 0;
this.criteria.forEach((_, i) => {
const w = parseFloat(this.container.querySelector(`.nwa-weight[data-idx="${i}"]`).value) || 0;
const sA = parseFloat(this.container.querySelector(`.nwa-score-a[data-idx="${i}"]`).value) || 0;
const sB = parseFloat(this.container.querySelector(`.nwa-score-b[data-idx="${i}"]`).value) || 0;
totalWeight += w;
const valA = (w * sA) / 100;
const valB = (w * sB) / 100;
totalScoreA += valA;
totalScoreB += valB;
const elA = document.getElementById(`nwa-val-a-${i}`);
const elB = document.getElementById(`nwa-val-b-${i}`);
if (elA) elA.textContent = (w * sA).toFixed(0);
if (elB) elB.textContent = (w * sB).toFixed(0);
});
const sumWeightEl = document.getElementById("nwa-sum-weight");
const weightBadge = document.getElementById("nwa-weight-sum");
const totAEl = document.getElementById("nwa-total-a");
const totBEl = document.getElementById("nwa-total-b");
const banner = document.getElementById("nwa-winner-banner");
if (sumWeightEl) sumWeightEl.textContent = `${totalWeight} %`;
if (weightBadge) {
weightBadge.textContent = `Gewichtung: ${totalWeight}%`;
weightBadge.className = totalWeight === 100 ? "ihk-badge ihk-badge-success" : "ihk-badge ihk-badge-danger";
}
const rawTotalA = totalScoreA * 100;
const rawTotalB = totalScoreB * 100;
if (totAEl) totAEl.textContent = rawTotalA.toFixed(0);
if (totBEl) totBEl.textContent = rawTotalB.toFixed(0);
if (totalWeight !== 100) {
banner.style.background = "rgba(239, 68, 68, 0.15)";
banner.style.border = "1px solid #ef4444";
banner.style.color = "#f87171";
banner.innerHTML = `⚠️ Achtung: Die Gesamtsumme der Gewichtungen beträgt aktuell ${totalWeight} % statt 100 %. Bitte Kriterien anpassen.`;
} else {
const winner = rawTotalA > rawTotalB ? "Angebot A" : (rawTotalB > rawTotalA ? "Angebot B" : "Gleichstand");
banner.style.background = "rgba(34, 197, 94, 0.15)";
banner.style.border = "1px solid #22c55e";
banner.style.color = "#4ade80";
banner.innerHTML = `🏆 Wirtschaftliche Entscheidung: ${winner} erzielt mit ${Math.max(rawTotalA, rawTotalB).toFixed(0)} Punkten den höchsten Gesamtnutzen und wird zur Beschaffung empfohlen.`;
}
}
}
window.NwaCalculator = NwaCalculator;