var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var ElTreeGridRowComponent_1, ElTreeGridHeaderRowComponent_1, ElTreeGridFooterRowComponent_1;
import { ChangeDetectionStrategy, Component, ElementRef, HostListener, Inject, Input } from '@angular/core';
import { Subject, timer } from 'rxjs';
import { take, takeUntil } from 'rxjs/operators';
import { ElCdkFooterRow, ElCdkHeaderRow, ElCdkRow } from '../cdk/table/type-mappings';
import { ElFooterRowComponent, ElHeaderRowComponent, ElRowComponent } from '../cdk/table/row';
import { EL_TREE_GRID } from './tree-grid-injection-tokens';
export const EL_ROW_DOUBLE_CLICK_DELAY = 200;
/**
 * Cells container. Adds the right class and role.
 */
let ElTreeGridRowComponent = ElTreeGridRowComponent_1 = class ElTreeGridRowComponent extends ElRowComponent {
    constructor(tree, elementRef) {
        super();
        this.elementRef = elementRef;
        this.doubleClick$ = new Subject();
        /**
         * Time to wait for second click to expand row deeply.
         * 200ms by default.
         */
        this.doubleClickDelay = EL_ROW_DOUBLE_CLICK_DELAY;
        /**
         * Toggle row on click. Enabled by default.
         */
        this.clickToToggle = true;
        this.tree = tree;
    }
    toggleIfEnabledNode() {
        if (!this.clickToToggle) {
            return;
        }
        timer(EL_ROW_DOUBLE_CLICK_DELAY)
            .pipe(take(1), takeUntil(this.doubleClick$))
            .subscribe(() => this.tree.toggleRow(this));
    }
    toggleIfEnabledNodeDeep() {
        if (!this.clickToToggle) {
            return;
        }
        this.doubleClick$.next();
        this.tree.toggleRow(this, { deep: true });
    }
    ngOnDestroy() {
        this.doubleClick$.complete();
    }
};
__decorate([
    Input(),
    __metadata("design:type", Number)
], ElTreeGridRowComponent.prototype, "doubleClickDelay", void 0);
__decorate([
    Input(),
    __metadata("design:type", Boolean)
], ElTreeGridRowComponent.prototype, "clickToToggle", void 0);
__decorate([
    HostListener('click'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], ElTreeGridRowComponent.prototype, "toggleIfEnabledNode", null);
__decorate([
    HostListener('dblclick'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], ElTreeGridRowComponent.prototype, "toggleIfEnabledNodeDeep", null);
ElTreeGridRowComponent = ElTreeGridRowComponent_1 = __decorate([
    Component({
        selector: 'tr[elTreeGridRow]',
        template: `<ng-container elCellOutlet></ng-container>`,
        host: {
            'class': 'el-tree-grid-row',
            'role': 'row',
        },
        providers: [{ provide: ElCdkRow, useExisting: ElTreeGridRowComponent_1 }],
        changeDetection: ChangeDetectionStrategy.OnPush
    }),
    __param(0, Inject(EL_TREE_GRID)),
    __metadata("design:paramtypes", [Object, ElementRef])
], ElTreeGridRowComponent);
export { ElTreeGridRowComponent };
let ElTreeGridHeaderRowComponent = ElTreeGridHeaderRowComponent_1 = class ElTreeGridHeaderRowComponent extends ElHeaderRowComponent {
};
ElTreeGridHeaderRowComponent = ElTreeGridHeaderRowComponent_1 = __decorate([
    Component({
        selector: 'tr[elTreeGridHeaderRow]',
        template: `
    <ng-container elCellOutlet></ng-container>`,
        host: {
            'class': 'el-tree-grid-header-row',
            'role': 'row',
        },
        changeDetection: ChangeDetectionStrategy.OnPush,
        providers: [{ provide: ElCdkHeaderRow, useExisting: ElTreeGridHeaderRowComponent_1 }]
    })
], ElTreeGridHeaderRowComponent);
export { ElTreeGridHeaderRowComponent };
let ElTreeGridFooterRowComponent = ElTreeGridFooterRowComponent_1 = class ElTreeGridFooterRowComponent extends ElFooterRowComponent {
};
ElTreeGridFooterRowComponent = ElTreeGridFooterRowComponent_1 = __decorate([
    Component({
        selector: 'tr[elTreeGridFooterRow]',
        template: `
    <ng-container elCellOutlet></ng-container>`,
        host: {
            'class': 'el-tree-grid-footer-row',
            'role': 'row',
        },
        changeDetection: ChangeDetectionStrategy.OnPush,
        providers: [{ provide: ElCdkFooterRow, useExisting: ElTreeGridFooterRowComponent_1 }]
    })
], ElTreeGridFooterRowComponent);
export { ElTreeGridFooterRowComponent };
//# sourceMappingURL=tree-grid-row.component.js.map