<ion-header>
    <ion-navbar core-back-button>
        <ion-title><core-format-text [text]="title"></core-format-text></ion-title>
        <ion-buttons end [hidden]="!evaluating">
            <button ion-button clear (click)="saveEvaluation()" [attr.aria-label]="'core.save' | translate">
                {{ 'core.save' | translate }}
            </button>
        </ion-buttons>
    </ion-navbar>
</ion-header>
<ion-content>
    <ion-refresher [enabled]="loaded" (ionRefresh)="refreshAssessment($event)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
    </ion-refresher>
    <core-loading [hideUntil]="loaded">

        <ion-item text-wrap>
            <ion-avatar *ngIf="profile" core-user-avatar [user]="profile" item-start [courseId]="courseId" [userId]="profile.id"></ion-avatar>

            <h2 *ngIf="profile && profile.fullname">{{profile.fullname}}</h2>

            <p *ngIf="workshop && assessment && showGrade(assessment.grade)">
                {{ 'addon.mod_workshop.submissiongradeof' | translate:{$a: workshop.grade } }}: {{assessment.grade}}
            </p>
            <p *ngIf="access && access.canviewallsubmissions && assessment && showGrade(assessment.gradinggrade)" [class.core-has-overriden-grade]=" showGrade(assessment.gradinggrade)">
                {{ 'addon.mod_workshop.gradinggradeof' | translate:{$a: workshop.gradinggrade } }}: {{assessment.gradinggrade}}
            </p>
            <p *ngIf="access && access.canviewallsubmissions && assessment && showGrade(assessment.gradinggradeover)" class="core-overriden-grade">
                {{ 'addon.mod_workshop.gradinggradeover' | translate }}: {{assessment.gradinggradeover}}
            </p>
            <p *ngIf="assessment && assessment.weight && assessment.weight != 1">
                {{ 'addon.mod_workshop.weightinfo' | translate:{$a: assessment.weight } }}
            </p>
            <ion-badge *ngIf="!assessment || !showGrade(assessment.grade)" color="danger">
                {{ 'addon.mod_workshop.notassessed' | translate }}
            </ion-badge>
        </ion-item>

        <addon-mod-workshop-assessment-strategy *ngIf="assessment && assessmentId && showGrade(assessment.grade) && workshop && access" [workshop]="workshop" [access]="access" [assessmentId]="assessmentId" [userId]="profile && profile.id" [strategy]="strategy"></addon-mod-workshop-assessment-strategy>

        <form ion-list [formGroup]="evaluateForm" *ngIf="evaluating">
            <ion-item text-wrap>
                <h2>{{ 'addon.mod_workshop.assessmentsettings' | translate }}</h2>
            </ion-item>
            <ion-item text-wrap *ngIf="access.canallocate">
                <ion-label stacked core-mark-required="true">{{ 'addon.mod_workshop.assessmentweight' | translate }}</ion-label>
                <ion-select formControlName="weight" required="true" interface="action-sheet">
                    <ion-option *ngFor="let w of weights" [value]="w">{{ w }}</ion-option>
                </ion-select>
            </ion-item>
            <ion-item text-wrap>
                <h2>{{ 'addon.mod_workshop.gradinggradecalculated' | translate }}</h2>
                <p>{{ assessment.gradinggrade }}</p>
            </ion-item>
            <ion-item text-wrap *ngIf="access.canoverridegrades">
                <ion-label stacked>{{ 'addon.mod_workshop.gradinggradeover' | translate }}</ion-label>
                <ion-select formControlName="grade" interface="action-sheet">
                    <ion-option *ngFor="let grade of evaluationGrades" [value]="grade.value">{{grade.label}}</ion-option>
                </ion-select>
            </ion-item>
            <ion-item *ngIf="access.canoverridegrades">
                <ion-label stacked>{{ 'addon.mod_workshop.feedbackreviewer' | translate }}</ion-label>
                <core-rich-text-editor item-content [control]="evaluateForm.controls['text']" formControlName="text"></core-rich-text-editor>
            </ion-item>
        </form>
        <ion-list *ngIf="!evaluating && evaluate && evaluate.text">
            <ion-item text-wrap>
                <ion-avatar core-user-avatar *ngIf="evaluateGradingByProfile" [user]="evaluateGradingByProfile" item-start [courseId]="courseId" [userId]="evaluateGradingByProfile.id"></ion-avatar>
                <h2 *ngIf="evaluateGradingByProfile && evaluateGradingByProfile.fullname">{{ 'addon.mod_workshop.feedbackby' | translate : {$a: evaluateGradingByProfile.fullname} }}</h2>
                <core-format-text [text]="evaluate.text"></core-format-text>
            </ion-item>
        </ion-list>
    </core-loading>
</ion-content>
