import { __decorate, __metadata, __spread } from 'tslib';
import { Injectable, EventEmitter, Output, ViewChild, TemplateRef, Input, Component, ChangeDetectorRef, NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { NgxPaginationModule } from 'ngx-pagination';
import { NgxDatatableModule } from '@swimlane/ngx-datatable';
import { TypeaheadModule, AccordionModule, BsDropdownModule, BsDatepickerModule, TooltipModule, TabsModule, PaginationModule } from 'ngx-bootstrap';
import { ToastrService } from 'ngx-toastr';
import { debounceTime, distinctUntilChanged } from 'rxjs/operators';

var NotificationService = /** @class */ (function () {
    function NotificationService() {
    }
    NotificationService.prototype.error = function (message, title, override) {
        this.notify('error', message, title, override);
    };
    NotificationService.prototype.info = function (message, title, override) {
        this.notify('info', message, title, override);
    };
    NotificationService.prototype.success = function (message, title, override) {
        this.notify('success', message, title, override);
    };
    NotificationService.prototype.warning = function (message, title, override) {
        this.notify('warning', message, title, override);
    };
    NotificationService.prototype.notify = function (method, message, title, override) {
        console[method](message || '', title || '', override);
    };
    NotificationService = __decorate([
        Injectable(),
        __metadata("design:paramtypes", [])
    ], NotificationService);
    return NotificationService;
}());

var GridRendererComponent = /** @class */ (function () {
    function GridRendererComponent(ref) {
        this.ref = ref;
        this.loading = true;
        this.activePage = 1;
        this.fakePageSizeModel = 0;
        this.searchVal = '';
        this.buttonClick = new EventEmitter();
        this.selectionType = 'multiClick';
        this.rowHeight = 'auto';
        this.columnMode = 'force';
        this.headerHeight = 40;
        this.footerHeight = 40;
        this.showPager = true;
        this.reorderable = true;
        this.swapColumns = true;
        this.editablePageSize = true;
        this.pageSizes = [5, 10, 15, 50, 100];
        this.actionButtons = [];
        this.selected = [];
        this._searchChanged = new EventEmitter();
        this._columns = [];
        this._rows = [];
        this._pageSize = 10;
    }
    Object.defineProperty(GridRendererComponent.prototype, "rows", {
        get: function () {
            var _this = this;
            var activeRows = this._rows;
            if (this.searchVal) {
                activeRows = activeRows.filter(function (row) {
                    // Object.values still not working for some browsers
                    var rowMeta = Object.keys(row)
                        .map(function (key) { return row[key]; })
                        .join(' ')
                        .toLowerCase();
                    var shouldFind = _this.searchVal.toLowerCase().split(' ');
                    return shouldFind.some(function (str) { return rowMeta.indexOf(str) !== -1; });
                });
            }
            return activeRows;
        },
        set: function (rows) {
            this._rows = rows;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridRendererComponent.prototype, "columns", {
        get: function () {
            return this._columns;
        },
        set: function (columns) {
            var _this = this;
            this._columns = columns.map(function (col) { return Object.assign({ headerTemplate: _this.hdrTpl, cellTemplate: _this.cellTpl }, col); });
            // this._columns = columns;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridRendererComponent.prototype, "pageSize", {
        get: function () {
            return this._pageSize;
        },
        set: function (pageSize) {
            this.fakePageSizeModel = pageSize;
            this._pageSize = pageSize;
        },
        enumerable: true,
        configurable: true
    });
    GridRendererComponent.prototype.ngAfterViewInit = function () {
        var _this = this;
        this.fakePageSizeModel = this.pageSize;
        this.loading = false;
        this.ref.detectChanges();
        this._searchChanged
            .pipe(debounceTime(400), distinctUntilChanged())
            .subscribe(function (searchVal) {
            _this.updateSearch(searchVal);
        });
    };
    GridRendererComponent.prototype.reset = function () {
        this.selected = [];
        this.searchVal = '';
        this.activePage = 1;
        this.pageSize = 10;
    };
    GridRendererComponent.prototype.buttonClicked = function (button) {
        this.buttonClick.emit(button);
    };
    GridRendererComponent.prototype.updatePageSize = function (pageSize) {
        this.pageSize = pageSize;
        this.ref.detectChanges();
    };
    GridRendererComponent.prototype.emitSearch = function (value) {
        if (value === undefined) {
            return;
        }
        this._searchChanged.emit(value);
    };
    GridRendererComponent.prototype.updateSearch = function (searchVal) {
        this.searchVal = searchVal;
        this.ref.detectChanges();
    };
    __decorate([
        Output('buttonClicked'),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "buttonClick", void 0);
    __decorate([
        ViewChild('hdrTpl', { static: false }),
        __metadata("design:type", TemplateRef)
    ], GridRendererComponent.prototype, "hdrTpl", void 0);
    __decorate([
        ViewChild('cellTpl', { static: false }),
        __metadata("design:type", TemplateRef)
    ], GridRendererComponent.prototype, "cellTpl", void 0);
    __decorate([
        ViewChild('defaultButtonRenderTemplate', { static: false }),
        __metadata("design:type", TemplateRef)
    ], GridRendererComponent.prototype, "defButtonTemplate", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "selectionType", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "rowHeight", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "columnMode", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "headerHeight", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "footerHeight", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "showPager", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "reorderable", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "swapColumns", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "editablePageSize", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "pageSizes", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "actionButtons", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], GridRendererComponent.prototype, "selected", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [Object])
    ], GridRendererComponent.prototype, "rows", null);
    __decorate([
        Input(),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [Object])
    ], GridRendererComponent.prototype, "columns", null);
    __decorate([
        Input(),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [Object])
    ], GridRendererComponent.prototype, "pageSize", null);
    GridRendererComponent = __decorate([
        Component({
            selector: 'datagrid-viewer',
            template: "<div class=\"grid-renderer\">\n  <div *ngIf=\"!loading\" class=\"controlBox\">\n    <div class=\"buttonsBox\">\n      <ng-container *ngIf=\"actionButtons?.length\">\n        <div *ngFor=\"let button of actionButtons\" class=\"button-container\">\n          <ng-template\n            [ngTemplateOutlet]=\"button.template || defaultButtonRenderTemplate\"\n            [ngTemplateOutletContext]=\"{ button: button }\"\n          ></ng-template>\n        </div>\n      </ng-container>\n    </div>\n    <div class=\"searchBox\">\n      <input\n        (ngModelChange)=\"emitSearch($event)\"\n        [(ngModel)]=\"searchVal\"\n        [ngModelOptions]=\"{ standalone: true }\"\n        class=\"form-control\"\n        placeholder=\"Search Here\"\n        type=\"text\"\n      />\n      <div class=\"input-group-append\">\n        <button (click)=\"updateSearch(searchVal)\" class=\"btn btn-outline-secondary\" type=\"button\">\n          <i class=\"fa fa-search\"></i>\n        </button>\n        <button (click)=\"reset()\" class=\"btn btn-outline-primary\" type=\"button\">\n          <i class=\"fa fa-recycle\"></i>\n        </button>\n      </div>\n    </div>\n  </div>\n  <div>\n    <ngx-datatable\n      [columnMode]=\"columnMode\"\n      [columns]=\"columns\"\n      [footerHeight]=\"footerHeight\"\n      [headerHeight]=\"headerHeight\"\n      [limit]=\"pageSize\"\n      [offset]=\"activePage - 1\"\n      [reorderable]=\"reorderable\"\n      [rowHeight]=\"rowHeight\"\n      [rows]=\"rows\"\n      [selected]=\"selected\"\n      [selectionType]=\"selectionType\"\n      [swapColumns]=\"swapColumns\"\n      [targetMarkerTemplate]=\"targetMarkerTemplate\"\n      class=\"bootstrap\"\n    >\n      <ngx-datatable-footer>\n        <ng-template\n          let-curPage=\"curPage\"\n          let-offset=\"offset\"\n          let-pageSize=\"pageSize\"\n          let-rowCount=\"rowCount\"\n          let-selectedCount=\"selectedCount\"\n          ngx-datatable-footer-template\n        >\n          <div class=\"page-count\">\n            Records: {{ rowCount?.toLocaleString() }}\n            <div class=\"vertical-separator-container\">\n              <!-- <div class=\"vertical-separator\"></div> -->\n            </div>\n            <div *ngIf=\"editablePageSize\" class=\"page-size-container\">\n              Visible per page:\n              <select (ngModelChange)=\"updatePageSize($event)\" [(ngModel)]=\"fakePageSizeModel\" [ngModelOptions]=\"{ standalone: true }\">\n                <option [selected]=\"size == pageSize ? true : null\" [value]=\"size\" *ngFor=\"let size of pageSizes\" selected=\"true\">\n                  {{ size }}\n                </option>\n              </select>\n            </div>\n          </div>\n          <datatable-pager\n            (change)=\"activePage = $event?.page\"\n            [count]=\"rowCount\"\n            [hidden]=\"!showPager\"\n            [page]=\"activePage\"\n            [pagerLeftArrowIcon]=\"'datatable-icon-prev'\"\n            [pagerNextIcon]=\"'datatable-icon-right'\"\n            [pagerPreviousIcon]=\"'datatable-icon-left'\"\n            [pagerRightArrowIcon]=\"'datatable-icon-skip'\"\n            [size]=\"pageSize\"\n          ></datatable-pager>\n        </ng-template>\n      </ngx-datatable-footer>\n    </ngx-datatable>\n  </div>\n</div>\n<ng-template #hdrTpl let-column=\"column\" let-sort=\"sortFn\">\n  <span class=\"datatable-header-cell-wrapper\">\n    <span (click)=\"sort()\" class=\"datatable-header-cell-label\">\n      <strong class=\"draggable\">{{ column?.title || column?.name }}</strong>\n    </span>\n  </span>\n  <span class=\"sort-btn\"></span>\n  <span class=\"resize-handle\"></span>\n</ng-template>\n<ng-template #cellTpl let-cellValue=\"value\" let-row=\"row\" ngx-datatable-cell-template>{{ cellValue }}</ng-template>\n<ng-template #defaultButtonRenderTemplate let-button=\"button\">\n  <button (click)=\"buttonClicked(button)\" [class]=\"'btn btn-outline-primary ' + button?.class\" type=\"button\">\n    {{ button?.name || button?.title }}\n  </button>\n</ng-template>\n<ng-template #targetMarkerTemplate let-class=\"class\">\n  <div [ngClass]=\"class\">\n    <div class=\"icon datatable-icon-down\"></div>\n    <div class=\"icon datatable-icon-up\"></div>\n  </div>\n</ng-template>\n",
            styles: [".grid-renderer{margin:5px}.controlBox{display:flex;flex:0 50%;flex-direction:row;flex-flow:row;flex-wrap:wrap;justify-content:space-between;width:100%;margin-bottom:5px}.controlBox .searchBox{display:inline-flex;align-self:flex-end;padding:0 5px}.controlBox .searchBox input{border-right:none;border-top-right-radius:0;border-bottom-right-radius:0}.controlBox .searchBox input:focus{border-color:#ced4da;outline:0;box-shadow:none}.controlBox .searchBox .input-group-append button{margin-left:3px}.controlBox .searchBox .input-group-append button:first-child{margin-left:-3px;border-color:#ced4da;border-left:0;border-top-left-radius:0;border-bottom-left-radius:0}.controlBox .buttonsBox{display:inline-flex;align-self:flex-start;padding:0 5px}.controlBox .buttonsBox button{margin-right:5px}.page-size-container{display:inline-block;width:150px}.page-count{position:relative}.vertical-separator-container{position:relative;display:inline-block;width:25px;height:50%}.vertical-separator{position:absolute;top:30%;bottom:25%;width:1px;height:100%;background:#ccc}.button-container{display:inline-block;margin-right:3px}.icon{position:absolute}.datatable-icon-down{top:0}.datatable-icon-up{top:40px}.dragFromLeft .icon{left:-13px}"]
        }),
        __metadata("design:paramtypes", [ChangeDetectorRef])
    ], GridRendererComponent);
    return GridRendererComponent;
}());

