<div class="wrapper">
  <div class="content">

    <div *ngIf="test">
      <div class="header">
        <button class="button" (click)="back()"><i class="fas fa-arrow-left"></i> Powrót</button>
        <span>
          <!-- <div *ngIf="currentUser">Twój wynik: {{prevMaxResult}}/{{maxPoints}}</div> -->
          <button title="Usuń" *ngIf="currentUser && currentUser.username === test.owner && (!isStarted || isEnded)" class="btn btn-study-cave" (click)="openPopup()"><i class="fas fa-trash-alt"></i></button>
          <button title="Edytuj" *ngIf="currentUser && currentUser.username === test.owner" class="btn btn-study-cave" (click)="edit()"><i class="fas fa-edit"></i></button>
          <button *ngIf="!isStarted && (test['permission'] !== 'GROUP' || (test['permission'] === 'GROUP' && !test['attempted'] && ((test['dateFrom'] < now && test['dateTo'] > now) || (test['isGroupOwner']))))" title="PDF" class="btn btn-study-cave" (click)="get()"><i class="fas fa-file-pdf"></i></button>
        </span>
      </div>
      <div>
        <h3>{{test.title}}</h3>
      </div>

      <div *ngIf="!isStarted && (test['permission'] !== 'GROUP' || (test['permission'] === 'GROUP' && !test['attempted'] && ((test['dateFrom'] < now && test['dateTo'] > now) || (test['isGroupOwner']))))">
        <br /><br />
        <button class="button" (click)="start()"> <i class="far fa-play-circle"></i> Rozpocznij test</button>
      </div>
      <div *ngIf="!isStarted && test['permission']==='GROUP' && test['attempted']">
        <br /><br />
        <h3>Test już został wcześniej rozwiązany!</h3>
      </div>
      <div *ngIf="!isStarted && test['permission']==='GROUP' && !test['attempted'] && !((test['dateFrom'] < now && test['dateTo'] > now) || (test['isGroupOwner']))">
        <br /><br />
        <h3>Test jest nieaktywny!</h3>
      </div>
      <div *ngIf="isStarted && !isEnded">


        <div class="question-view">
          <br />
          <div *ngIf="prevAnswerResultBool !== undefined && prevAnswerResultBool" class="alert alert-success">
            Poprzednia odpowiedź była poprawna.
          </div>
          <div *ngIf="prevAnswerResultBool !== undefined && !prevAnswerResultBool" class="alert alert-danger">
            Poprzednia odpowiedź była niepoprawna.
          </div>
          <div *ngIf="currentUser">Twój aktualny wynik: {{points}}/{{maxPoints}}</div>
          <app-question-view [question]="test.body[currentQuestionIndex]" [questionIndex]="currentQuestionIndex" [activeFifty]='lifebuoyTest' (emitNextQuestionRequest)="handleEmitNextQuestionRequest($event)" (lifebuoyTest)="LifebuoyFifty($event)" ></app-question-view>
        </div>



      </div>




      <h3 *ngIf="isEnded">
        Koniec pytań. Twój wynik to {{points}}/{{maxPoints}}.
      </h3>


    </div>

    <div *ngIf="test === undefined">
      Błąd. Test nie istnieje lub nie masz do niego dostępu.
    </div>
    <app-comments [what]="'tests'"></app-comments>
  </div>
  <p-dialog header="Potwierdź" [(visible)]="display">
    Czy chcesz usunąć test?
    <p-footer>
        <button type="button" pButton icon="pi pi-check" (click)="deleteTest()" label="TAK" class="button" ></button>
        <button type="button" pButton icon="pi pi-close" (click)="display=false" label="NIE" class="button" ></button>
    </p-footer>
</p-dialog>
</div>
