import * as i0 from '@angular/core';
import { EventEmitter, Component, Output, Input, NgModule } from '@angular/core';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import { BehaviorSubject, Subject, combineLatest, takeUntil, map } from 'rxjs';

class BsPaginationComponent {
    constructor() {
        /** All page numbers. */
        this.pageNumbers$ = new BehaviorSubject([]);
        /** Selected number. */
        this.selectedPageNumber$ = new BehaviorSubject(1);
        /** Number of boxes. */
        this.numberOfBoxes$ = new BehaviorSubject(0);
        /** Display previous/next arrows. */
        this.showArrows$ = new BehaviorSubject(true);
        /** Page number size. */
        this.size$ = new BehaviorSubject('medium');
        //#region SelectedPageNumber
        this.selectedPageNumberChange = new EventEmitter();
        this.destroyed$ = new Subject();
        this.visibleNumberOfNumberBoxes$ = combineLatest([
            this.numberOfBoxes$,
            this.pageNumbers$,
            this.showArrows$,
        ])
            .pipe(takeUntil(this.destroyed$))
            .pipe(map(([numberOfBoxes, pageNumbers, showArrows]) => {
            if (numberOfBoxes <= 0) {
                return pageNumbers.length;
            }
            else if (!showArrows) {
                return Math.min(numberOfBoxes, pageNumbers.length);
            }
            else if (numberOfBoxes <= 2) {
                return Math.min(1, pageNumbers.length);
            }
            else {
                return Math.min(numberOfBoxes - 2, pageNumbers.length);
            }
        }));
        this.isLeftOverflow$ = combineLatest([this.pageNumbers$, this.selectedPageNumber$, this.visibleNumberOfNumberBoxes$])
            .pipe(map(([pageNumbers, selectedPageNumber, visibleNumberOfNumberBoxes]) => {
            const index = pageNumbers.indexOf(selectedPageNumber);
            const middle = Math.floor(visibleNumberOfNumberBoxes / 2);
            return index > middle;
        }));
        this.isRightOverflow$ = combineLatest([this.pageNumbers$, this.selectedPageNumber$, this.visibleNumberOfNumberBoxes$])
            .pipe(map(([pageNumbers, selectedPageNumber, visibleNumberOfNumberBoxes]) => {
            const index = pageNumbers.indexOf(selectedPageNumber);
            const middle = Math.floor(visibleNumberOfNumberBoxes / 2);
            return (pageNumbers.length - index) < middle;
        }));
        this.shownPageNumbers$ = combineLatest([
            this.pageNumbers$,
            this.selectedPageNumber$,
            this.visibleNumberOfNumberBoxes$,
            this.isLeftOverflow$,
            this.isRightOverflow$
        ])
            .pipe(takeUntil(this.destroyed$))
            .pipe(map(([pageNumbers, selectedPageNumber, visibleNumberOfNumberBoxes, isLeftOverflow, isRightOverflow]) => {
            // const boxesToRemove = pageNumbers.length - visibleNumberOfNumberBoxes
            //   + (isLeftOverflow ? 1 : 0)
            //   + (isRightOverflow ? 1 : 0);
            // let result: number[] = [];
            // result.push(pageNumbers[0]);
            // // ...
            // result.push(pageNumbers[pageNumbers.length - 1]);
            let startIndex = 0;
            const half = Math.round((visibleNumberOfNumberBoxes - 1) / 2);
            if (pageNumbers.indexOf(selectedPageNumber) < half) {
                startIndex = 0;
            }
            else if (pageNumbers.indexOf(selectedPageNumber) >=
                pageNumbers.length - half) {
                startIndex = pageNumbers.length - visibleNumberOfNumberBoxes;
            }
            else {
                startIndex = pageNumbers.indexOf(selectedPageNumber) - half;
            }
            return [...Array(visibleNumberOfNumberBoxes).keys()]
                .map((p) => p + startIndex)
                .map((p) => ({
                page: pageNumbers[p],
                selected: pageNumbers[p] === selectedPageNumber,
            }));
        }));
        this.isFirstPage$ = combineLatest([
            this.pageNumbers$,
            this.selectedPageNumber$,
        ])
            .pipe(takeUntil(this.destroyed$))
            .pipe(map(([pageNumbers, selectedPageNumber]) => {
            return pageNumbers.indexOf(selectedPageNumber) === 0;
        }));
        this.isLastPage$ = combineLatest([
            this.pageNumbers$,
            this.selectedPageNumber$,
        ])
            .pipe(takeUntil(this.destroyed$))
            .pipe(map(([pageNumbers, selectedPageNumber]) => {
            return (pageNumbers.indexOf(selectedPageNumber) === pageNumbers.length - 1);
        }));
        this.selectedPageNumber$
            .pipe(takeUntil(this.destroyed$))
            .subscribe((selectedPageNumber) => {
            this.selectedPageNumberChange.emit(selectedPageNumber);
        });
    }
    set selectedPageNumber(value) {
        this.selectedPageNumber$.next(value);
    }
    get selectedPageNumber() {
        return this.selectedPageNumber$.value;
    }
    //#endregion
    //#region NumberOfBoxes
    set numberOfBoxes(value) {
        this.numberOfBoxes$.next(value);
    }
    get numberOfBoxes() {
        return this.numberOfBoxes$.value;
    }
    //#endregion
    //#region PageNumbers
    set pageNumbers(value) {
        this.pageNumbers$.next(value);
    }
    get pageNumbers() {
        return this.pageNumbers$.value;
    }
    //#endregion
    //#region ShowArrows
    set showArrows(value) {
        this.showArrows$.next(value);
    }
    get showArrows() {
        return this.showArrows$.value;
    }
    //#endregion
    //#region Size
    set size(value) {
        this.size$.next(value);
    }
    get size() {
        return this.size$.value;
    }
    //#endregion
    ngOnDestroy() {
        this.destroyed$.next(true);
    }
    onSelectPage(event, page) {
        this.selectedPageNumber$.next(page);
        return false;
    }
    onPrevious() {
        const index = this.pageNumbers.indexOf(this.selectedPageNumber);
        if (index > 0) {
            const newValue = this.pageNumbers[index - 1];
            this.selectedPageNumber$.next(newValue);
        }
        else {
            this.selectedPageNumber$.next(this.pageNumbers[0]);
        }
        return false;
    }
    onNext() {
        const index = this.pageNumbers.indexOf(this.selectedPageNumber);
        if (index < 0) {
            this.selectedPageNumber$.next(this.pageNumbers[this.pageNumbers.length - 1]);
        }
        else if (index < this.pageNumbers.length - 1) {
            this.selectedPageNumber$.next(this.pageNumbers[index + 1]);
        }
        else {
            this.selectedPageNumber$.next(this.pageNumbers[this.pageNumbers.length - 1]);
        }
        return false;
    }
    trackByPageNumber(index, page) {
        return page;
    }
}
BsPaginationComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsPaginationComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
BsPaginationComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.7", type: BsPaginationComponent, selector: "bs-pagination", inputs: { selectedPageNumber: "selectedPageNumber", numberOfBoxes: "numberOfBoxes", pageNumbers: "pageNumbers", showArrows: "showArrows", size: "size" }, outputs: { selectedPageNumberChange: "selectedPageNumberChange" }, ngImport: i0, template: "<ul class=\"pagination\">\n    <li class=\"page-item\" *ngIf=\"showArrows$ | async\">\n        <a class=\"page-link\" href=\"\" (click)=\"onPrevious()\" [class.disabled]=\"isFirstPage$ | async\" aria-label=\"Previous\">\n            <span aria-hidden=\"true\">&laquo;</span>\n            <span class=\"visually-hidden\">Previous</span>\n        </a>\n    </li>\n    <li *ngFor=\"let pageNumber of (shownPageNumbers$ | async); trackBy: trackByPageNumber\" class=\"page-item\">\n        <a class=\"page-link\" href=\"\" (click)=\"onSelectPage($event, pageNumber.page)\"\n          [ngClass]=\"{ 'active': pageNumber.selected }\" *ngIf=\"pageNumber.page != '...'\">\n            {{ pageNumber.page }}\n            <span class=\"visually-hidden\" *ngIf=\"pageNumber.selected\">(current)</span>\n        </a>\n    </li>\n    <li class=\"page-item\" *ngIf=\"showArrows$ | async\">\n        <a class=\"page-link\" href=\"\" (click)=\"onNext()\" [class.disabled]=\"isLastPage$ | async\" aria-label=\"Next\">\n            <span aria-hidden=\"true\">&raquo;</span>\n            <span class=\"visually-hidden\">Next</span>\n        </a>\n    </li>\n</ul>", styles: [":host ::ng-deep .pagination{--bs-pagination-padding-x: .75rem;--bs-pagination-padding-y: .375rem;--bs-pagination-font-size: 1rem;--bs-pagination-color: var(--bs-link-color);--bs-pagination-bg: #fff;--bs-pagination-border-width: 1px;--bs-pagination-border-color: #dee2e6;--bs-pagination-border-radius: .375rem;--bs-pagination-hover-color: var(--bs-link-hover-color);--bs-pagination-hover-bg: #e9ecef;--bs-pagination-hover-border-color: #dee2e6;--bs-pagination-focus-color: var(--bs-link-hover-color);--bs-pagination-focus-bg: #e9ecef;--bs-pagination-focus-box-shadow: 0 0 0 .25rem rgba(13, 110, 253, .25);--bs-pagination-active-color: #fff;--bs-pagination-active-bg: #0d6efd;--bs-pagination-active-border-color: #0d6efd;--bs-pagination-disabled-color: #6c757d;--bs-pagination-disabled-bg: #fff;--bs-pagination-disabled-border-color: #dee2e6;display:flex;padding-left:0;list-style:none}:host ::ng-deep .page-link{position:relative;display:block;padding:var(--bs-pagination-padding-y) var(--bs-pagination-padding-x);font-size:var(--bs-pagination-font-size);color:var(--bs-pagination-color);text-decoration:none;background-color:var(--bs-pagination-bg);border:var(--bs-pagination-border-width) solid var(--bs-pagination-border-color);transition:color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out}@media (prefers-reduced-motion: reduce){:host ::ng-deep .page-link{transition:none}}:host ::ng-deep .page-link:hover{z-index:2;color:var(--bs-pagination-hover-color);background-color:var(--bs-pagination-hover-bg);border-color:var(--bs-pagination-hover-border-color)}:host ::ng-deep .page-link:focus{z-index:3;color:var(--bs-pagination-focus-color);background-color:var(--bs-pagination-focus-bg);outline:0;box-shadow:var(--bs-pagination-focus-box-shadow)}:host ::ng-deep .page-link.active,.active>:host ::ng-deep .page-link{z-index:3;color:var(--bs-pagination-active-color);background-color:var(--bs-pagination-active-bg);border-color:var(--bs-pagination-active-border-color)}:host ::ng-deep .page-link.disabled,.disabled>:host ::ng-deep .page-link{color:var(--bs-pagination-disabled-color);pointer-events:none;background-color:var(--bs-pagination-disabled-bg);border-color:var(--bs-pagination-disabled-border-color)}:host ::ng-deep .page-item:not(:first-child) .page-link{margin-left:-1px}:host ::ng-deep .page-item:first-child .page-link{border-top-left-radius:var(--bs-pagination-border-radius);border-bottom-left-radius:var(--bs-pagination-border-radius)}:host ::ng-deep .page-item:last-child .page-link{border-top-right-radius:var(--bs-pagination-border-radius);border-bottom-right-radius:var(--bs-pagination-border-radius)}:host ::ng-deep .pagination-lg{--bs-pagination-padding-x: 1.5rem;--bs-pagination-padding-y: .75rem;--bs-pagination-font-size: 1.25rem;--bs-pagination-border-radius: .5rem}:host ::ng-deep .pagination-sm{--bs-pagination-padding-x: .5rem;--bs-pagination-padding-y: .25rem;--bs-pagination-font-size: .875rem;--bs-pagination-border-radius: .25rem}:host{display:inline-block}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsPaginationComponent, decorators: [{
            type: Component,
            args: [{ selector: 'bs-pagination', template: "<ul class=\"pagination\">\n    <li class=\"page-item\" *ngIf=\"showArrows$ | async\">\n        <a class=\"page-link\" href=\"\" (click)=\"onPrevious()\" [class.disabled]=\"isFirstPage$ | async\" aria-label=\"Previous\">\n            <span aria-hidden=\"true\">&laquo;</span>\n            <span class=\"visually-hidden\">Previous</span>\n        </a>\n    </li>\n    <li *ngFor=\"let pageNumber of (shownPageNumbers$ | async); trackBy: trackByPageNumber\" class=\"page-item\">\n        <a class=\"page-link\" href=\"\" (click)=\"onSelectPage($event, pageNumber.page)\"\n          [ngClass]=\"{ 'active': pageNumber.selected }\" *ngIf=\"pageNumber.page != '...'\">\n            {{ pageNumber.page }}\n            <span class=\"visually-hidden\" *ngIf=\"pageNumber.selected\">(current)</span>\n        </a>\n    </li>\n    <li class=\"page-item\" *ngIf=\"showArrows$ | async\">\n        <a class=\"page-link\" href=\"\" (click)=\"onNext()\" [class.disabled]=\"isLastPage$ | async\" aria-label=\"Next\">\n            <span aria-hidden=\"true\">&raquo;</span>\n            <span class=\"visually-hidden\">Next</span>\n        </a>\n    </li>\n</ul>", styles: [":host ::ng-deep .pagination{--bs-pagination-padding-x: .75rem;--bs-pagination-padding-y: .375rem;--bs-pagination-font-size: 1rem;--bs-pagination-color: var(--bs-link-color);--bs-pagination-bg: #fff;--bs-pagination-border-width: 1px;--bs-pagination-border-color: #dee2e6;--bs-pagination-border-radius: .375rem;--bs-pagination-hover-color: var(--bs-link-hover-color);--bs-pagination-hover-bg: #e9ecef;--bs-pagination-hover-border-color: #dee2e6;--bs-pagination-focus-color: var(--bs-link-hover-color);--bs-pagination-focus-bg: #e9ecef;--bs-pagination-focus-box-shadow: 0 0 0 .25rem rgba(13, 110, 253, .25);--bs-pagination-active-color: #fff;--bs-pagination-active-bg: #0d6efd;--bs-pagination-active-border-color: #0d6efd;--bs-pagination-disabled-color: #6c757d;--bs-pagination-disabled-bg: #fff;--bs-pagination-disabled-border-color: #dee2e6;display:flex;padding-left:0;list-style:none}:host ::ng-deep .page-link{position:relative;display:block;padding:var(--bs-pagination-padding-y) var(--bs-pagination-padding-x);font-size:var(--bs-pagination-font-size);color:var(--bs-pagination-color);text-decoration:none;background-color:var(--bs-pagination-bg);border:var(--bs-pagination-border-width) solid var(--bs-pagination-border-color);transition:color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out}@media (prefers-reduced-motion: reduce){:host ::ng-deep .page-link{transition:none}}:host ::ng-deep .page-link:hover{z-index:2;color:var(--bs-pagination-hover-color);background-color:var(--bs-pagination-hover-bg);border-color:var(--bs-pagination-hover-border-color)}:host ::ng-deep .page-link:focus{z-index:3;color:var(--bs-pagination-focus-color);background-color:var(--bs-pagination-focus-bg);outline:0;box-shadow:var(--bs-pagination-focus-box-shadow)}:host ::ng-deep .page-link.active,.active>:host ::ng-deep .page-link{z-index:3;color:var(--bs-pagination-active-color);background-color:var(--bs-pagination-active-bg);border-color:var(--bs-pagination-active-border-color)}:host ::ng-deep .page-link.disabled,.disabled>:host ::ng-deep .page-link{color:var(--bs-pagination-disabled-color);pointer-events:none;background-color:var(--bs-pagination-disabled-bg);border-color:var(--bs-pagination-disabled-border-color)}:host ::ng-deep .page-item:not(:first-child) .page-link{margin-left:-1px}:host ::ng-deep .page-item:first-child .page-link{border-top-left-radius:var(--bs-pagination-border-radius);border-bottom-left-radius:var(--bs-pagination-border-radius)}:host ::ng-deep .page-item:last-child .page-link{border-top-right-radius:var(--bs-pagination-border-radius);border-bottom-right-radius:var(--bs-pagination-border-radius)}:host ::ng-deep .pagination-lg{--bs-pagination-padding-x: 1.5rem;--bs-pagination-padding-y: .75rem;--bs-pagination-font-size: 1.25rem;--bs-pagination-border-radius: .5rem}:host ::ng-deep .pagination-sm{--bs-pagination-padding-x: .5rem;--bs-pagination-padding-y: .25rem;--bs-pagination-font-size: .875rem;--bs-pagination-border-radius: .25rem}:host{display:inline-block}\n"] }]
        }], ctorParameters: function () { return []; }, propDecorators: { selectedPageNumberChange: [{
                type: Output
            }], selectedPageNumber: [{
                type: Input
            }], numberOfBoxes: [{
                type: Input
            }], pageNumbers: [{
                type: Input
            }], showArrows: [{
                type: Input
            }], size: [{
                type: Input
            }] } });

class BsPaginationModule {
}
BsPaginationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsPaginationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
BsPaginationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.7", ngImport: i0, type: BsPaginationModule, declarations: [BsPaginationComponent], imports: [CommonModule], exports: [BsPaginationComponent] });
BsPaginationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsPaginationModule, imports: [CommonModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsPaginationModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [
                        BsPaginationComponent
                    ],
                    imports: [
                        CommonModule
                    ],
                    exports: [
                        BsPaginationComponent
                    ]
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { BsPaginationComponent, BsPaginationModule };
//# sourceMappingURL=mintplayer-ng-bootstrap-pagination.mjs.map
