import { Component, Input } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "./../../core/error-handler.service";
import * as i2 from "../../core/http.service";
import * as i3 from "@angular/common";
import * as i4 from "@angular/flex-layout/flex";
import * as i5 from "@angular/router";
import * as i6 from "@angular/material/table";
import * as i7 from "ngx-infinite-scroll";
export class ImportHistoryListComponent {
    constructor(errorHandler, http) {
        this.errorHandler = errorHandler;
        this.http = http;
        this.histories = [];
        this.displayedColumns = [
            'index',
            'imported_by',
            'date',
            'no_of_records'
        ];
        this.isWorking = false;
        this.pageEvent = { page: 1, perPage: 25, lastPage: 1 };
    }
    ngOnInit() {
        if (this.config.importHistory.isEnabled) {
            this.filter = {
                model_type: this.config.importHistory.type
            };
        }
        this.loadData();
    }
    loadData() {
        try {
            this.isWorking = true;
            this.http.get(this.config.importHistory.apiUrl, { params: { ...this.filter, ...this.pageEvent, sort_by: 'created_at|desc' } }).subscribe((result) => {
                this.histories = this.histories.concat(result.data);
                this.pageEvent.page = result.current_page;
                this.pageEvent.lastPage = result.last_page;
            });
        }
        catch (error) {
            this.errorHandler.handleError(error);
        }
        finally {
            this.isWorking = false;
        }
    }
    onScroll() {
        if (this.pageEvent.lastPage > this.pageEvent.page) {
            this.pageEvent.page += 1;
            this.loadData();
        }
    }
    reload() {
        this.histories = [];
        this.pageEvent = { page: 1, perPage: 25, lastPage: 1 };
        this.loadData();
    }
    ngOnDestroy() {
        //Until destroyed uses it
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ImportHistoryListComponent, deps: [{ token: i1.ErrorHandlerService }, { token: i2.HttpService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: ImportHistoryListComponent, selector: "app-import-history-list", inputs: { config: "config" }, ngImport: i0, template: "<section fxLayout=\"column\">\n  <h5 class=\"primary-color py-3\">\n    Import History\n  </h5>\n  <table mat-table [dataSource]=\"histories\" class=\"mat-elevation-z8 w-100\" infi infiniteScroll\n    [infiniteScrollDistance]=\"2\" [infiniteScrollThrottle]=\"50\" (scrolled)=\"onScroll()\">\n\n    <!-- Index Column -->\n    <ng-container matColumnDef=\"index\">\n      <th mat-header-cell *matHeaderCellDef> # </th>\n      <td mat-cell *matCellDef=\"let element;let i=index\"> {{ i+1 }} </td>\n    </ng-container>\n\n    <!-- Date Column -->\n    <ng-container matColumnDef=\"date\">\n      <th mat-header-cell *matHeaderCellDef> Date </th>\n      <td mat-cell *matCellDef=\"let element\"> {{element?.created_at | date:'medium'}} </td>\n    </ng-container>\n\n    <!-- Imported By Column -->\n    <ng-container matColumnDef=\"imported_by\">\n      <th mat-header-cell *matHeaderCellDef> Imported By </th>\n      <td mat-cell *matCellDef=\"let element\"> {{element?.creator?.name}} </td>\n    </ng-container>\n\n    <!-- No of records Column -->\n    <ng-container matColumnDef=\"no_of_records\">\n      <th mat-header-cell *matHeaderCellDef> # of Records </th>\n      <td mat-cell *matCellDef=\"let element\">\n        <a *ngIf=\"config.viewRouterLink\" href=\"javascript:;\"\n          [routerLink]=\"[config.viewRouterLink]\" [queryParams]=\"{import_id: element?.id}\">\n          {{element?.no_of_records}}\n        </a>\n        <span *ngIf=\"!config.viewRouterLink\">\n          {{element?.no_of_records}}\n        </span>\n      </td>\n    </ng-container>\n\n    <tr mat-header-row *matHeaderRowDef=\"displayedColumns\"></tr>\n    <tr mat-row *matRowDef=\"let row; columns: displayedColumns;\"></tr>\n  </table>\n</section>\n", styles: [""], dependencies: [{ kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i4.DefaultLayoutDirective, selector: "  [fxLayout], [fxLayout.xs], [fxLayout.sm], [fxLayout.md],  [fxLayout.lg], [fxLayout.xl], [fxLayout.lt-sm], [fxLayout.lt-md],  [fxLayout.lt-lg], [fxLayout.lt-xl], [fxLayout.gt-xs], [fxLayout.gt-sm],  [fxLayout.gt-md], [fxLayout.gt-lg]", inputs: ["fxLayout", "fxLayout.xs", "fxLayout.sm", "fxLayout.md", "fxLayout.lg", "fxLayout.xl", "fxLayout.lt-sm", "fxLayout.lt-md", "fxLayout.lt-lg", "fxLayout.lt-xl", "fxLayout.gt-xs", "fxLayout.gt-sm", "fxLayout.gt-md", "fxLayout.gt-lg"] }, { kind: "directive", type: i5.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "component", type: i6.MatTable, selector: "mat-table, table[mat-table]", exportAs: ["matTable"] }, { kind: "directive", type: i6.MatHeaderCellDef, selector: "[matHeaderCellDef]" }, { kind: "directive", type: i6.MatHeaderRowDef, selector: "[matHeaderRowDef]", inputs: ["matHeaderRowDef", "matHeaderRowDefSticky"] }, { kind: "directive", type: i6.MatColumnDef, selector: "[matColumnDef]", inputs: ["matColumnDef"] }, { kind: "directive", type: i6.MatCellDef, selector: "[matCellDef]" }, { kind: "directive", type: i6.MatRowDef, selector: "[matRowDef]", inputs: ["matRowDefColumns", "matRowDefWhen"] }, { kind: "directive", type: i6.MatHeaderCell, selector: "mat-header-cell, th[mat-header-cell]" }, { kind: "directive", type: i6.MatCell, selector: "mat-cell, td[mat-cell]" }, { kind: "component", type: i6.MatHeaderRow, selector: "mat-header-row, tr[mat-header-row]", exportAs: ["matHeaderRow"] }, { kind: "component", type: i6.MatRow, selector: "mat-row, tr[mat-row]", exportAs: ["matRow"] }, { kind: "directive", type: i7.InfiniteScrollDirective, selector: "[infiniteScroll], [infinite-scroll], [data-infinite-scroll]", inputs: ["infiniteScrollDistance", "infiniteScrollUpDistance", "infiniteScrollThrottle", "infiniteScrollDisabled", "infiniteScrollContainer", "scrollWindow", "immediateCheck", "horizontal", "alwaysCallback", "fromRoot"], outputs: ["scrolled", "scrolledUp"] }, { kind: "pipe", type: i3.DatePipe, name: "date" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ImportHistoryListComponent, decorators: [{
            type: Component,
            args: [{ selector: 'app-import-history-list', template: "<section fxLayout=\"column\">\n  <h5 class=\"primary-color py-3\">\n    Import History\n  </h5>\n  <table mat-table [dataSource]=\"histories\" class=\"mat-elevation-z8 w-100\" infi infiniteScroll\n    [infiniteScrollDistance]=\"2\" [infiniteScrollThrottle]=\"50\" (scrolled)=\"onScroll()\">\n\n    <!-- Index Column -->\n    <ng-container matColumnDef=\"index\">\n      <th mat-header-cell *matHeaderCellDef> # </th>\n      <td mat-cell *matCellDef=\"let element;let i=index\"> {{ i+1 }} </td>\n    </ng-container>\n\n    <!-- Date Column -->\n    <ng-container matColumnDef=\"date\">\n      <th mat-header-cell *matHeaderCellDef> Date </th>\n      <td mat-cell *matCellDef=\"let element\"> {{element?.created_at | date:'medium'}} </td>\n    </ng-container>\n\n    <!-- Imported By Column -->\n    <ng-container matColumnDef=\"imported_by\">\n      <th mat-header-cell *matHeaderCellDef> Imported By </th>\n      <td mat-cell *matCellDef=\"let element\"> {{element?.creator?.name}} </td>\n    </ng-container>\n\n    <!-- No of records Column -->\n    <ng-container matColumnDef=\"no_of_records\">\n      <th mat-header-cell *matHeaderCellDef> # of Records </th>\n      <td mat-cell *matCellDef=\"let element\">\n        <a *ngIf=\"config.viewRouterLink\" href=\"javascript:;\"\n          [routerLink]=\"[config.viewRouterLink]\" [queryParams]=\"{import_id: element?.id}\">\n          {{element?.no_of_records}}\n        </a>\n        <span *ngIf=\"!config.viewRouterLink\">\n          {{element?.no_of_records}}\n        </span>\n      </td>\n    </ng-container>\n\n    <tr mat-header-row *matHeaderRowDef=\"displayedColumns\"></tr>\n    <tr mat-row *matRowDef=\"let row; columns: displayedColumns;\"></tr>\n  </table>\n</section>\n" }]
        }], ctorParameters: () => [{ type: i1.ErrorHandlerService }, { type: i2.HttpService }], propDecorators: { config: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 