/**
 * @fileoverview added by tsickle
 * Generated from: components/datatable/parts/header/datatable-header.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/*
    MIT License

    Copyright (c) 2019 Temainfo Software

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
*/
import { Component, forwardRef, Inject, ViewChild, ElementRef, Output, EventEmitter } from '@angular/core';
import { TlDatatable } from '../../datatable';
import { DatatableHelpersService } from '../../services/datatable-helpers.service';
import { TlDatatabaleColumnFilter } from '../column-filter/datatable-column-filter';
import { TlDatatableFilterService } from '../../services/datatable-filter.service';
import { TlDatatableSortService } from '../../services/datatable-sort.service';
import { Subscription } from 'rxjs';
export class TlDatatableHeader {
    /**
     * @param {?} dt
     * @param {?} helperService
     * @param {?} filterService
     * @param {?} sortService
     */
    constructor(dt, helperService, filterService, sortService) {
        this.dt = dt;
        this.helperService = helperService;
        this.filterService = filterService;
        this.sortService = sortService;
        this.keydownFilter = new EventEmitter();
        this.subscription = new Subscription();
        this.filderOrder = 1;
    }
    /**
     * @return {?}
     */
    ngAfterViewInit() {
        if (this.columnsFilter !== undefined) {
            this.subscription.add(this.columnsFilter.filterEvent.subscribe((/**
             * @param {?} value
             * @return {?}
             */
            (value) => {
                this.filterService.setFilter(value);
            })));
        }
        this.subscription.add(this.dt.getScrollingHorizontal().subscribe((/**
         * @param {?} leftValue
         * @return {?}
         */
        (leftValue) => {
            this.datatableHeader.nativeElement.firstElementChild.scrollLeft = leftValue;
        })));
    }
    /**
     * @param {?} column
     * @return {?}
     */
    onClick(column) {
        if ((column.sortable === false) || (this.dt.allowSortColumn === false)) {
            return;
        }
        this.filderOrder = this.filderOrder * -1;
        if (this.sortField !== column.field) {
            this.sortField = column.field;
            this.filderOrder = 1;
        }
        this.sortService.setSort({ sorts: { column: column.field, sortBy: this.filderOrder } });
    }
    /**
     * @param {?} column
     * @return {?}
     */
    getSortOrder(column) {
        /** @type {?} */
        let order = 0;
        if (this.sortField === column.field) {
            order = this.filderOrder;
        }
        return order;
    }
    /**
     * @return {?}
     */
    ngOnDestroy() {
        this.subscription.unsubscribe();
    }
}
TlDatatableHeader.decorators = [
    { type: Component, args: [{
                selector: 'tl-datatable-header',
                template: "<div class=\"ui-datatable-header\" #datatableHeader [resizer]=\"dt.allowResize\" [datatable]=\"dt\" >\n    <div class=\"ui-datatable-header-wrap\">\n\n        <div class=\"ui-datatable-column-separator\"></div>\n\n        <table #table class=\"ui-datatable-table\" [colgroup]=\"dt.columns\">\n            <thead class=\"ui-datatable-table-head\">\n\n                <tr class=\"ui-row ui-row-title\">\n                    <th *ngFor=\"let column of dt.columns;\"\n                        (click)=\"onClick(column)\"\n                        [class]=\"'ui-cel ' + helperService.getClassAlignment(column.alignment)\">\n\n                        <span>{{column.title}}</span>\n                        <div *ngIf=\"dt.allowSortColumn\" class=\"ui-sort-indicator -push-{{column.alignment}}\">\n                            <span\n                              [ngClass]=\"{\n                                      'ion ion-ios-arrow-round-up': getSortOrder(column) == 1,\n                                      'ion ion-ios-arrow-round-down': getSortOrder(column) == -1\n                              }\"\n                            >\n                          </span>\n                        </div>\n                    </th>\n                </tr>\n                <tr *ngIf=\"dt.allowFilterColumn\" class=\"ui-row ui-row-filter\"\n                    [tlColumnFilter]=\"dt.columns\"></tr>\n            </thead>\n        </table>\n    </div>\n</div>\n",
                providers: [DatatableHelpersService],
                styles: [".ui-datatable-header{-moz-user-select:none;-ms-user-select:none;-webkit-touch-callout:none;-webkit-user-select:none;padding:0 17px 0 0;position:relative;user-select:none}.ui-datatable-header-wrap{overflow:hidden}.ui-datatable-column-separator{cursor:col-resize;height:100%;left:0;position:absolute;top:0;width:4px;z-index:9999}.ui-datatable-column-separator:hover{cursor:col-resize}.ui-datatable-table-head{font-size:1em}.ui-datatable-table-head>.ui-row{height:25px;margin:0}.ui-datatable-table-head>.ui-row-filter{height:32px}.ui-datatable-table-head>.ui-row .ui-sort-indicator{content:\" \";font-size:15px;font-weight:600;height:17px;width:5.65px}.ui-datatable-table-head>.ui-row .ui-sort-indicator.-push-center,.ui-datatable-table-head>.ui-row .ui-sort-indicator.-push-left{float:right}.ui-datatable-table-head>.ui-row .ui-sort-indicator.-push-right{float:left}.ui-datatable-table-head>.ui-row .ui-cel{align-items:center;box-sizing:border-box;cursor:pointer;overflow:hidden;padding-left:5px;padding-right:5px}.ui-datatable-table-head>.ui-row .ui-cel.-textleft{text-align:left}.ui-datatable-table-head>.ui-row .ui-cel.-textright{text-align:right}.ui-datatable-table-head>.ui-row .ui-cel.-textcenter{text-align:center}.ui-datatable-table-head>.ui-row .ui-cel:last-child{border-right:none}.ui-datatable-table-head>.ui-row .ui-cel.ui-filter-cel{padding:5px}", ".tl-datatable-box{box-sizing:border-box;width:100%}.ui-datatable-table{border-collapse:collapse;border-spacing:0;font-family:RobotoRegular,Helvetica,Arial,sans-serif;table-layout:fixed;text-align:center;width:100%}.hidden{display:none}"]
            }] }
];
/** @nocollapse */
TlDatatableHeader.ctorParameters = () => [
    { type: TlDatatable, decorators: [{ type: Inject, args: [forwardRef((/**
                     * @return {?}
                     */
                    () => TlDatatable)),] }] },
    { type: DatatableHelpersService },
    { type: TlDatatableFilterService },
    { type: TlDatatableSortService }
];
TlDatatableHeader.propDecorators = {
    columnsFilter: [{ type: ViewChild, args: [TlDatatabaleColumnFilter, { static: false },] }],
    datatableHeader: [{ type: ViewChild, args: ['datatableHeader', { static: true },] }],
    keydownFilter: [{ type: Output }]
};
if (false) {
    /** @type {?} */
    TlDatatableHeader.prototype.columnsFilter;
    /** @type {?} */
    TlDatatableHeader.prototype.datatableHeader;
    /** @type {?} */
    TlDatatableHeader.prototype.keydownFilter;
    /**
     * @type {?}
     * @private
     */
    TlDatatableHeader.prototype.subscription;
    /**
     * @type {?}
     * @private
     */
    TlDatatableHeader.prototype.filderOrder;
    /**
     * @type {?}
     * @private
     */
    TlDatatableHeader.prototype.sortField;
    /** @type {?} */
    TlDatatableHeader.prototype.dt;
    /** @type {?} */
    TlDatatableHeader.prototype.helperService;
    /** @type {?} */
    TlDatatableHeader.prototype.filterService;
    /**
     * @type {?}
     * @private
     */
    TlDatatableHeader.prototype.sortService;
}
//# sourceMappingURL=data:application/json;base64, 