import { Component, ChangeDetectionStrategy, ChangeDetectorRef, ViewChild } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatButtonModule } from '@angular/material/button';
import { FirstUppercaseLocalizeSAPipe } from '@anglr/common';
import { Subscription } from 'rxjs';
import { DragActiveService, LayoutEditorMetadataManager } from '../../services';
import { ComponentsTreeItemSAComponent } from './item';
import { DndBusService } from '../../modules';
import * as i0 from "@angular/core";
import * as i1 from "../../services";
import * as i2 from "@angular/common";
import * as i3 from "@angular/material/button";
/**
 * Component displaying components tree
 */
export class ComponentsTreeSAComponent {
    //######################### constructor #########################
    constructor(_manager, _changeDetector) {
        this._manager = _manager;
        this._changeDetector = _changeDetector;
        //######################### protected fields #########################
        /**
         * Subscriptions created during initialization
         */
        this._initSubscriptions = new Subscription();
    }
    //######################### public methods - implementation of OnInit #########################
    /**
     * Initialize component
     */
    ngOnInit() {
        this._initSubscriptions.add(this._manager.layoutChange.subscribe(() => {
            this.root = this._manager.getMetadata();
            this._changeDetector.detectChanges();
        }));
        this._initSubscriptions.add(this._manager.selectedChange.subscribe(() => {
            var _a;
            (_a = this.rootTreeItem) === null || _a === void 0 ? void 0 : _a.expand(this._manager.selectedComponent);
            this._changeDetector.detectChanges();
        }));
        this._initSubscriptions.add(this._manager.highlightedChange.subscribe(() => this._changeDetector.detectChanges()));
        this._initSubscriptions.add(this._manager.displayNameChange.subscribe(() => this._changeDetector.detectChanges()));
        this.root = this._manager.getMetadata();
    }
    //######################### public methods - implementation of OnDestroy #########################
    /**
     * Called when component is destroyed
     */
    ngOnDestroy() {
        this._initSubscriptions.unsubscribe();
    }
}
ComponentsTreeSAComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: ComponentsTreeSAComponent, deps: [{ token: i1.LayoutEditorMetadataManager }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
ComponentsTreeSAComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.4", type: ComponentsTreeSAComponent, isStandalone: true, selector: "components-tree", providers: [
        DragActiveService,
        DndBusService,
    ], viewQueries: [{ propertyName: "rootTreeItem", first: true, predicate: ComponentsTreeItemSAComponent, descendants: true }], ngImport: i0, template: "\n<div class=\"component-tree\" *ngIf=\"root\">\n    <button type=\"button\" mat-icon-button [attr.aria-label]=\"'collapse all'|firstUppercaseLocalize\"  (click)=\"rootTreeItem?.collapseAll()\">\n        <span class=\"fa fa-minus-square\"></span>\n    </button>\n\n    <button type=\"button\" mat-icon-button [attr.aria-label]=\"'Expand all'|firstUppercaseLocalize\" (click)=\"rootTreeItem?.expandAll()\">\n        <span class=\"fa fa-plus-square\"></span>\n    </button>\n    \n    <components-tree-item [data]=\"root\"></components-tree-item>\n</div>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i3.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }, { kind: "component", type: ComponentsTreeItemSAComponent, selector: "components-tree-item", inputs: ["data", "index", "parentId", "open"], exportAs: ["componentsTreeItem"] }, { kind: "pipe", type: FirstUppercaseLocalizeSAPipe, name: "firstUppercaseLocalize" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: ComponentsTreeSAComponent, decorators: [{
            type: Component,
            args: [{ selector: 'components-tree', standalone: true, imports: [
                        CommonModule,
                        MatButtonModule,
                        ComponentsTreeItemSAComponent,
                        FirstUppercaseLocalizeSAPipe,
                    ], providers: [
                        DragActiveService,
                        DndBusService,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, template: "\n<div class=\"component-tree\" *ngIf=\"root\">\n    <button type=\"button\" mat-icon-button [attr.aria-label]=\"'collapse all'|firstUppercaseLocalize\"  (click)=\"rootTreeItem?.collapseAll()\">\n        <span class=\"fa fa-minus-square\"></span>\n    </button>\n\n    <button type=\"button\" mat-icon-button [attr.aria-label]=\"'Expand all'|firstUppercaseLocalize\" (click)=\"rootTreeItem?.expandAll()\">\n        <span class=\"fa fa-plus-square\"></span>\n    </button>\n    \n    <components-tree-item [data]=\"root\"></components-tree-item>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.LayoutEditorMetadataManager }, { type: i0.ChangeDetectorRef }], propDecorators: { rootTreeItem: [{
                type: ViewChild,
                args: [ComponentsTreeItemSAComponent]
            }] } });
//# sourceMappingURL=componentsTree.component.js.map