<ion-header>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-back-button [text]="'core.back' | translate"></ion-back-button>
        </ion-buttons>
        <ion-title *ngIf="plan">{{plan.plan.name}}</ion-title>
    </ion-toolbar>
</ion-header>
<ion-content>
    <ion-refresher slot="fixed" [disabled]="!loaded" (ionRefresh)="refreshLearningPlan($event.target)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
    </ion-refresher>
    <core-loading [hideUntil]="loaded">
        <ion-card *ngIf="user">
            <ion-item class="ion-text-wrap">
                <ion-label>
                    <core-user-avatar [user]="user" slot="start"></core-user-avatar>
                    <h2>{{ user.fullname }}</h2>
                </ion-label>
            </ion-item>
       </ion-card>
        <ion-card *ngIf="plan">
            <ion-list>
                <ion-item class="ion-text-wrap" *ngIf="plan.plan.description" lines="none">
                    <ion-label>
                        <core-format-text [text]="plan.plan.description" contextLevel="user"
                            [contextInstanceId]="plan.plan.userid">
                        </core-format-text>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" lines="none">
                    <ion-label>
                        <p>
                            <strong>{{ 'addon.competency.status' | translate }}</strong>: {{ plan.plan.statusname }}
                        </p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="plan.plan.duedate > 0" lines="none">
                    <ion-label>
                        <p>
                            <strong>{{ 'addon.competency.duedate' | translate }}</strong>:
                            {{ plan.plan.duedate * 1000 | coreFormatDate }}
                        </p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="plan.plan.template" lines="none">
                    <ion-label>
                        <p>
                            <strong>{{ 'addon.competency.template' | translate }}</strong>: {{ plan.plan.template.shortname }}
                        </p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" lines="none">
                    <ion-label>
                        <p>
                            <strong>{{ 'addon.competency.progress' | translate }}</strong>:
                            {{ 'addon.competency.xcompetenciesproficientoutofy' | translate:
                                {$a: {x: plan.proficientcompetencycount, y: plan.competencycount} } }}
                        </p>
                        <core-progress-bar [progress]="plan.proficientcompetencypercentage"
                            [text]="plan.proficientcompetencypercentageformatted"></core-progress-bar>
                    </ion-label>
                </ion-item>
            </ion-list>
        </ion-card>
        <ion-card *ngIf="plan">
            <ion-card-header class="ion-text-wrap">
                <h2>{{ 'addon.competency.learningplancompetencies' | translate }}</h2>
            </ion-card-header>
            <ion-list>
                <ion-item class="ion-text-wrap" *ngIf="plan.competencycount == 0">
                    <ion-label>
                        <p>{{ 'addon.competency.nocompetencies' | translate }}</p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngFor="let competency of plan.competencies"
                    (click)="openCompetency(competency.competency.id)"
                    [attr.aria-label]="competency.competency.shortname" detail="true" button>
                    <ion-label><h2>{{competency.competency.shortname}} <em>{{competency.competency.idnumber}}</em></h2></ion-label>
                    <ion-badge *ngIf="competency.usercompetencyplan" slot="end"
                        [color]="competency.usercompetencyplan.proficiency ? 'success' : 'danger'">
                            {{ competency.usercompetencyplan.gradename }}
                        </ion-badge>
                    <ion-badge *ngIf="!competency.usercompetencyplan" slot="end"
                        [color]="competency.usercompetency.proficiency ? 'success' : 'danger'">
                        {{ competency.usercompetency.gradename }}
                    </ion-badge>
                </ion-item>
            </ion-list>
        </ion-card>
    </core-loading>
</ion-content>
