<!-- Buttons to add to the header. -->
<core-navbar-buttons slot="end">
    <ion-button *ngIf="canSearch" (click)="showSearch()" [attr.aria-label]="'addon.mod_data.search' | translate">
        <ion-icon name="fas-search" slot="icon-only" aria-hidden="true"></ion-icon>
    </ion-button>
    <core-context-menu>
        <core-context-menu-item *ngIf="externalUrl" [priority]="900" [content]="'core.openinbrowser' | translate"
            [href]="externalUrl" iconAction="fas-external-link-alt">
        </core-context-menu-item>
        <core-context-menu-item *ngIf="description" [priority]="800" [content]="'core.moduleintro' | translate"
            (action)="expandDescription()" iconAction="fas-arrow-right">
        </core-context-menu-item>
        <core-context-menu-item *ngIf="blog" [priority]="750" content="{{'addon.blog.blog' | translate}}"
            iconAction="far-newspaper" (action)="gotoBlog()">
        </core-context-menu-item>
        <core-context-menu-item *ngIf="loaded && !(hasOffline || hasOfflineRatings) && isOnline" [priority]="700"
            [content]="'core.refresh' | translate" (action)="doRefresh(null, $event)" [iconAction]="refreshIcon"
            [closeOnClick]="false">
        </core-context-menu-item>
        <core-context-menu-item *ngIf="loaded && (hasOffline || hasOfflineRatings) && isOnline"  [priority]="600"
            [content]="'core.settings.synchronizenow' | translate" (action)="doRefresh(null, $event, true)" [iconAction]="syncIcon"
            [closeOnClick]="false">
        </core-context-menu-item>
        <core-context-menu-item [priority]="500" *ngIf="canAdd" [content]="'addon.mod_data.addentries' | translate"
            iconAction="fas-plus" (action)="gotoAddEntries()">
        </core-context-menu-item>
        <core-context-menu-item [priority]="400" *ngIf="firstEntry" [content]="'addon.mod_data.single' | translate"
            iconAction="fas-file" (action)="gotoEntry(firstEntry)">
        </core-context-menu-item>
        <core-context-menu-item *ngIf="prefetchStatusIcon" [priority]="300" [content]="prefetchText" (action)="prefetch($event)"
            [iconAction]="prefetchStatusIcon" [closeOnClick]="false">
        </core-context-menu-item>
        <core-context-menu-item *ngIf="size" [priority]="200" [content]="'core.clearstoreddata' | translate:{$a: size}"
            iconDescription="fas-archive" (action)="removeFiles($event)" iconAction="fas-trash" [closeOnClick]="false">
        </core-context-menu-item>
    </core-context-menu>
</core-navbar-buttons>

