<ion-header>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-back-button [text]="'core.back' | translate" />
        </ion-buttons>
        <ion-title>
            <h1>{{ 'addon.mod_chat.messages' | translate }}</h1>
        </ion-title>
    </ion-toolbar>
</ion-header>
<ion-content>
    <ion-refresher slot="fixed" [disabled]="!loaded" (ionRefresh)="refreshMessages($event.target)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}" />
    </ion-refresher>
    <core-loading [hideUntil]="loaded">
        <ion-list class="addon-messages-discussion-container">
            <ng-container *ngFor="let message of messages; index as index;">

                <div class="ion-text-center addon-messages-date" *ngIf="message.showDate">
                    {{ message.timestamp * 1000 | coreFormatDate:"strftimedayshort" }}
                </div>

                <div class="ion-text-center addon-mod_chat-notice" *ngIf="message.special">
                    <ion-badge class="ion-text-wrap" color="success" *ngIf="message.issystem && message.message === 'enter'">
                        <span>
                            <ion-icon name="fas-right-to-bracket" aria-hidden="true" />
                            {{ message.timestamp * 1000 | coreFormatDate:"strftimetime" }}
                            {{ 'addon.mod_chat.messageenter' | translate:{$a: message.userfullname} }}
                        </span>
                    </ion-badge>

                    <ion-badge class="ion-text-wrap" color="danger" *ngIf="message.issystem && message.message === 'exit'">
                        <span>
                            <ion-icon name="fas-right-from-bracket" aria-hidden="true" />
                            {{ message.timestamp * 1000 | coreFormatDate:"strftimetime" }}
                            {{ 'addon.mod_chat.messageexit' | translate:{$a: message.userfullname} }}
                        </span>
                    </ion-badge>

                    <ion-badge class="ion-text-wrap" color="primary" *ngIf="message.beep === 'all'">
                        <span>
                            <ion-icon name="fas-bell" aria-hidden="true" />
                            {{ message.timestamp * 1000 | coreFormatDate:"strftimetime" }}
                            {{ 'addon.mod_chat.messagebeepseveryone' | translate:{$a: message.userfullname} }}
                        </span>
                    </ion-badge>

                    <ion-badge class="ion-text-wrap" color="primary"
                        *ngIf="message.userid !== currentUserId && message.beep === currentUserId">
                        <span>
                            <ion-icon name="fas-bell" aria-hidden="true" />
                            {{ message.timestamp * 1000 | coreFormatDate:"strftimetime" }}
                            {{ 'addon.mod_chat.messagebeepsyou' | translate:{$a: message.userfullname} }}
                        </span>
                    </ion-badge>

                    <ion-badge class="ion-text-wrap" color="light"
                        *ngIf="message.userid === currentUserId && message.beep && message.beep !== 'all'">
                        <span>
                            <ion-icon name="fas-bell" aria-hidden="true" />
                            {{ message.timestamp * 1000 | coreFormatDate:"strftimetime" }}
                            {{ 'addon.mod_chat.messageyoubeep' | translate:{$a: message.beepWho} }}
                        </span>
                    </ion-badge>

                    <ion-badge class="ion-text-wrap" color="info" *ngIf="!message.issystem && !message.beep">
                        <span>
                            <ion-icon name="fas-asterisk" aria-hidden="true" />
                            {{ message.timestamp * 1000 | coreFormatDate:"strftimetime" }}
                            <strong>
                                {{ message.userfullname }} <core-format-text [text]="message.message" contextLevel="module"
                                    [contextInstanceId]="cmId" [courseId]="courseId" />
                            </strong>
                        </span>
                    </ion-badge>
                </div>

                <core-message *ngIf="!message.special" [message]="message" [user]="message" [text]="message.message"
                    [time]="message.timestamp * 1000" contextLevel="module" [instanceId]="cmId" [courseId]="courseId" />
            </ng-container>
        </ion-list>
    </core-loading>
</ion-content>
