import { __decorate, __values } from "tslib";
import { Component, HostBinding, Input, ViewChild, QueryList, ViewChildren, forwardRef, ChangeDetectionStrategy, ChangeDetectorRef, DoCheck, ElementRef, HostListener } from '@angular/core';
import { IgxFilteringService } from '../filtering/grid-filtering.service';
import { GridBaseAPIService } from '../api.service';
import { IgxColumnResizingService } from '../resizing/resizing.service';
import { IgxGridHeaderComponent } from './grid-header.component';
import { IgxGridFilteringCellComponent } from '../filtering/base/grid-filtering-cell.component';
import { isIE } from '../../core/utils';
var Z_INDEX = 9999;
/**
 * @hidden
 */
var IgxGridHeaderGroupComponent = /** @class */ (function () {
    function IgxGridHeaderGroupComponent(cdr, gridAPI, element, colResizingService, filteringService) {
        this.cdr = cdr;
        this.gridAPI = gridAPI;
        this.element = element;
        this.colResizingService = colResizingService;
        this.filteringService = filteringService;
    }
    IgxGridHeaderGroupComponent_1 = IgxGridHeaderGroupComponent;
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "gridRowSpan", {
        get: function () {
            return this.column.gridRowSpan;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "gridColumnSpan", {
        get: function () {
            return this.column.gridColumnSpan;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "rowEnd", {
        get: function () {
            return this.column.rowEnd;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "colEnd", {
        get: function () {
            return this.column.colEnd;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "rowStart", {
        get: function () {
            return this.column.rowStart;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "colStart", {
        get: function () {
            return this.column.colStart;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "width", {
        /**
         * Gets the width of the header group.
         * @memberof IgxGridHeaderGroupComponent
         */
        get: function () {
            return this.grid.getHeaderGroupWidth(this.column);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "styleClasses", {
        /**
         * Gets the style classes of the header group.
         * @memberof IgxGridHeaderGroupComponent
         */
        get: function () {
            var e_1, _a;
            var defaultClasses = [
                'igx-grid__thead-item',
                this.column.headerGroupClasses
            ];
            var classList = {
                'igx-grid__th--pinned': this.isPinned,
                'igx-grid__th--pinned-last': this.isLastPinned,
                'igx-grid__drag-col-header': this.isHeaderDragged,
                'igx-grid__th--filtering': this.isFiltered
            };
            try {
                for (var _b = __values(Object.keys(classList)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var className = _c.value;
                    if (classList[className]) {
                        defaultClasses.push(className);
                    }
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_1) throw e_1.error; }
            }
            return defaultClasses.join(' ');
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "zIndex", {
        /**
         * @hidden
         */
        get: function () {
            if (!this.column.pinned) {
                return null;
            }
            return Z_INDEX - this.grid.pinnedColumns.indexOf(this.column);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "grid", {
        /**
         * Gets the grid of the header group.
         * @memberof IgxGridHeaderGroupComponent
         */
        get: function () {
            return this.gridAPI.grid;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "isFiltered", {
        /**
         * Gets whether the header group belongs to a column that is filtered.
         * @memberof IgxGridHeaderGroupComponent
         */
        get: function () {
            return this.filteringService.filteredColumn === this.column;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "isLastPinned", {
        /**
         * Gets whether the header group is stored in the last column in the pinned area.
         * @memberof IgxGridHeaderGroupComponent
         */
        get: function () {
            return !this.grid.hasColumnLayouts ? this.column.isLastPinned : false;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "groupDisplayStyle", {
        get: function () {
            return this.grid.hasColumnLayouts && this.column.children && !isIE() ? 'flex' : '';
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "isPinned", {
        /**
         * Gets whether the header group is stored in a pinned column.
         * @memberof IgxGridHeaderGroupComponent
         */
        get: function () {
            return this.column.pinned;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "isHeaderDragged", {
        /**
         * Gets whether the header group belongs to a column that is moved.
         * @memberof IgxGridHeaderGroupComponent
         */
        get: function () {
            return this.grid.draggedColumn === this.column;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "hasLastPinnedChildColumn", {
        /**
         * @hidden
         */
        get: function () {
            return this.column.allChildren.some(function (child) { return child.isLastPinned; });
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgxGridHeaderGroupComponent.prototype, "height", {
        /**
         * @hidden
         */
        get: function () {
            return this.element.nativeElement.getBoundingClientRect().height;
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @hidden
     */
    IgxGridHeaderGroupComponent.prototype.onMouseDown = function (event) {
        // hack for preventing text selection in IE and Edge while dragging the resizer
        event.preventDefault();
    };
    IgxGridHeaderGroupComponent.prototype.ngDoCheck = function () {
        this.cdr.markForCheck();
    };
    var IgxGridHeaderGroupComponent_1;
    IgxGridHeaderGroupComponent.ctorParameters = function () { return [
        { type: ChangeDetectorRef },
        { type: GridBaseAPIService },
        { type: ElementRef },
        { type: IgxColumnResizingService },
        { type: IgxFilteringService }
    ]; };
    __decorate([
        HostBinding('style.-ms-grid-row-span')
    ], IgxGridHeaderGroupComponent.prototype, "gridRowSpan", null);
    __decorate([
        HostBinding('style.-ms-grid-column-span')
    ], IgxGridHeaderGroupComponent.prototype, "gridColumnSpan", null);
    __decorate([
        HostBinding('style.grid-row-end')
    ], IgxGridHeaderGroupComponent.prototype, "rowEnd", null);
    __decorate([
        HostBinding('style.grid-column-end')
    ], IgxGridHeaderGroupComponent.prototype, "colEnd", null);
    __decorate([
        HostBinding('style.-ms-grid-row'),
        HostBinding('style.grid-row-start')
    ], IgxGridHeaderGroupComponent.prototype, "rowStart", null);
    __decorate([
        HostBinding('style.-ms-grid-column'),
        HostBinding('style.grid-column-start')
    ], IgxGridHeaderGroupComponent.prototype, "colStart", null);
    __decorate([
        Input()
    ], IgxGridHeaderGroupComponent.prototype, "column", void 0);
    __decorate([
        Input()
    ], IgxGridHeaderGroupComponent.prototype, "gridID", void 0);
    __decorate([
        ViewChild(IgxGridHeaderComponent)
    ], IgxGridHeaderGroupComponent.prototype, "headerCell", void 0);
    __decorate([
        ViewChild(IgxGridFilteringCellComponent)
    ], IgxGridHeaderGroupComponent.prototype, "filterCell", void 0);
    __decorate([
        ViewChildren(forwardRef(function () { return IgxGridHeaderGroupComponent_1; }), { read: IgxGridHeaderGroupComponent_1 })
    ], IgxGridHeaderGroupComponent.prototype, "children", void 0);
    __decorate([
        HostBinding('class')
    ], IgxGridHeaderGroupComponent.prototype, "styleClasses", null);
    __decorate([
        HostBinding('style.z-index')
    ], IgxGridHeaderGroupComponent.prototype, "zIndex", null);
    __decorate([
        HostBinding('style.display')
    ], IgxGridHeaderGroupComponent.prototype, "groupDisplayStyle", null);
    __decorate([
        HostListener('mousedown', ['$event'])
    ], IgxGridHeaderGroupComponent.prototype, "onMouseDown", null);
    IgxGridHeaderGroupComponent = IgxGridHeaderGroupComponent_1 = __decorate([
        Component({
            changeDetection: ChangeDetectionStrategy.OnPush,
            preserveWhitespaces: false,
            selector: 'igx-grid-header-group',
            template: "<ng-container *ngIf=\"grid.hasColumnLayouts && column.columnGroup\">\n    <span *ngIf=\"grid.hasMovableColumns\" class=\"igx-grid__th-drop-indicator-left\"></span>\n    <div class=\"igx-grid__thead-group igx-grid__mrl-block\"\n     [ngClass]=\"{'igx-grid__th--pinned-last': hasLastPinnedChildColumn}\"\n     [ngStyle]=\"{'grid-template-rows':column.getGridTemplate(true, false),\n     'grid-template-columns':column.getGridTemplate(false, false),\n     '-ms-grid-rows':column.getGridTemplate(true, true),\n     '-ms-grid-columns':column.getGridTemplate(false, true)}\">\n        <ng-container *ngFor=\"let child of column.children\" >\n            <igx-grid-header-group *ngIf=\"!child.hidden\" class=\"igx-grid__thead-subgroup\"\n                [column]=\"child\"\n                [gridID]=\"child.grid.id\"\n                [igxColumnMovingDrag]=\"child\"\n                [ghostHost]=\"grid.outletDirective.nativeElement\"\n                [attr.droppable]=\"true\"\n                [igxColumnMovingDrop]=\"child\">\n            </igx-grid-header-group>\n        </ng-container>\n    </div>\n    <span *ngIf=\"grid.hasMovableColumns\" class=\"igx-grid__th-drop-indicator-right\"></span>\n</ng-container>\n\n\n<ng-template #defaultColumn>\n    <span class=\"igx-grid__th-group-title\" [attr.title]=\"column.header\">{{column.header}}</span>\n</ng-template>\n\n<ng-template #defaultCollapseIndicator>\n    <igx-icon [attr.draggable]=\"false\" >\n            {{column.expanded ? 'expand_more' : 'chevron_right'}} </igx-icon>\n</ng-template>\n\n<ng-container *ngIf=\"!grid.hasColumnLayouts && column.columnGroup\">\n    <span *ngIf=\"grid.hasMovableColumns\" class=\"igx-grid__th-drop-indicator-left\"></span>\n    <div class=\"igx-grid__thead-title\"\n        role=\"columnheader\"\n        [attr.aria-label]=\"column.header || column.field\"\n        [attr.aria-expanded]=\"column.expanded\"\n        tabindex=\"0\"\n        [ngClass]=\"{'igx-grid__th--pinned-last': hasLastPinnedChildColumn, 'igx-grid__th--collapsible': column.collapsible}\"\n        [igxColumnMovingDrag]=\"column\"\n        [ghostHost]=\"grid.outletDirective.nativeElement\"\n        [attr.droppable]=\"true\"\n        [igxColumnMovingDrop]=\"column\">\n        <ng-container *ngIf=\"column.collapsible\">\n            <div class=\"igx-grid__th-expander\" (click)=\"column.expanded = !column.expanded\">\n                <ng-container\n                    *ngTemplateOutlet=\"column.collapsibleIndicatorTemplate ? column.collapsibleIndicatorTemplate : defaultCollapseIndicator; context: {$implicit: column, column: column}\">\n                </ng-container>\n            </div>\n        </ng-container>\n        <ng-container *ngTemplateOutlet=\"column.headerTemplate ? column.headerTemplate : defaultColumn; context: { $implicit: column, column: column}\">\n        </ng-container>\n    </div>\n    <div class=\"igx-grid__thead-group\">\n        <ng-container *ngFor=\"let child of column.children\">\n            <igx-grid-header-group *ngIf=\"!child.hidden\" class=\"igx-grid__thead-subgroup\"\n                                [column]=\"child\"\n                                [gridID]=\"child.grid.id\"\n                                [style.min-width]=\"grid.getHeaderGroupWidth(child)\"\n                                [style.flex-basis]=\"grid.getHeaderGroupWidth(child)\">\n            </igx-grid-header-group>\n        </ng-container>\n    </div>\n    <span *ngIf=\"grid.hasMovableColumns\" class=\"igx-grid__th-drop-indicator-right\"></span>\n</ng-container>\n\n<ng-container *ngIf=\"!column.columnGroup\">\n    <span *ngIf=\"grid.hasMovableColumns\" class=\"igx-grid__th-drop-indicator-left\"></span>\n    <igx-grid-header [igxColumnMovingDrag]=\"column\" [ghostHost]=\"grid.outletDirective.nativeElement\" [attr.droppable]=\"true\" [igxColumnMovingDrop]=\"column\" [gridID]=\"column.grid.id\" [column]=\"column\"></igx-grid-header>\n    <igx-grid-filtering-cell *ngIf=\"grid.allowFiltering && grid.filterMode == 'quickFilter'\" [column]=\"column\" [attr.draggable]=\"false\"></igx-grid-filtering-cell>\n    <span *ngIf=\"!column.columnGroup && column.resizable\" class=\"igx-grid__th-resize-handle\"\n          [igxResizeHandle]=\"column\"\n          [attr.draggable]=\"false\"\n          [style.cursor]=\"colResizingService.resizeCursor\">\n    </span>\n    <span *ngIf=\"grid.hasMovableColumns\" class=\"igx-grid__th-drop-indicator-right\"></span>\n</ng-container>\n"
        })
    ], IgxGridHeaderGroupComponent);
    return IgxGridHeaderGroupComponent;
}());
export { IgxGridHeaderGroupComponent };
//# sourceMappingURL=data:application/json;base64, 