<ion-header>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-back-button [text]="'core.back' | translate"></ion-back-button>
        </ion-buttons>
        <ion-title>
            <core-format-text [text]="title" contextLevel="module" [contextInstanceId]="workshop && workshop.coursemodule"
                [courseId]="courseId">
            </core-format-text>
        </ion-title>
        <ion-buttons slot="end" [hidden]="!evaluating">
            <ion-button fill="clear" (click)="saveEvaluation()" [attr.aria-label]="'core.save' | translate">
                {{ 'core.save' | translate }}
            </ion-button>
        </ion-buttons>
    </ion-toolbar>
</ion-header>
<ion-content>
    <ion-refresher slot="fixed" [disabled]="!loaded" (ionRefresh)="refreshAssessment($event.target)" *ngIf="!evaluating">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
    </ion-refresher>
    <core-loading [hideUntil]="loaded">

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

            <ion-label>
                <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="workshop && 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-label>
        </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" #evaluateFormEl>
            <ion-item class="ion-text-wrap">
                <ion-label><h2>{{ 'addon.mod_workshop.assessmentsettings' | translate }}</h2></ion-label>
            </ion-item>
            <ion-item class="ion-text-wrap" *ngIf="access?.canallocate">
                <ion-label position="stacked">
                    <span core-mark-required="true">
                        {{ 'addon.mod_workshop.assessmentweight' | translate }}
                    </span>
                </ion-label>
                <ion-select formControlName="weight" required="true" interface="action-sheet">
                    <ion-select-option *ngFor="let w of weights" [value]="w">{{ w }}</ion-select-option>
                </ion-select>
            </ion-item>
            <ion-item class="ion-text-wrap">
                <ion-label>
                    <h2>{{ 'addon.mod_workshop.gradinggradecalculated' | translate }}</h2>
                    <p>{{ assessment.gradinggrade }}</p>
                </ion-label>
            </ion-item>
            <ion-item class="ion-text-wrap" *ngIf="access?.canoverridegrades">
                <ion-label position="stacked">{{ 'addon.mod_workshop.gradinggradeover' | translate }}</ion-label>
                <ion-select formControlName="grade" interface="action-sheet">
                    <ion-select-option *ngFor="let grade of evaluationGrades" [value]="grade.value">
                        {{grade.label}}
                    </ion-select-option>
                </ion-select>
            </ion-item>
            <ion-item *ngIf="access?.canoverridegrades">
                <ion-label position="stacked">{{ 'addon.mod_workshop.feedbackreviewer' | translate }}</ion-label>
                <core-rich-text-editor [control]="evaluateForm.controls['text']" name="text"
                    [autoSave]="true" contextLevel="module" [contextInstanceId]="workshop?.coursemodule"
                    elementId="feedbackreviewer_editor" [draftExtraParams]="{asid: assessmentId}">
                </core-rich-text-editor>
            </ion-item>
        </form>
        <ion-list *ngIf="!evaluating && evaluate && evaluate.text">
            <ion-item class="ion-text-wrap">
                <core-user-avatar *ngIf="evaluateByProfile" [user]="evaluateByProfile" slot="start"
                    [courseId]="courseId" [userId]="evaluateByProfile.id"></core-user-avatar>
                <ion-label>
                    <h2 *ngIf="evaluateByProfile && evaluateByProfile.fullname">
                        {{ 'addon.mod_workshop.feedbackby' | translate : {$a: evaluateByProfile.fullname} }}
                    </h2>
                    <core-format-text [text]="evaluate.text" contextLevel="module" [contextInstanceId]="workshop?.coursemodule"
                        [courseId]="courseId">
                    </core-format-text>
                </ion-label>
            </ion-item>
        </ion-list>
    </core-loading>
</ion-content>
