interface WHO5CalculatorProps {
    answers: { [key: number]: string };
}

export const calculateWHO5Results = ({ answers }: WHO5CalculatorProps) => {
    const itemScores = Array.from({ length: 5 }, (_, index) => {
        const questionId = index + 1;
        return Number.parseInt(answers[questionId] ?? "0", 10);
    });

    const rawScore = itemScores.reduce((sum, score) => sum + score, 0);
    const percentageScore = rawScore * 4;
    const hasVeryLowItem = itemScores.some((score) => score <= 1);

    let level: "high" | "moderate" | "low" | "very_low" = "high";
    if (rawScore <= 7) {
        level = "very_low";
    } else if (rawScore <= 12) {
        level = "low";
    } else if (rawScore <= 17) {
        level = "moderate";
    }

    return {
        rawScore,
        percentageScore,
        itemScores,
        hasVeryLowItem,
        level,
        needsAttention: rawScore <= 12 || hasVeryLowItem,
    };
};
