<ion-header>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-back-button [text]="'core.back' | translate"></ion-back-button>
        </ion-buttons>
        <ion-title>
            <h1>{{ 'addon.mod_quiz.review' | translate }}</h1>
        </ion-title>

        <ion-buttons slot="end">
            <ion-button fill="clear" *ngIf="navigation.length" [attr.aria-label]="'addon.mod_quiz.opentoc' | translate"
                (click)="openNavigation()" aria-haspopup="true">
                <ion-icon name="fas-bookmark" slot="icon-only" aria-hidden="true"></ion-icon>
            </ion-button>
        </ion-buttons>
    </ion-toolbar>
</ion-header>
<ion-content class="limited-width">
    <ion-refresher slot="fixed" [disabled]="!loaded" (ionRefresh)="refreshData($event.target)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
    </ion-refresher>
    <core-loading [hideUntil]="loaded">

        <!-- Review summary -->
        <ion-card *ngIf="attempt">
            <ion-list>
                <ion-item class="ion-text-wrap">
                    <ion-label>
                        <p class="item-heading">{{ 'addon.mod_quiz.startedon' | translate }}</p>
                        <p>{{ attempt.timestart! * 1000 | coreFormatDate }}</p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap">
                    <ion-label>
                        <p class="item-heading">{{ 'addon.mod_quiz.attemptstate' | translate }}</p>
                        <p>{{ readableState }}</p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="showCompleted">
                    <ion-label>
                        <p class="item-heading">{{ 'addon.mod_quiz.completedon' | translate }}</p>
                        <p>{{ attempt.timefinish! * 1000 | coreFormatDate }}</p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="timeTaken">
                    <ion-label>
                        <p class="item-heading">{{ 'addon.mod_quiz.timetaken' | translate }}</p>
                        <p>{{ timeTaken }}</p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="overTime">
                    <ion-label>
                        <p class="item-heading">{{ 'addon.mod_quiz.overdue' | translate }}</p>
                        <p>{{ overTime }}</p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="readableMark">
                    <ion-label>
                        <p class="item-heading">{{ 'addon.mod_quiz.marks' | translate }}</p>
                        <p>{{ readableMark }}</p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="readableGrade">
                    <ion-label>
                        <p class="item-heading">{{ 'addon.mod_quiz.grade' | translate }}</p>
                        <p>{{ readableGrade }}</p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngFor="let data of additionalData">
                    <ion-label>
                        <p class="item-heading">{{ data.title }}</p>
                        <core-format-text [component]="component" [componentId]="cmId" [text]="data.content" contextLevel="module"
                            [contextInstanceId]="cmId" [courseId]="courseId">
                        </core-format-text>
                    </ion-label>
                </ion-item>
            </ion-list>
        </ion-card>

        <!-- Questions -->
        <div *ngIf="attempt && questions.length">

            <!-- Questions. -->
            <div *ngFor="let question of questions">
                <ion-card id="addon-mod_quiz-question-{{question.slot}}">
                    <!-- "Header" of the question. -->
                    <ion-item-divider>
                        <ion-label class="ion-text-wrap">
                            <h2 *ngIf="question.type !== 'description' && question.questionnumber">
                                {{ 'core.question.questionno' | translate:{$a: question.questionnumber} }}
                            </h2>
                            <h2 *ngIf="question.type === 'description' || !question.questionnumber">
                                {{ 'core.question.information' | translate }}
                            </h2>
                        </ion-label>
                        <div class="ion-text-wrap ion-margin-horizontal addon-mod_quiz-question-note" slot="end"
                            *ngIf="question.status || question.readableMark">
                            <p *ngIf="question.status">{{question.status}}</p>
                            <p *ngIf="question.readableMark" [innerHTML]="question.readableMark"></p>
                        </div>
                    </ion-item-divider>

                    <!-- Body of the question. -->
                    <core-question class="ion-text-wrap" [question]="question" [component]="component" [componentId]="cmId"
                        [attemptId]="attempt.id" [usageId]="attempt.uniqueid" [offlineEnabled]="false" contextLevel="module"
                        [contextInstanceId]="cmId" [courseId]="courseId" [review]="true" [preferredBehaviour]="quiz?.preferredbehaviour">
                    </core-question>
                </ion-card>
            </div>
        </div>

        <div collapsible-footer appearOnBottom *ngIf="loaded && numPages > 1" slot="fixed">
            <ion-row class="ion-justify-content-between ion-align-items-center ion-no-padding ion-wrap">
                <ion-col class="ion-text-start ion-no-padding core-navigation-arrow" size="auto" *ngIf="!showAll">
                    <ion-button [disabled]="previousPage < 0" fill="clear" [attr.aria-label]="'core.previous' | translate"
                        (click)="changePage(previousPage)">
                        <ion-icon name="fas-chevron-left" slot="icon-only" aria-hidden="true"></ion-icon>
                    </ion-button>
                </ion-col>
                <ion-col class="ion-text-center">
                    <!-- In review we can toggle between all questions in same page or one page at a time. -->
                    <ion-button class="ion-text-wrap" *ngIf="numPages > 1" (click)="switchMode()" fill="outline">
                        <span *ngIf="!showAll">{{ 'addon.mod_quiz.showall' | translate }}</span>
                        <span *ngIf="showAll">{{ 'addon.mod_quiz.showeachpage' | translate }}</span>
                    </ion-button>
                </ion-col>
                <ion-col class="ion-text-end ion-no-padding core-navigation-arrow" size="auto" *ngIf="!showAll">
                    <ion-button [disabled]="nextPage >= numPages" fill="clear" [attr.aria-label]="'core.next' | translate"
                        (click)="changePage(nextPage)">
                        <ion-icon name="fas-chevron-right" slot="icon-only" aria-hidden="true"></ion-icon>
                    </ion-button>
                </ion-col>
            </ion-row>
        </div>
    </core-loading>
</ion-content>