var environment = {
    production: false,
    developmentMode: false,
};

var ENVIRONMENT_NAME = '____DataGridData';

var ngxBbootstrap = [
    TypeaheadModule.forRoot(),
    AccordionModule.forRoot(),
    BsDropdownModule.forRoot(),
    BsDatepickerModule.forRoot(),
    TooltipModule.forRoot(),
    TabsModule.forRoot(),
    NgxPaginationModule,
    PaginationModule.forRoot(),
];
var DataGridModule = /** @class */ (function () {
    function DataGridModule() {
    }
    DataGridModule_1 = DataGridModule;
    DataGridModule.forRoot = function (_enviroment) {
        return {
            ngModule: DataGridModule_1,
            providers: [{ provide: 'enviroment', useValue: _enviroment || environment[ENVIRONMENT_NAME] }],
        };
    };
    var DataGridModule_1;
    DataGridModule = DataGridModule_1 = __decorate([
        NgModule({
            declarations: [GridRendererComponent],
            imports: __spread([CommonModule, FormsModule, NgxDatatableModule], ngxBbootstrap),
            providers: [NotificationService, ToastrService],
            exports: [GridRendererComponent],
            schemas: [CUSTOM_ELEMENTS_SCHEMA],
        })
    ], DataGridModule);
    return DataGridModule;
}());

/**
 * Generated bundle index. Do not edit.
 */

export { DataGridModule, GridRendererComponent, NotificationService as ɵa, environment as ɵb, ENVIRONMENT_NAME as ɵc };
//# sourceMappingURL=dotgov-z_datagrid.js.map
