<ion-content>
    <ion-refresher [enabled]="loaded" (ionRefresh)="refreshData($event)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
    </ion-refresher>

    <core-search-box *ngIf="search.enabled" (onSubmit)="searchMessage($event)" (onClear)="clearSearch($event)" [placeholder]=" 'addon.messages.message' | translate" autocorrect="off" spellcheck="false" lengthCheck="2" [disabled]="!loaded"></core-search-box>

    <core-loading [hideUntil]="loaded" [message]="loadingMessage">

        <ion-list *ngIf="search.showResults" no-margin>
            <ion-item-divider>
                <h2>{{ 'core.searchresults' | translate }}</h2>
                <ion-note item-end>{{ search.results.length }}</ion-note>
            </ion-item-divider>
            <a ion-item text-wrap *ngFor="let result of search.results" [title]="result.fullname" (click)="gotoDiscussion(result.userid, result.messageid)" [class.core-split-item-selected]="result.userid == discussionUserId" class="addon-message-discussion">
                <ion-avatar core-user-avatar [user]="result" item-start [checkOnline]="result.showonlinestatus"></ion-avatar>
                <h2><core-format-text [text]="result.fullname"></core-format-text></h2>
                <p><core-format-text clean="true" singleLine="true" [text]="result.lastmessage"></core-format-text></p>
            </a>
        </ion-list>

        <ion-list *ngIf="!search.showResults" no-margin>
            <a ion-item text-wrap *ngFor="let discussion of discussions" [title]="discussion.fullname" (click)="gotoDiscussion(discussion.message.user)" [class.core-split-item-selected]="discussion.message.user == discussionUserId" class="addon-message-discussion">
                <ion-avatar core-user-avatar [user]="discussion" item-start [checkOnline]="discussion.showonlinestatus"></ion-avatar>
                <h2>
                    <core-format-text [text]="discussion.fullname"></core-format-text>
                </h2>
                <ion-note *ngIf="discussion.message.timecreated > 0 || discussion.unread">
                    <span *ngIf="discussion.unread" class="core-primary-circle"></span>
                    <span *ngIf="discussion.message.timecreated > 0">{{discussion.message.timecreated / 1000 | coreDateDayOrTime}}</span>
                </ion-note>
                <p><core-format-text clean="true" singleLine="true" [text]="discussion.message.message"></core-format-text></p>
            </a>
        </ion-list>

        <core-empty-box *ngIf="(!discussions || discussions.length <= 0) && !search.showResults" icon="chatbubbles" [message]="'addon.messages.nomessagesfound' | translate"></core-empty-box>

        <core-empty-box *ngIf="(!search.results || search.results.length <= 0) && search.showResults" icon="search" [message]="'core.noresults' | translate"></core-empty-box>
    </core-loading>
</ion-content>
