import { Component, Input, ContentChildren, EventEmitter, Output } from '@angular/core';
import { BehaviorSubject, map } from 'rxjs';
import { PaginationResponse } from '@mintplayer/pagination';
import { DatatableSettings } from '../datatable-settings';
import { BsDatatableColumnDirective } from '../datatable-column';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "@mintplayer/ng-bootstrap/grid";
import * as i3 from "@mintplayer/ng-bootstrap/table";
import * as i4 from "@mintplayer/ng-bootstrap/pagination";
export class BsDatatableComponent {
    constructor() {
        //#region Columns
        this.columns$ = new BehaviorSubject([]);
        this.reloadData = new EventEmitter();
        this.settings = new DatatableSettings();
        this.settings.sortProperty = '';
        this.settings.sortDirection = 'ascending';
        this.settings.perPage = { values: [10, 20, 50], selected: 20 };
        this.settings.page = { values: [1], selected: 1 };
        this.numberOfColumns$ = this.columns$.pipe(map(columns => columns.length));
    }
    set columns(value) {
        this.columns$.next(value);
    }
    columnHeaderClicked(column) {
        if (column.bsDatatableColumn.sortable) {
            if (this.settings.sortProperty !== column.bsDatatableColumn.name) {
                this.settings.sortProperty = column.bsDatatableColumn.name;
                this.settings.sortDirection = 'ascending';
            }
            else if (this.settings.sortDirection === 'descending') {
                this.settings.sortDirection = 'ascending';
            }
            else {
                this.settings.sortDirection = 'descending';
            }
            this.reloadData.emit(this.settings);
        }
    }
}
BsDatatableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsDatatableComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
BsDatatableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.7", type: BsDatatableComponent, selector: "bs-datatable", inputs: { settings: "settings", data: "data" }, outputs: { reloadData: "reloadData" }, queries: [{ propertyName: "columns", predicate: BsDatatableColumnDirective }], ngImport: i0, template: "<bs-table [isResponsive]=\"true\" [striped]=\"true\" [hover]=\"true\" class=\"mb-3\">\n    <thead>\n        <tr>\n            <th *ngFor=\"let column of (columns$ | async)\" class=\"text-nowrap\"\n                [class.sort]=\"column.bsDatatableColumn.sortable\"\n                [class.sort-asc]=\"column.bsDatatableColumn.sortable && (settings.sortProperty === column.bsDatatableColumn.name) && (settings.sortDirection === 'ascending')\"\n                [class.sort-desc]=\"column.bsDatatableColumn.sortable && (settings.sortProperty === column.bsDatatableColumn.name) && (settings.sortDirection === 'descending')\"\n                (click)=\"columnHeaderClicked(column)\">\n                <ng-container *ngTemplateOutlet=\"column.templateRef\"></ng-container>\n            </th>\n        </tr>\n    </thead>\n    <tbody>\n        <ng-container *ngIf=\"!!data && !!rowTemplate\">\n            <ng-container *ngFor=\"let item of data.data\">\n                <ng-container *ngTemplateOutlet=\"rowTemplate; context: { $implicit: item }\"></ng-container>\n            </ng-container>\n        </ng-container>\n    </tbody>\n    <tfoot>\n        <tr>\n            <td [colSpan]=\"numberOfColumns$ | async\">\n                <bs-grid [stopFullWidthAt]=\"'never'\">\n                    <div bsRow>\n                        <div [bsColumn]=\"{md: 12}\">\n                            <bs-pagination class=\"float-start\" [pageNumbers]=\"settings.perPage.values\"\n                                [(selectedPageNumber)]=\"settings.perPage.selected\" (selectedPageNumberChange)=\"reloadData.emit(settings)\"\n                                [showArrows]=\"false\"></bs-pagination>\n                            <bs-pagination class=\"float-end\" [pageNumbers]=\"settings.page.values\"\n                                [(selectedPageNumber)]=\"settings.page.selected\" (selectedPageNumberChange)=\"reloadData.emit(settings)\"\n                                [showArrows]=\"true\"></bs-pagination>\n                        </div>\n                    </div>\n                </bs-grid>\n            </td>\n        </tr>\n    </tfoot>\n</bs-table>", styles: ["@charset \"UTF-8\";tfoot>tr>td{border-bottom:none}bs-table thead th.sort{position:relative;cursor:pointer;padding-right:2rem}bs-table thead th.sort:before,bs-table thead th.sort:after{position:absolute;display:block;opacity:.3;bottom:.5em}bs-table thead th.sort:before{content:\"\\2191\";right:1em}bs-table thead th.sort:after{content:\"\\2193\";right:.5em}bs-table thead th.sort.sort-asc:after{opacity:1}bs-table thead th.sort.sort-desc:before{opacity:1}\n"], dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: i2.BsGridComponent, selector: "bs-grid", inputs: ["stopFullWidthAt"] }, { kind: "directive", type: i2.BsGridRowDirective, selector: "[bsRow]" }, { kind: "directive", type: i2.BsGridColumnDirective, selector: "[bsColumn]", inputs: ["bsColumn"] }, { kind: "component", type: i3.BsTableComponent, selector: "bs-table", inputs: ["isResponsive", "striped", "hover"] }, { kind: "component", type: i4.BsPaginationComponent, selector: "bs-pagination", inputs: ["selectedPageNumber", "numberOfBoxes", "pageNumbers", "showArrows", "size"], outputs: ["selectedPageNumberChange"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsDatatableComponent, decorators: [{
            type: Component,
            args: [{ selector: 'bs-datatable', template: "<bs-table [isResponsive]=\"true\" [striped]=\"true\" [hover]=\"true\" class=\"mb-3\">\n    <thead>\n        <tr>\n            <th *ngFor=\"let column of (columns$ | async)\" class=\"text-nowrap\"\n                [class.sort]=\"column.bsDatatableColumn.sortable\"\n                [class.sort-asc]=\"column.bsDatatableColumn.sortable && (settings.sortProperty === column.bsDatatableColumn.name) && (settings.sortDirection === 'ascending')\"\n                [class.sort-desc]=\"column.bsDatatableColumn.sortable && (settings.sortProperty === column.bsDatatableColumn.name) && (settings.sortDirection === 'descending')\"\n                (click)=\"columnHeaderClicked(column)\">\n                <ng-container *ngTemplateOutlet=\"column.templateRef\"></ng-container>\n            </th>\n        </tr>\n    </thead>\n    <tbody>\n        <ng-container *ngIf=\"!!data && !!rowTemplate\">\n            <ng-container *ngFor=\"let item of data.data\">\n                <ng-container *ngTemplateOutlet=\"rowTemplate; context: { $implicit: item }\"></ng-container>\n            </ng-container>\n        </ng-container>\n    </tbody>\n    <tfoot>\n        <tr>\n            <td [colSpan]=\"numberOfColumns$ | async\">\n                <bs-grid [stopFullWidthAt]=\"'never'\">\n                    <div bsRow>\n                        <div [bsColumn]=\"{md: 12}\">\n                            <bs-pagination class=\"float-start\" [pageNumbers]=\"settings.perPage.values\"\n                                [(selectedPageNumber)]=\"settings.perPage.selected\" (selectedPageNumberChange)=\"reloadData.emit(settings)\"\n                                [showArrows]=\"false\"></bs-pagination>\n                            <bs-pagination class=\"float-end\" [pageNumbers]=\"settings.page.values\"\n                                [(selectedPageNumber)]=\"settings.page.selected\" (selectedPageNumberChange)=\"reloadData.emit(settings)\"\n                                [showArrows]=\"true\"></bs-pagination>\n                        </div>\n                    </div>\n                </bs-grid>\n            </td>\n        </tr>\n    </tfoot>\n</bs-table>", styles: ["@charset \"UTF-8\";tfoot>tr>td{border-bottom:none}bs-table thead th.sort{position:relative;cursor:pointer;padding-right:2rem}bs-table thead th.sort:before,bs-table thead th.sort:after{position:absolute;display:block;opacity:.3;bottom:.5em}bs-table thead th.sort:before{content:\"\\2191\";right:1em}bs-table thead th.sort:after{content:\"\\2193\";right:.5em}bs-table thead th.sort.sort-asc:after{opacity:1}bs-table thead th.sort.sort-desc:before{opacity:1}\n"] }]
        }], ctorParameters: function () { return []; }, propDecorators: { columns: [{
                type: ContentChildren,
                args: [BsDatatableColumnDirective]
            }], settings: [{
                type: Input
            }], data: [{
                type: Input
            }], reloadData: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 