<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Quiz Result</title>
    <style>
        /* General styles */
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }

        /* Header styles */
        .header {
            position: fixed;
            top: 0;
            right: 0;
            padding: 10px 20px;
            display: flex;
            gap: 10px; /* Space between buttons */
        }

        /* Button styles */
        .nav-button {
            background-color: #2196F3; /* Blue background */
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            text-decoration: none; /* Remove underline for links */
            font-size: 14px;
        }

        .nav-button:hover {
            background-color: #1976D2; /* Darker blue on hover */
        }

        /* Result container styles */
        .result-container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            max-width: 600px;
            width: 100%;
            text-align: center;
            margin: 80px auto 20px; /* Add margin to avoid overlap with header */
        }

        .result-header {
            font-size: 24px;
            font-weight: bold;
            color: #4CAF50;
            margin-bottom: 20px;
        }

        .result-details {
            margin-top: 20px;
            text-align: left;
        }

        .result-details h3 {
            margin-bottom: 10px;
            color: #333;
        }

        .result-details ul {
            list-style-type: none;
            padding: 0;
        }

        .result-details li {
            margin-bottom: 10px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            background-color: #f9f9f9;
        }

        .correct {
            color: #4CAF50;
        }

        .incorrect {
            color: #f44336;
        }
    </style>
</head>
<body>
    <!-- Header with Home and Logout Buttons -->
    <div class="header">
        <a th:href="@{/home}">
            <button class="nav-button">Home</button>
        </a>
        <form th:action="@{/logout}" method="post">
            <button type="submit" class="nav-button">Logout</button>
        </form>
    </div>

    <!-- Result Container -->
    <div class="result-container">
        <!-- Result Header -->
        <div class="result-header" th:text="${'You scored ' + correctAnswers + ' out of ' + totalQuestions + '!'}"></div>

        <!-- Result Details -->
        <div class="result-details">
            <h3>Details:</h3>
            <ul>
                <!-- Iterate through quizzes and display correct/incorrect answers -->
                <li th:each="quiz, iterStat : ${quizzes}">
                    <div>
                        <strong th:text="${'Question ' + (iterStat.index + 1) + ': ' + quiz.questionText}"></strong>
                    </div>
                    <div>
                        <span>Your Answer: </span>
                        <span th:class="${quiz.correctAnswer == userAnswers[iterStat.index] ? 'correct' : 'incorrect'}" 
                              th:text="${userAnswers[iterStat.index]}"></span>
                    </div>
                    <div th:if="${quiz.correctAnswer != userAnswers[iterStat.index]}">
                        <span>Correct Answer: </span>
                        <span class="correct" th:text="${quiz.correctAnswer}"></span>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</body>
</html>