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

class BsRatingComponent {
    constructor() {
        this.destroyed$ = new Subject();
        this.maximum$ = new BehaviorSubject(5);
        this.value$ = new BehaviorSubject(3);
        this.previewValue$ = new BehaviorSubject(null);
        //#endregion
        //#region Value
        this.valueChange = new EventEmitter();
        this.starsChange = new EventEmitter();
        this.stars$ = combineLatest([this.maximum$, this.previewValue$, this.value$])
            .pipe(map(([maximum, previewValue, value]) => {
            const v = previewValue ?? value;
            return [
                ...[...Array(v).keys()].map(i => true),
                ...[...Array(maximum - v).keys()].map(i => false)
            ];
        }));
        combineLatest([this.previewValue$, this.value$])
            .pipe(takeUntil(this.destroyed$))
            .subscribe(([previewValue, value]) => {
            const v = previewValue ?? value;
            this.starsChange.emit(v);
        });
    }
    //#region Maximum
    set maximum(value) {
        this.maximum$.next(value);
    }
    get value() {
        return this.value$.value;
    }
    set value(value) {
        this.value$.next(value);
        this.valueChange.emit(value);
    }
    //#endregion
    ngOnDestroy() {
        this.destroyed$.next(true);
    }
    hoverValue(index) {
        this.previewValue$.next(index + 1);
    }
    selectValue(index) {
        this.value = index + 1;
    }
    onMouseLeave() {
        this.previewValue$.next(null);
    }
}
BsRatingComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: BsRatingComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
BsRatingComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.0.4", type: BsRatingComponent, selector: "bs-rating", inputs: { maximum: "maximum", value: "value" }, outputs: { valueChange: "valueChange", starsChange: "starsChange" }, host: { listeners: { "mouseleave": "onMouseLeave()" } }, ngImport: i0, template: "<span class=\"cursor-pointer\" *ngFor=\"let star of (stars$ | async), let i = index\" (mouseenter)=\"hoverValue(i)\" (click)=\"selectValue(i)\">\n    {{ star ? '&#9733;' : '&#9734;' }}\n</span>", styles: [""], dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: BsRatingComponent, decorators: [{
            type: Component,
            args: [{ selector: 'bs-rating', template: "<span class=\"cursor-pointer\" *ngFor=\"let star of (stars$ | async), let i = index\" (mouseenter)=\"hoverValue(i)\" (click)=\"selectValue(i)\">\n    {{ star ? '&#9733;' : '&#9734;' }}\n</span>" }]
        }], ctorParameters: function () { return []; }, propDecorators: { maximum: [{
                type: Input
            }], valueChange: [{
                type: Output
            }], starsChange: [{
                type: Output
            }], value: [{
                type: Input
            }], onMouseLeave: [{
                type: HostListener,
                args: ['mouseleave']
            }] } });

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

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

export { BsRatingComponent, BsRatingModule };
//# sourceMappingURL=mintplayer-ng-bootstrap-rating.mjs.map
