<ion-header>
    <ion-navbar core-back-button>
        <ion-title>{{ 'addon.notifications.notifications' | translate }}</ion-title>
    </ion-navbar>
</ion-header>
<ion-content>
    <ion-refresher [enabled]="notificationsLoaded" (ionRefresh)="refreshNotifications($event)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
    </ion-refresher>
    <core-loading [hideUntil]="notificationsLoaded">
        <div padding *ngIf="canMarkAllNotificationsAsRead">
            <button ion-button block (click)="markAllNotificationsAsRead()" color="light" icon-start *ngIf="!loadingMarkAllNotificationsAsRead">
                <core-icon name="fa-check"></core-icon>
                {{ 'addon.notifications.markallread' | translate }}
            </button>
            <button ion-button block color="light" icon-start *ngIf="loadingMarkAllNotificationsAsRead">
                <ion-spinner></ion-spinner>
            </button>
        </div>
        <ion-card *ngFor="let notification of notifications">
            <ion-item text-wrap>
                <ion-avatar *ngIf="notification.useridfrom > 0" core-user-avatar [user]="notification" item-start [profileUrl]="notification.profileimageurlfrom" [fullname]="notification.userfromfullname" [userId]="notification.useridfrom" [extraIcon]="notification.iconurl"></ion-avatar>
                <img *ngIf="notification.useridfrom <= 0 && notification.iconurl" [src]="notification.iconurl" alt="" role="presentation" class="core-notification-icon" item-start>
                <h2><core-format-text [text]="notification.subject"></core-format-text></h2>
                <p><ion-note float-end padding-left text-end>
                        {{notification.timecreated | coreDateDayOrTime}}
                        <span *ngIf="!notification.timeread"><core-icon name="fa-circle" color="primary"></core-icon></span>
                    </ion-note>
                </p>
                <p *ngIf="notification.userfromfullname"><core-format-text [text]="notification.userfromfullname"></core-format-text></p>
            </ion-item>
            <ion-item text-wrap>
                <p><core-format-text [text]="notification.mobiletext | coreCreateLinks"></core-format-text></p>
            </ion-item>
            <addon-notifications-actions [contextUrl]="notification.contexturl" [courseId]="notification.courseid" [data]="notification.customdata"></addon-notifications-actions>
        </ion-card>
        <core-empty-box *ngIf="!notifications || notifications.length <= 0" icon="notifications" [message]="'addon.notifications.therearentnotificationsyet' | translate"></core-empty-box>
        <core-infinite-loading [enabled]="canLoadMore" (action)="loadMoreNotifications($event)" [error]="loadMoreError"></core-infinite-loading>
    </core-loading>
</ion-content>
