{% extends "student/student_layout.html" %}
{% block student_content %}
<div class="container">
    <figure class="text-center">
        <h3 class="display-5">{{ exam_info[1] }}</h3>
        {% if exams_given[5] == 1 %} 
            <h4><strong>Score: {{exams_given[2]}} out of {{exam_info[5]}}</strong></h4>
        {% else %}
            <h4><strong>Assessment is pending</strong></h4>
            Your response for each question is as below
        {% endif %}
    </figure>
    <br>
    <form class="form-group">
        {% for question in questions %}
        <div class="card">
            <div class="card-body">
                <div class="card-title bg-light p-3">{{question[1]|safe}}</div>
                {% if question[2] == 'O' %}
                <ul class="list-group list-group-flush">
                    {% for option in options %}
                        {% if option[3] == question[0] %}
                        
                            {% set isCorrect=0 %} 
                            {% if option[2] == '1' %}
                                {% set isCorrect=1 %}                                        
                            {% endif %}
                            
                            {% set ns = namespace() %}
                            {% set ns.isSelected=0 %} 
                            {% for o in selected_options %}
                                {% if o[2] == option[0] %}
                                    {% set ns.isSelected=1 %} 
                                {% endif %}
                            {% endfor %}
                            {% if exams_given[5] == 1 %}
                                {% if ((isCorrect == 1) and (ns.isSelected == 1)) %}
                                    <div class="list-group-item list-group-item-success">
                                        <label>
                                            <div class="form-check">
                                                <input class="form-check-input" type="radio" checked name="{{question[0]}}" value="{{option[0]}}">
                                                <label class="form-check-label">
                                                    {{ option[1] }}
                                                </label>
                                            </div>
                                        </label>
                                    </div>
                                {% elif ((isCorrect == 1) and (ns.isSelected == 0)) %}
                                    <div class="list-group-item list-group-item-success">
                                        <label>
                                            <div class="form-check">
                                                <input class="form-check-input"  type="radio" name="{{question[0]}}" value="{{option[0]}}">
                                                <label class="form-check-label">
                                                    {{ option[1] }}
                                                </label>
                                            </div>
                                        </label>
                                    </div>
                                {% elif ((isCorrect == 0) and (ns.isSelected == 1)) %}
                                    <div class="list-group-item list-group-item-danger">
                                        <label>
                                            <div class="form-check">
                                                <input class="form-check-input"  checked type="radio" name="{{question[0]}}" value="{{option[0]}}">
                                                <label class="form-check-label">
                                                    {{ option[1] }}
                                                </label>
                                            </div>
                                        </label>
                                    </div>
                                {% else %}
                                    <div class="list-group-item ">
                                        <label>
                                            <div class="form-check">
                                                <input class="form-check-input"  type="radio" name="{{question[0]}}" value="{{option[0]}}">
                                                <label class="form-check-label">
                                                    {{ option[1] }} {{colour}}
                                                </label>
                                            </div>
                                        </label>
                                    </div>
                                {% endif %}
                            {% else %}
                                {% if (ns.isSelected == 1) %}
                                <div class="list-group-item ">
                                    <label>
                                        <div class="form-check">
                                            <input class="form-check-input"  checked type="radio" name="{{question[0]}}" value="{{option[0]}}">
                                            <label class="form-check-label">
                                                {{ option[1] }}
                                            </label>
                                        </div>
                                    </label>
                                </div>
                                {% else %}
                                <div class="list-group-item ">
                                    <label>
                                        <div class="form-check">
                                            <input class="form-check-input"  type="radio" name="{{question[0]}}" value="{{option[0]}}">
                                            <label class="form-check-label">
                                                {{ option[1] }} {{colour}}
                                            </label>
                                        </div>
                                    </label>
                                </div>
                                {% endif %}
                            {% endif %}
                        {% endif %}
                    {% endfor %}
                </ul>
                {% elif question[2] == 'S' %}
                    {% for sub_sol in subjective_solutions %}
                        {% if question[0] == sub_sol[2] %}
                            <embed src="/static/student_uploads/{{sub_sol[1]}}" width="100%" height="500px"/>
                        {% endif %}
                    {% endfor %}
                {% endif %}
            </div>

        </div>
        <br>
        {% endfor %}
        
        <br>
    </form>
</div>

<script>
    function myFunction() {
        if (confirm("Submit the Exam?")) {
        }
        else {
            return false;
        }
    }
</script>
{% endblock %}