import * as i0 from '@angular/core';
import { EventEmitter, Component, SkipSelf, Optional, Output, Input, ContentChild, NgModule } from '@angular/core';
import * as i2 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i3 from '@mintplayer/ng-bootstrap/icon';
import { BsIconModule } from '@mintplayer/ng-bootstrap/icon';
import * as i1 from '@mintplayer/ng-bootstrap/list-group';
import { BsListGroupModule } from '@mintplayer/ng-bootstrap/list-group';
import { BehaviorSubject, Subject, map, takeUntil } from 'rxjs';
import { SlideUpDownAnimation } from '@mintplayer/ng-animations';

class BsTreeviewComponent {
    constructor(parent) {
        //#region isExpanded
        this.isExpanded$ = new BehaviorSubject(false);
        this.isExpandedChange = new EventEmitter();
        //#endregion
        this.destroyed$ = new Subject();
        const level = !parent ? 0 : parent.level$.value + 1;
        this.level$ = new BehaviorSubject(level);
        this.indentation$ = this.level$.pipe(map(level => level * 30));
        this.isExpanded$.next(!parent);
        this.isExpanded$
            .pipe(takeUntil(this.destroyed$))
            .subscribe((isExpanded) => this.isExpandedChange.emit(isExpanded));
    }
    get isExpanded() {
        return this.isExpanded$.value;
    }
    set isExpanded(value) {
        this.isExpanded$.next(value);
    }
    ngOnDestroy() {
        this.destroyed$.next(true);
    }
}
BsTreeviewComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsTreeviewComponent, deps: [{ token: BsTreeviewComponent, optional: true, skipSelf: true }], target: i0.ɵɵFactoryTarget.Component });
BsTreeviewComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.7", type: BsTreeviewComponent, selector: "bs-treeview", inputs: { isExpanded: "isExpanded" }, outputs: { isExpandedChange: "isExpandedChange" }, ngImport: i0, template: "<bs-list-group [@slideUpDown]=\"isExpanded$ | async\" class=\"d-block overflow-y-hidden\">\n    <ng-content></ng-content>\n</bs-list-group>", styles: [":host{margin-top:-1px}\n"], dependencies: [{ kind: "component", type: i1.BsListGroupComponent, selector: "bs-list-group" }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }], animations: [SlideUpDownAnimation] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsTreeviewComponent, decorators: [{
            type: Component,
            args: [{ selector: 'bs-treeview', animations: [SlideUpDownAnimation], template: "<bs-list-group [@slideUpDown]=\"isExpanded$ | async\" class=\"d-block overflow-y-hidden\">\n    <ng-content></ng-content>\n</bs-list-group>", styles: [":host{margin-top:-1px}\n"] }]
        }], ctorParameters: function () { return [{ type: BsTreeviewComponent, decorators: [{
                    type: SkipSelf
                }, {
                    type: Optional
                }] }]; }, propDecorators: { isExpandedChange: [{
                type: Output
            }], isExpanded: [{
                type: Input
            }] } });

class BsTreeviewItemComponent {
    constructor(parent) {
        this.parent = parent;
    }
    onClick(ev) {
        if (this.childTree) {
            this.childTree.isExpanded = !this.childTree.isExpanded;
        }
    }
}
BsTreeviewItemComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsTreeviewItemComponent, deps: [{ token: BsTreeviewComponent }], target: i0.ɵɵFactoryTarget.Component });
BsTreeviewItemComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.7", type: BsTreeviewItemComponent, selector: "bs-treeview-item", queries: [{ propertyName: "childTree", first: true, predicate: BsTreeviewComponent }], ngImport: i0, template: "<bs-list-group-item (click)=\"onClick($event)\" class=\"d-block cursor-pointer list-group-item-action\">\n    <span [style.padding-left.px]=\"parent.indentation$ | async\">\n        <bs-icon [icon]=\"'chevron-right'\" [class.open]=\"childTree?.isExpanded$ | async\" [class.invisible]=\"!childTree\" class=\"d-inline-block me-2\"></bs-icon>\n        <ng-content></ng-content>\n    </span>\n</bs-list-group-item>\n<ng-content select=\"bs-treeview\"></ng-content>\n", styles: ["bs-list-group-item{margin-bottom:-1px}bs-icon{transition:transform .2s}bs-icon.open{transform:rotate(90deg)}\n"], dependencies: [{ kind: "component", type: i1.BsListGroupItemComponent, selector: "bs-list-group-item" }, { kind: "component", type: i3.BsIconComponent, selector: "bs-icon", inputs: ["icon"] }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsTreeviewItemComponent, decorators: [{
            type: Component,
            args: [{ selector: 'bs-treeview-item', template: "<bs-list-group-item (click)=\"onClick($event)\" class=\"d-block cursor-pointer list-group-item-action\">\n    <span [style.padding-left.px]=\"parent.indentation$ | async\">\n        <bs-icon [icon]=\"'chevron-right'\" [class.open]=\"childTree?.isExpanded$ | async\" [class.invisible]=\"!childTree\" class=\"d-inline-block me-2\"></bs-icon>\n        <ng-content></ng-content>\n    </span>\n</bs-list-group-item>\n<ng-content select=\"bs-treeview\"></ng-content>\n", styles: ["bs-list-group-item{margin-bottom:-1px}bs-icon{transition:transform .2s}bs-icon.open{transform:rotate(90deg)}\n"] }]
        }], ctorParameters: function () { return [{ type: BsTreeviewComponent }]; }, propDecorators: { childTree: [{
                type: ContentChild,
                args: [BsTreeviewComponent, { descendants: false }]
            }] } });

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

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

export { BsTreeviewComponent, BsTreeviewItemComponent, BsTreeviewModule };
//# sourceMappingURL=mintplayer-ng-bootstrap-treeview.mjs.map
