import { __decorate } from "tslib";
import { Component, Input, ViewChild } from '@angular/core';
import { UtilTimeService } from '../../../shared/service/utilTime.service';
import { Timer } from '../../../shared/models/index';
import { QuizService } from '../../../shared/service/quiz.service';
let HeaderComponent = class HeaderComponent {
    constructor(utilService, quizService) {
        this.utilService = utilService;
        this.quizService = quizService;
        this.isTotalTimeExceeded = false;
        this.isItemTimeExceeded = false;
    }
    ngOnChanges(changes) {
        if (changes.itemData && changes.itemData.currentValue) {
            this.setItemDetails();
        }
    }
    ngOnInit() {
        this.testData = this.quizService.testData;
        this.instanceData = this.quizService.instanceDetails;
        this.testEngineFeatures = this.quizService.testEngineFeatures;
        this.testModeSettings = this.quizService.testModeSettings;
        this.setQuizTimer();
    }
    /* setting quiz timer  for the header*/
    setQuizTimer() {
        this.quizTimerConfig = new Timer();
        this.quizTimerConfig.isIncrement = true;
        const instanceData = this.quizService.instanceDetails;
        this.quizTimerConfig.timer = instanceData.totalTimeSpent;
        this.quizTimerConfig.limit = instanceData.quizTime;
        this.timePerQuestion = instanceData.questionTime;
        this.quizTime = this.utilService.convertSecondsToTimerFormat(instanceData.quizTime);
    }
    /* Seting iterm details for the latest item recieved from qp base */
    setItemDetails() {
        if (this.itemData) {
            this.timeSpentForItem =
                this.itemData &&
                    this.itemData.userAttemptDetails &&
                    this.itemData.userAttemptDetails.timeSpent
                    ? this.itemData.userAttemptDetails.timeSpent
                    : 0;
            this.isItemTimeExceeded = false;
            this.itemTimerConfig = new Timer();
            this.itemTimerConfig.timer = this.timeSpentForItem;
            this.itemTimerConfig.isIncrement = true;
            this.itemTimerConfig.limit = this.quizService.instanceDetails.questionTime;
        }
    }
    getTotalTimeSpent() {
        return this.quizTimer.getTimer();
    }
    getItemTimeSpent() {
        return this.itemTimer.getTimer();
    }
    itemTimeExceeded() {
        this.isItemTimeExceeded = true;
    }
    totalTimeExceeded() {
        this.isTotalTimeExceeded = true;
    }
    getTimer(time) {
        return this.utilService.convertSecondsToTimerFormat(time);
    }
};
HeaderComponent.ctorParameters = () => [
    { type: UtilTimeService },
    { type: QuizService }
];
__decorate([
    Input('itemData')
], HeaderComponent.prototype, "itemData", void 0);
__decorate([
    Input('testProgress')
], HeaderComponent.prototype, "testProgress", void 0);
__decorate([
    ViewChild('itemTimer')
], HeaderComponent.prototype, "itemTimer", void 0);
__decorate([
    ViewChild('quizTimer')
], HeaderComponent.prototype, "quizTimer", void 0);
HeaderComponent = __decorate([
    Component({
        selector: 'qp-header',
        template: "<div class=\"quiz-header-badges\">\n  <ng-container *ngIf=\"testData && testModeSettings\">\n    <div\n      class=\"quiz-badges-child\"\n      [ngClass]=\"{\n        'badges-exceeded':\n          instanceData.questionTime == 0 ||\n          timeSpentForItem > instanceData.questionTime ||\n          isItemTimeExceeded ||\n          instanceData.quizTime == 0 ||\n          instanceData.totalTimeSpent > instanceData.quizTime ||\n          isTotalTimeExceeded\n      }\"\n      *ngIf=\"\n        testModeSettings.showItemTimeLimit && instanceData.questionTime > 0\n      \"\n    >\n      <span class=\"quiz-bades-label\">Time Allotted Per Question</span>\n      <span class=\"wkqp-badge\">{{ timePerQuestion }} Seconds </span>\n    </div>\n    <div\n      class=\"quiz-badges-child\"\n      *ngIf=\"testModeSettings.showItemTimeSpent; else hiddenItemTimer\"\n      [ngClass]=\"{\n        'badges-exceeded':\n          instanceData.questionTime == 0 ||\n          timeSpentForItem > instanceData.questionTime ||\n          isItemTimeExceeded ||\n          instanceData.quizTime == 0 ||\n          instanceData.totalTimeSpent > instanceData.quizTime ||\n          isTotalTimeExceeded\n      }\"\n    >\n      <span\n        class=\"quiz-bades-label\"\n        *ngIf=\"\n          timeSpentForItem < instanceData.questionTime && !isItemTimeExceeded\n        \"\n        >Time Spent on Question</span\n      >\n      <span\n        class=\"quiz-bades-label\"\n        *ngIf=\"\n          instanceData.questionTime == 0 ||\n          timeSpentForItem > instanceData.questionTime ||\n          isItemTimeExceeded\n        \"\n        >Time on Question Exceeded</span\n      >\n\n      <span\n        class=\"wkqp-badge\"\n        [ngClass]=\"\n          instanceData.questionTime == 0 ||\n          timeSpentForItem > instanceData.questionTime ||\n          isItemTimeExceeded\n            ? 'wkqp-badge-danger'\n            : 'wkqp-badge-success'\n        \"\n      >\n        <lib-timer\n          #itemTimer\n          [timerConfig]=\"itemTimerConfig\"\n          (timeExceeded)=\"itemTimeExceeded()\"\n        ></lib-timer>\n      </span>\n    </div>\n    <ng-template #hiddenItemTimer>\n      <div class=\"hidden-conatiner\">\n        <lib-timer\n          #itemTimer\n          [timerConfig]=\"itemTimerConfig\"\n          (timeExceeded)=\"itemTimeExceeded()\"\n        ></lib-timer>\n      </div>\n    </ng-template>\n    <div\n      class=\"quiz-badges-child\"\n      *ngIf=\"testModeSettings.showCorrect && testProgress\"\n      [ngClass]=\"{\n        'badges-exceeded':\n          instanceData.questionTime == 0 ||\n          timeSpentForItem > instanceData.questionTime ||\n          isItemTimeExceeded ||\n          instanceData.quizTime == 0 ||\n          instanceData.totalTimeSpent > instanceData.quizTime ||\n          isTotalTimeExceeded\n      }\"\n    >\n      <span class=\"quiz-bades-label\">Correct</span>\n\n      <span class=\"wkqp-badge\">{{ testProgress.totalCorrectAnswers }}</span>\n    </div>\n    <div\n      class=\"quiz-badges-child\"\n      [ngClass]=\"{\n        'badges-exceeded':\n          instanceData.questionTime == 0 ||\n          timeSpentForItem > instanceData.questionTime ||\n          isItemTimeExceeded ||\n          instanceData.quizTime == 0 ||\n          instanceData.totalTimeSpent > instanceData.quizTime ||\n          isTotalTimeExceeded\n      }\"\n      *ngIf=\"testModeSettings.showIncorrect && testProgress\"\n    >\n      <span class=\"quiz-bades-label\">Incorrect</span>\n\n      <span class=\"wkqp-badge\">{{ testProgress.totalWrongAnswers }}</span>\n    </div>\n    <div\n      class=\"quiz-badges-child\"\n      [ngClass]=\"{\n        'badges-exceeded':\n          instanceData.questionTime == 0 ||\n          timeSpentForItem > instanceData.questionTime ||\n          isItemTimeExceeded ||\n          instanceData.quizTime == 0 ||\n          instanceData.totalTimeSpent > instanceData.quizTime ||\n          isTotalTimeExceeded\n      }\"\n      *ngIf=\"testModeSettings.showUnanswered && testProgress\"\n    >\n      <span class=\"quiz-bades-label\">Unanswered</span>\n\n      <span class=\"wkqp-badge\">{{ testProgress.totalUnAttempted }}</span>\n    </div>\n    <div\n      class=\"quiz-badges-child\"\n      [ngClass]=\"{\n        'badges-exceeded':\n          instanceData.questionTime == 0 ||\n          timeSpentForItem > instanceData.questionTime ||\n          isItemTimeExceeded ||\n          instanceData.quizTime == 0 ||\n          instanceData.totalTimeSpent > instanceData.quizTime ||\n          isTotalTimeExceeded\n      }\"\n      *ngIf=\"testModeSettings.showTestTimeLimit && instanceData.quizTime > 0\"\n    >\n      <span class=\"quiz-bades-label\">Time Allotted for Quiz</span>\n\n      <span class=\"wkqp-badge\">{{ quizTime }}</span>\n    </div>\n    <div\n      class=\"quiz-badges-child\"\n      [ngClass]=\"{\n        'badges-exceeded':\n          instanceData.questionTime == 0 ||\n          timeSpentForItem > instanceData.questionTime ||\n          isItemTimeExceeded ||\n          instanceData.quizTime == 0 ||\n          instanceData.totalTimeSpent > instanceData.quizTime ||\n          isTotalTimeExceeded\n      }\"\n      *ngIf=\"testModeSettings.showTestTimeSpent; else hiddenQuizTimer\"\n    >\n      <span\n        class=\"quiz-bades-label\"\n        *ngIf=\"\n          instanceData.totalTimeSpent < instanceData.quizTime &&\n          !isTotalTimeExceeded\n        \"\n        >Time Spent on Quiz</span\n      >\n      <span\n        class=\"quiz-bades-label\"\n        *ngIf=\"\n          instanceData.quizTime == 0 ||\n          instanceData.totalTimeSpent > instanceData.quizTime ||\n          isTotalTimeExceeded\n        \"\n        >Time on Quiz Exceeded</span\n      >\n\n      <span\n        class=\"wkqp-badge\"\n        [ngClass]=\"\n          instanceData.quizTime == 0 ||\n          instanceData.totalTimeSpent > instanceData.quizTime ||\n          isTotalTimeExceeded\n            ? 'wkqp-badge-danger'\n            : 'wkqp-badge-success'\n        \"\n      >\n        <lib-timer\n          #quizTimer\n          [timerConfig]=\"quizTimerConfig\"\n          (timeExceeded)=\"totalTimeExceeded()\"\n        ></lib-timer>\n      </span>\n    </div>\n    <ng-template #hiddenQuizTimer>\n      <div class=\"hidden-conatiner\">\n        <lib-timer\n          #quizTimer\n          [timerConfig]=\"quizTimerConfig\"\n          (timeExceeded)=\"totalTimeExceeded()\"\n        ></lib-timer>\n      </div>\n    </ng-template>\n    <div\n      class=\"quiz-badges-child\"\n      [ngClass]=\"{\n        'badges-exceeded':\n          instanceData.questionTime == 0 ||\n          timeSpentForItem > instanceData.questionTime ||\n          isItemTimeExceeded ||\n          instanceData.quizTime == 0 ||\n          instanceData.totalTimeSpent > instanceData.quizTime ||\n          isTotalTimeExceeded\n      }\"\n      *ngIf=\"testModeSettings.showItems\"\n    >\n      <span class=\"quiz-bades-label\">Question</span>\n\n      <span class=\"wkqp-badge\"\n        >{{ itemData && itemData.sequence ? itemData.sequence : '' }} of\n        {{ instanceData.numberOfQuestions }}</span\n      >\n    </div>\n  </ng-container>\n</div>\n",
        styles: [".quiz-header-badges{display:flex;padding:10px;background:var(--secondary-color)}.quiz-badges-child:last-child{padding-right:0}.quiz-bades-label{padding-bottom:5px;line-height:18px;display:block;min-height:40px}table.correct-inline-text span.wkqp-badge{white-space:normal}.hidden-conatiner{display:none}"]
    })
], HeaderComponent);
export { HeaderComponent };
//# sourceMappingURL=data:application/json;base64, 