<ion-header>
    <ion-navbar core-back-button>
        <ion-title>
            <img *ngIf="event && event.moduleIcon" src="{{event.moduleIcon}}" alt="" role="presentation" class="core-module-icon">
            <core-icon *ngIf="event && event.icon && !event.moduleIcon" [name]="event.icon" item-start></core-icon>
            <core-format-text *ngIf="event" [text]="event.name"></core-format-text>
        </ion-title>
        <ion-buttons end>
            <!-- The context menu will be added in here. -->
        </ion-buttons>
    </ion-navbar>
</ion-header>
<core-navbar-buttons end>
    <core-context-menu>
        <core-context-menu-item [hidden]="isSplitViewOn || !eventLoaded || (!hasOffline && !event.deleted) || !isOnline"  [priority]="400" [content]="'core.settings.synchronizenow' | translate" (action)="doRefresh(null, $event, true)" [iconAction]="syncIcon" [closeOnClick]="false"></core-context-menu-item>
        <core-context-menu-item [hidden]="!canEdit || !event || !event.canedit || event.deleted" [priority]="300" [content]="'core.edit' | translate" (action)="openEdit()" [iconAction]="'create'"></core-context-menu-item>
        <core-context-menu-item [hidden]="!canDelete || !event || !event.candelete || event.deleted" [priority]="200" [content]="'core.delete' | translate" (action)="deleteEvent()" [iconAction]="'trash'"></core-context-menu-item>
        <core-context-menu-item [hidden]="!event || !event.deleted" [priority]="200" [content]="'core.restore' | translate" (action)="undoDelete()" [iconAction]="'undo'"></core-context-menu-item>
    </core-context-menu>
</core-navbar-buttons>
<ion-content>
    <ion-refresher [enabled]="eventLoaded" (ionRefresh)="doRefresh($event)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
    </ion-refresher>
    <core-loading [hideUntil]="eventLoaded">
        <!-- There is data to be synchronized -->
        <ion-card class="core-warning-card" icon-start *ngIf="hasOffline || event.deleted">
            <ion-icon name="warning"></ion-icon> {{ 'core.hasdatatosync' | translate:{$a: 'addon.calendar.calendarevent' | translate} }}
        </ion-card>

        <ion-card>
            <ion-card-content *ngIf="event">
                <ion-item text-wrap *ngIf="isSplitViewOn">
                    <img *ngIf="event.moduleIcon" src="{{event.moduleIcon}}" item-start alt="" role="presentation" class="core-module-icon">
                    <core-icon *ngIf="event.icon && !event.moduleIcon" [name]="event.icon" item-start></core-icon>
                    <h2>{{ 'addon.calendar.eventname' | translate }}</h2>
                    <p><core-format-text [text]="event.name"></core-format-text></p>
                    <ion-note item-end *ngIf="event.deleted">
                        <ion-icon name="trash"></ion-icon> {{ 'core.deletedoffline' | translate }}
                    </ion-note>
                </ion-item>
                <ion-item>
                    <h2>{{ 'addon.calendar.when' | translate }}</h2>
                    <p><core-format-text [text]="event.formattedtime"></core-format-text></p>
                    <ion-note item-end *ngIf="!isSplitViewOn && event.deleted">
                        <ion-icon name="trash"></ion-icon> {{ 'core.deletedoffline' | translate }}
                    </ion-note>
                </ion-item>
                <ion-item>
                    <h2>{{ 'addon.calendar.eventtype' | translate }}</h2>
                    <p>{{ 'addon.calendar.type' + event.formattedType | translate }}</p>
                </ion-item>
                <a ion-item text-wrap *ngIf="courseName" [href]="courseUrl" core-link capture="true">
                    <h2>{{ 'core.course' | translate}}</h2>
                    <p><core-format-text [text]="courseName"></core-format-text></p>
                </a>
                <ion-item text-wrap *ngIf="groupName">
                    <h2>{{ 'core.group' | translate}}</h2>
                    <p>{{ groupName }}</p>
                </ion-item>
                <a ion-item text-wrap *ngIf="categoryPath">
                    <h2>{{ 'core.category' | translate}}</h2>
                    <p><core-format-text [text]="categoryPath"></core-format-text></p>
                </a>
                <ion-item text-wrap *ngIf="event.description">
                    <h2>{{ 'core.description' | translate}}</h2>
                    <p>
                        <core-format-text [text]="event.description"></core-format-text>
                    </p>
                </ion-item>
                <ion-item text-wrap *ngIf="event.location">
                    <h2>{{ 'core.location' | translate}}</h2>
                    <p>
                        <a [href]="event.encodedLocation" core-link auto-login="no">
                            <core-format-text [text]="event.location"></core-format-text>
                        </a>
                    </p>
                </ion-item>
                <ion-item *ngIf="moduleUrl">
                    <a ion-button block color="primary" [href]="moduleUrl" core-link capture="true">{{ 'addon.calendar.gotoactivity' | translate }}</a>
                </ion-item>
            </ion-card-content>
        </ion-card>

        <ion-card list *ngIf="notificationsEnabled">
            <ion-item>
                <h2>{{ 'addon.calendar.reminders' | translate }}</h2>
            </ion-item>
            <ng-container *ngFor="let reminder of reminders">
                <ion-item  text-wrap *ngIf="reminder.time > 0 || defaultTime > 0" [class.item-dimmed]="(reminder.time == -1 ? (event.timestart - defaultTime) : reminder.time) <= currentTime" >
                    <p *ngIf="reminder.time == -1">{{ 'core.defaultvalue' | translate :{$a: ((event.timestart - defaultTime) * 1000) | coreFormatDate } }}</p>
                    <p *ngIf="reminder.time > 0">{{ reminder.time * 1000 | coreFormatDate }}</p>
                    <button ion-button icon-only clear="true" (click)="cancelNotification(reminder.id, $event)" [attr.aria-label]=" 'core.delete' | translate" item-end *ngIf="(reminder.time == -1 ? (event.timestart - defaultTime) : reminder.time) > currentTime">
                        <ion-icon name="trash" color="danger"></ion-icon>
                    </button>
                </ion-item>
            </ng-container>

            <ng-container *ngIf="event.timestart + event.timeduration > currentTime">
                <ion-item>
                    <ion-label stacked><h2>{{ 'addon.calendar.setnewreminder' | translate }}</h2></ion-label>
                    <ion-datetime [(ngModel)]="notificationTimeText" [placeholder]="'core.choosedots' | translate" [displayFormat]="notificationFormat" [min]="notificationMin" [max]="notificationMax"></ion-datetime>
                </ion-item>
                <ion-item>
                    <button ion-button block color="primary" (click)="addNotificationTime($event)" [disabled]="!notificationTimeText">{{ 'core.save' | translate }}</button>
                </ion-item>
            </ng-container>
        </ion-card>
    </core-loading>
</ion-content>