<!-- Content. -->
<core-loading [hideUntil]="loaded" class="core-loading-center">

    <core-course-module-description [description]="description" [component]="component" [componentId]="componentId"
        contextLevel="module" [contextInstanceId]="module.id" [courseId]="courseId">
    </core-course-module-description>

    <!-- Data done in offline but not synchronized -->
    <ion-card class="core-warning-card" *ngIf="hasOffline || hasOfflineRatings">
        <ion-item>
            <ion-icon name="fas-exclamation-triangle" slot="start" aria-hidden="true"></ion-icon>
            <ion-label>{{ 'core.hasdatatosync' | translate: {$a: moduleName} }}</ion-label>
        </ion-item>
    </ion-card>

    <ion-item class="ion-text-wrap" *ngIf="groupInfo && (groupInfo.separateGroups || groupInfo.visibleGroups)">
        <ion-label id="addon-data-groupslabel">
            <ng-container *ngIf="groupInfo.separateGroups">{{'core.groupsseparate' | translate }}</ng-container>
            <ng-container *ngIf="groupInfo.visibleGroups">{{'core.groupsvisible' | translate }}</ng-container>
        </ion-label>
        <ion-select [(ngModel)]="selectedGroup" (ionChange)="setGroup(selectedGroup)" aria-labelledby="addon-data-groupslabel"
            interface="action-sheet">
            <ion-select-option *ngFor="let groupOpt of groupInfo.groups" [value]="groupOpt.id">
                {{groupOpt.name}}
            </ion-select-option>
        </ion-select>
    </ion-item>

    <ion-card class="core-info-card" *ngIf="!access?.timeavailable && timeAvailableFrom">
        <ion-item>
            <ion-icon name="fas-info-circle" slot="start" aria-hidden="true"></ion-icon>
            <ion-label>{{ 'addon.mod_data.notopenyet' | translate:{$a: timeAvailableFromReadable} }}</ion-label>
        </ion-item>
    </ion-card>

    <ion-card class="core-info-card" *ngIf="!access?.timeavailable && timeAvailableTo">
        <ion-item>
            <ion-icon name="fas-info-circle" slot="start" aria-hidden="true"></ion-icon>
            <ion-label>{{ 'addon.mod_data.expired' | translate:{$a: timeAvailableToReadable} }}</ion-label>
        </ion-item>
    </ion-card>

    <ion-card class="core-info-card" *ngIf="access && access.entrieslefttoview">>
        <ion-item>
            <ion-icon name="fas-info-circle" slot="start" aria-hidden="true"></ion-icon>
            <ion-label>
                {{ 'addon.mod_data.entrieslefttoaddtoview' | translate:{$a: {entrieslefttoview: access.entrieslefttoview} } }}
            </ion-label>
        </ion-item>
    </ion-card>

    <ion-card class="core-info-card" *ngIf="access && access.entrieslefttoadd">>
        <ion-item>
            <ion-icon name="fas-info-circle" slot="start" aria-hidden="true"></ion-icon>
            <ion-label>
                {{ 'addon.mod_data.entrieslefttoadd' | translate:{$a: {entriesleft: access.entrieslefttoadd} } }}
            </ion-label>
        </ion-item>
    </ion-card>

    <!-- Reset search. -->
    <ng-container *ngIf="search.searching && !isEmpty">
        <ion-item *ngIf="!foundRecordsTranslationData">
            <ion-label>
                <a (click)="searchReset()">{{ 'addon.mod_data.resetsettings' | translate}}</a>
            </ion-label>
        </ion-item>

        <ion-card class="core-success-card" *ngIf="foundRecordsTranslationData" (click)="searchReset()">
            <ion-item><ion-label>
            <p [innerHTML]="'addon.mod_data.foundrecords' | translate:{$a: foundRecordsTranslationData}"></p>
            </ion-label></ion-item>
        </ion-card>
    </ng-container>

    <div class="addon-data-contents addon-data-entries-{{database.id}} ion-padding-horizontal" *ngIf="!isEmpty && database">
        <core-style [css]="database.csstemplate" prefix=".addon-data-entries-{{database.id}}"></core-style>

        <core-compile-html [text]="entriesRendered" [jsData]="jsData" [extraImports]="extraImports"></core-compile-html>
    </div>

    <ion-grid *ngIf="search.page > 0 || hasNextPage">
        <ion-row class="ion-align-items-center">
            <ion-col *ngIf="search.page > 0">
                <ion-button expand="block" fill="outline" (click)="searchEntries(search.page - 1)">
                    <ion-icon name="fas-chevron-left" slot="start" aria-hidden="true"></ion-icon>
                    {{ 'core.previous' | translate }}
                </ion-button>
            </ion-col>
            <ion-col *ngIf="hasNextPage">
                <ion-button expand="block" (click)="searchEntries(search.page + 1)">
                    {{ 'core.next' | translate }}
                    <ion-icon name="fas-chevron-right" slot="end" aria-hidden="true"></ion-icon>
                </ion-button>
            </ion-col>
        </ion-row>
    </ion-grid>

    <core-empty-box *ngIf="isEmpty && !search.searching" icon="fas-database" [message]="'addon.mod_data.norecords' | translate">
    </core-empty-box>

    <core-empty-box *ngIf="isEmpty && search.searching" icon="fas-database" [message]="'addon.mod_data.nomatch' | translate"
        class="core-empty-box-clickable">
        <a (click)="searchReset()">{{ 'addon.mod_data.resetsettings' | translate}}</a>
    </core-empty-box>

</core-loading>

<ion-fab slot="fixed" core-fab vertical="bottom" horizontal="end" *ngIf="canAdd">
    <ion-fab-button (click)="gotoAddEntries()" [attr.aria-label]="'addon.mod_data.addentries' | translate">
        <ion-icon name="fas-plus" aria-hidden="true"></ion-icon>
    </ion-fab-button>
</ion-fab>
