<span class="aui-avatar-root"><span class="aui-avatar-fallback">trivy</span></span>
<div class="aui-assistant-message-content">
    <div class="group relative flex items-start">
        <div class="flex-1 space-y-2 overflow-hidden">
            <div id="latex-content" class="prose break-words dark:prose-invert prose-p:leading-relaxed prose-pre:p-0">
                <div id="ai-message-1" class="ai-message grid gap-2 rounded-2xl border border-zinc-200 bg-white p-2 sm:p-4">
                    <div class="grid gap-2 sm:flex sm:flex-row justify-between items-center border-b p-2">
                        <div class="sm:basis-2/3">
                            <div class="text-sm font-medium">Test on: can you give me 2 frq based test. the subject is ap world history</div>
                            <div class="text-xs text-zinc-600">2 questions</div>
                        </div>
                    </div>
                    <div class="question-tabs-wrapper">
                        <div class="question-tabs-container">
                            <button class="question-tab-button active" onclick="displayQuestion(1, '1')">Question 1</button> <button class="question-tab-button False" onclick="displayQuestion(2, '1')">Question 2</button>
                        </div>
                    </div>
                    <div class="tabs-content mt-4">
                        
                            <div class="tab-content" id="q-1-1" style="display: block">
                                <div class="markdown-content">
                                    <div class="question-text mb-4">Analyze the impact of the Silk Road on the cultural, economic, and political developments of civilizations in Asia, Europe, and Africa from 300 BCE to 1500 CE. Be sure to include specific examples of trade goods, technologies, and ideas that were exchanged along the Silk Road.</div>
                                    <div id="frq-stuff"><textarea id="frq-textarea-{i+1}-{len(chat_history_test)//2}" style="width: 100%; min-height: 100px; border: 1px solid #ccc; padding: 8px;" placeholder="Your answer"></textarea></div>
                                </div>
                            </div>
                         
                            <div class="tab-content" id="q-2-1" style="display: none">
                                <div class="markdown-content">
                                    <div class="question-text mb-4">Compare and contrast the systems of government and social hierarchy in ancient China during the Qin and Han dynasties (221 BCE - 220 CE) with those in ancient India during the Mauryan and Gupta dynasties (322 BCE - 550 CE). How did the philosophical and religious beliefs of each region influence the development of their respective systems of government and social organization?</div>
                                    <div id="frq-stuff"><textarea id="frq-textarea-{i+1}-{len(chat_history_test)//2}" style="width: 100%; min-height: 100px; border: 1px solid #ccc; padding: 8px;" placeholder="Your answer"></textarea></div>
                                </div>
                            </div>
                        
                    </div>
                    <div id="results-1" class="mt-4 hidden"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css">
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/contrib/auto-render.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
    function initializeTest(messageId) {
        // Initialize LaTeX rendering
        renderMathInElement(document.getElementById('latex-content'), {
            delimiters: [
                {left: "$$", right: "$$", display: true},
                {left: "$", right: "$", display: false},
                {left: "\(", right: "\)", display: false},
                {left: "\[", right: "\]", display: true}
            ],
            throwOnError: false,
            strict: false
        });

        // Initialize test state
        if (!window.testState) window.testState = {};
        window.testState[messageId] = {
            currentQuestion: 1,
            answers: new Array(2).fill(null)
        };

        // Initialize Prism.js
        Prism.highlightAll();

        // Initialize Chart.js
        const chartContainers = document.querySelectorAll('.chartjs-container');
        chartContainers.forEach(container => {
            const config = JSON.parse(container.dataset.chartConfig);
            new Chart(container, config);
        });
    }

    function displayQuestion(num, messageId) {
        const container = document.getElementById(`ai-message-${messageId}`);
        const state = window.testState[messageId];
        state.currentQuestion = num;

        // Update tabs
        container.querySelectorAll('.question-tab-button').forEach((tab, i) => {
            if (i + 1 === num) {
                tab.classList.add('active');
            } else {
                tab.classList.remove('active');
            }
        });

        // Update content
        container.querySelectorAll('.tab-content').forEach(content => {
            content.style.display = 'none';
        });
        document.getElementById(`q-${num}-${messageId}`).style.display = 'block';
    }

    function handleAnswer(questionNum, answer, messageId) {
        const state = window.testState[messageId];
        state.answers[questionNum - 1] = answer;

        // Check if all questions answered
        if (!state.answers.includes(null)) {
            showResults(messageId);
        }
    }

    function showResults(messageId) {
        const container = document.getElementById(`results-${messageId}`);
        const state = window.testState[messageId];
        let correct = 0;
        let resultsHtml = '<div class="bg-zinc-50 rounded-lg p-4"><div class="text-center"><div class="text-lg font-medium">Test Results</div>';

        // Calculate score and generate results HTML
        state.answers.forEach((answer, i) => {
            const correctAnswer = document.getElementById(`correct-${i+1}-${messageId}`).value;
            const isCorrect = answer === correctAnswer;
            if (isCorrect) correct++;

            resultsHtml += `
                <div class="text-left mt-2 p-2 rounded ${isCorrect ? 'bg-green-100' : 'bg-red-100'}">
                    <strong>Q${i+1}:</strong> Your answer: ${answer}
                    ${isCorrect ? '✓' : `✗ (Correct: ${correctAnswer})`}
                </div>
            `;
        });

        // Display overall score
        const percentage = ((correct / 2) * 100).toFixed(1);
        resultsHtml += `
            <div class="mt-4">
                <div class="text-3xl font-bold text-blue-600">${percentage}%</div>
                <div class="text-sm text-zinc-600">${correct} out of 2 correct</div>
            </div>
        </div></div>`;

        container.innerHTML = resultsHtml;
        container.classList.remove('hidden');

        // Create a chart to visualize results
        const chartContainer = document.createElement('div');
        chartContainer.className = 'chartjs-container';
        chartContainer.style.width = '100%';
        chartContainer.style.height = '200px';
        container.appendChild(chartContainer);

        new Chart(chartContainer, {
            type: 'pie',
            data: {
                labels: ['Correct', 'Incorrect'],
                datasets: [{
                    data: [correct, 2 - correct],
                    backgroundColor: ['#4CAF50', '#F44336']
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false
            }
        });
    }

    // Add test initialization to window
    window.initializeTest = initializeTest;
    window.handleAnswer = handleAnswer;
    window.displayQuestion = displayQuestion;

    document.addEventListener('DOMContentLoaded', function() {
        window.initializeTest('1');
    });
</script>
<style>
.aui-avatar-root {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.aui-avatar-fallback {
    background-color: #f4f4f5;
    color: #71717a;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.question-tabs-wrapper {
    display: flex;
    justify-content: center; /* Keeps the tabs centered horizontally */
    width: 100%;
    overflow: hidden;
}

.question-tabs-container {
    background-color: #f6f7f6;
    border-radius: 9999px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    padding: 2px;
    max-width: 100%;
}

.question-tab-button {
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 13px;
    font-weight: 500;
    color: #bcbdbc;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    line-height: 1.2;
    position: relative;
    z-index: 0;
    margin: 2px;
}

.question-tab-button:hover {
    color: #626061;
}

.question-tab-button.active {
    background-color: #ffffff;
    color: #18181b;
}

.border-b {
    border-bottom-width: 1px;
    border-color: rgb(228 228 231);
}

.markdown-content {
    font-size: 14px;
    line-height: 1.6;
    padding: 1rem;
}

        .question-text {
            margin-bottom: 1rem;
            padding: 0;
            white-space: normal; /* Ensure text wraps */
        }

        .chartjs-container {
            margin: 1rem 0;
            padding: 1rem;
            background-color: white;
            border-radius: 8px;
        }

        .options {
            display: flex;
            flex-direction: column;
        }

        .test-option-item {
            margin-bottom: 0.5rem;
            display: flex;
            align-items: center;
        }

        .test-option-item input[type="radio"] {
            margin-right: 0.5rem;
        }

        .test-option-item label {
            font-size: 14px;
            color: black;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: flex-start;
            width: 100%;
            padding: 0.5rem 0;
        }

        pre[class*="language-"] {
            margin: 1em 0;
            padding: 1em;
            overflow: auto;
            border-radius: 0.3em;
        }
        </style>