<div class="reader" #reader [ngStyle]="{overflow: (isFullscreen ? 'auto' : 'visible')}">
    <div class="fixed-top overlay" *ngIf="menuOpen" [@slideFromTop]="menuOpen">
        <div style="display: flex; margin-top: 5px;">
            <button class="btn btn-icon" style="height: 100%" title="Back" (click)="closeReader()">
                <i class="fa fa-arrow-left" aria-hidden="true"></i>
                <span class="sr-only">Back</span>
            </button>
            
            <div>
                <div style="font-weight: bold;">{{title}} <span class="clickable" *ngIf="incognitoMode" (click)="turnOffIncognito()" role="button" aria-label="Incognito mode is on. Toggle to turn off.">(<i class="fa fa-glasses"  aria-hidden="true"></i><span class="sr-only">Incognito Mode:</span>)</span></div>
                <div class="subtitle">
                    {{subtitle}}
                </div>
            </div>
            <div style="margin-left: auto; padding-right: 3%;">
                <button class="btn btn-icon btn-small" role="checkbox" [attr.aria-checked]="pageBookmarked" title="{{pageBookmarked ? 'Unbookmark Page' : 'Bookmark Page'}}" (click)="bookmarkPage()"><i class="{{pageBookmarked ? 'fa' : 'far'}} fa-bookmark" aria-hidden="true"></i><span class="sr-only">{{pageBookmarked ? 'Unbookmark Page' : 'Bookmark Page'}}</span></button>
            </div>
        </div>
    </div>
    <ng-container *ngIf="isLoading">
        <div class="spinner-border text-secondary loading" role="status">
            <span class="invisible">Loading...</span>
        </div>
    </ng-container>

    <div (click)="toggleMenu()" class="reading-area">
        <canvas #content class="{{getFittingOptionClass()}} {{readerMode === READER_MODE.MANGA_LR || readerMode === READER_MODE.MANGA_UD ? '' : 'd-none'}} {{showClickOverlay ? 'blur' : ''}}" 
                ondragstart="return false;" onselectstart="return false;">
        </canvas>
        <div class="webtoon-images" *ngIf="readerMode === READER_MODE.WEBTOON && !isLoading">
            <app-infinite-scroller [pageNum]="pageNum" 
            [bufferPages]="5" 
            [goToPage]="goToPageEvent" 
            (pageNumberChange)="handleWebtoonPageChange($event)" 
            [totalPages]="maxPages" 
            [urlProvider]="getPageUrl" 
            (loadNextChapter)="loadNextChapter()" 
            (loadPrevChapter)="loadPrevChapter()"
            [bookmarkPage]="showBookmarkEffectEvent"
            [fullscreenToggled]="fullscreenEvent"></app-infinite-scroller>
        </div>
        <ng-container *ngIf="readerMode === READER_MODE.MANGA_LR || readerMode === READER_MODE.MANGA_UD">
            <div class="pagination-area {{readerMode === READER_MODE.MANGA_LR ? 'right' : 'bottom'}} {{clickOverlayClass('right')}}" (click)="handlePageChange($event, 'right')">
                <div *ngIf="showClickOverlay">
                    <i class="fa fa-angle-{{readingDirection === ReadingDirection.LeftToRight ? 'double-' : ''}}{{readerMode === READER_MODE.MANGA_LR ? 'right' : 'down'}}"
                     title="Next Page" aria-hidden="true"></i>
                </div>
            </div>
            <div class="pagination-area {{readerMode === READER_MODE.MANGA_LR ? 'left' : 'top'}} {{clickOverlayClass('left')}}" (click)="handlePageChange($event, 'left')">
                <div *ngIf="showClickOverlay">
                    <i class="fa fa-angle-{{readingDirection === ReadingDirection.RightToLeft ? 'double-' : ''}}{{readerMode === READER_MODE.MANGA_LR ? 'left' : 'up'}}"
                     title="Previous Page" aria-hidden="true"></i>
                </div>
            </div>
        </ng-container>
    </div>
    
    <div class="fixed-bottom overlay" *ngIf="menuOpen" [@slideFromBottom]="menuOpen">
        <div class="form-group" *ngIf="pageOptions != undefined && pageOptions.ceil != undefined">
            <span class="sr-only" id="slider-info"></span>
            <div class="row no-gutters">
                <button class="btn btn-small btn-icon col-1" [disabled]="prevChapterDisabled" (click)="loadPrevChapter();resetMenuCloseTimer();" title="Prev Chapter/Volume"><i class="fa fa-fast-backward" aria-hidden="true"></i></button>
                <button class="btn btn-small btn-icon col-1" [disabled]="prevPageDisabled || pageNum === 0" (click)="goToPage(0);resetMenuCloseTimer();" title="First Page"><i class="fa fa-step-backward" aria-hidden="true"></i></button>
                <div class="col custom-slider" *ngIf="pageOptions.ceil > 0; else noSlider">
                    <ngx-slider [options]="pageOptions" [value]="pageNum" aria-describedby="slider-info" [manualRefresh]="refreshSlider" (userChangeEnd)="sliderPageUpdate($event);startMenuCloseTimer()" (userChange)="sliderDragUpdate($event)" (userChangeStart)="cancelMenuCloseTimer();"></ngx-slider>
                </div>
                <ng-template #noSlider>
                    <div class="col custom-slider">
                        <ngx-slider [options]="pageOptions" [value]="pageNum" aria-describedby="slider-info" (userChangeEnd)="startMenuCloseTimer()" (userChangeStart)="cancelMenuCloseTimer();"></ngx-slider>
                    </div>
                </ng-template>
                <button class="btn btn-small btn-icon col-2" [disabled]="nextPageDisabled || pageNum >= maxPages - 1" (click)="goToPage(this.maxPages);resetMenuCloseTimer();" title="Last Page"><i class="fa fa-step-forward" aria-hidden="true"></i></button>
                <button class="btn btn-small btn-icon col-1" [disabled]="nextChapterDisabled" (click)="loadNextChapter();resetMenuCloseTimer();" title="Next Chapter/Volume"><i class="fa fa-fast-forward" aria-hidden="true"></i></button>
            </div>
            
            
        </div>
        <div class="row pt-4 ml-2 mr-2">
            <div class="col">
                <button class="btn btn-icon" (click)="setReadingDirection();resetMenuCloseTimer();" [disabled]="readerMode === READER_MODE.WEBTOON || readerMode === READER_MODE.MANGA_UD" aria-describedby="reading-direction" title="Reading Direction: {{readingDirection === ReadingDirection.LeftToRight ? 'Left to Right' : 'Right to Left'}}">
                    <i class="fa fa-angle-double-{{readingDirection === ReadingDirection.LeftToRight ? 'right' : 'left'}}" aria-hidden="true"></i>
                    <span id="reading-direction" class="sr-only">{{readingDirection === ReadingDirection.LeftToRight ? 'Left to Right' : 'Right to Left'}}</span>
                </button>
            </div>
            <div class="col">
                <button class="btn btn-icon" title="Reading Mode" (click)="toggleReaderMode();resetMenuCloseTimer();">
                    <i class="fa {{readerModeIcon}}" aria-hidden="true"></i>
                    <span class="sr-only">Reading Mode</span>
                </button>
            </div>
            <div class="col">
                <button class="btn btn-icon" title="{{this.isFullscreen ? 'Collapse' : 'Fullscreen'}}" (click)="toggleFullscreen();resetMenuCloseTimer();">
                    <i class="fa {{this.isFullscreen ? 'fa-compress-alt' : 'fa-expand-alt'}}" aria-hidden="true"></i>
                    <span class="sr-only">{{this.isFullscreen ? 'Collapse' : 'Fullscreen'}}</span>
                </button>
            </div>
            <div class="col">
                <button class="btn btn-icon" title="Settings" (click)="settingsOpen = !settingsOpen;resetMenuCloseTimer();">
                    <i class="fa fa-sliders-h" aria-hidden="true"></i>
                    <span class="sr-only">Settings</span>
                </button>
            </div>
        </div>
        <div class="bottom-menu" *ngIf="settingsOpen && generalSettingsForm">
            <form [formGroup]="generalSettingsForm">
                <div class="row">
                    <div class="col-6">
                        <label for="page-splitting">Image Splitting</label>&nbsp;
                        <div class="split fa fa-image">
                            <div class="{{splitIconClass}}"></div> 
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="form-group">
                            <select class="form-control" id="page-splitting" formControlName="pageSplitOption">
                                <option *ngFor="let opt of pageSplitOptions" [value]="opt.value">{{opt.text}}</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-6">
                        <label for="page-fitting">Image Scaling</label>&nbsp;<i class="fa {{getFittingIcon()}}" aria-hidden="true"></i>
                    </div>
                    <div class="col-6">
                        <select class="form-control" id="page-fitting" formControlName="fittingOption">
                            <option value="full-height">Height</option>
                            <option value="full-width">Width</option>
                            <option value="original">Original</option>
                        </select>
                    </div>
                </div>

                <div class="row mt-2 mb-2">
                    <div class="col-6">
                        <label for="autoCloseMenu" class="form-check-label">Auto Close Menu</label>
                    </div>
                    <div class="col-6">
                        <div class="form-check">
                            <input id="autoCloseMenu" type="checkbox" aria-label="Admin" class="form-check-input" formControlName="autoCloseMenu">
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    
</div>