import { __decorate } from "tslib";
import { UntilDestroy } from '@ngneat/until-destroy';
import { untilDestroyed } from '@ngneat/until-destroy';
import { UpdateViewComponent } from './../update-view/update-view.component';
import { UntypedFormControl } from '@angular/forms';
import { Component } from '@angular/core';
import { debounceTime } from 'rxjs/operators';
import * as i0 from "@angular/core";
import * as i1 from "@angular/material/dialog";
import * as i2 from "./../techlify-update.service";
import * as i3 from "@angular/forms";
import * as i4 from "./../../core/alert.service";
import * as i5 from "@angular/common";
import * as i6 from "ngx-infinite-scroll";
import * as i7 from "@angular/flex-layout/flex";
import * as i8 from "@angular/material/button";
import * as i9 from "@angular/material/form-field";
import * as i10 from "@angular/material/icon";
import * as i11 from "@angular/material/input";
import * as i12 from "@angular/material/sort";
import * as i13 from "@angular/material/table";
import * as i14 from "../../read-more/read-more.component";
let TechlifyUpdateHistoryComponent = class TechlifyUpdateHistoryComponent {
    constructor(dialog, techlifyUpdateService, fb, alertService) {
        this.dialog = dialog;
        this.techlifyUpdateService = techlifyUpdateService;
        this.fb = fb;
        this.alertService = alertService;
        this.techlifyUpdates = [];
        this.displayedColumns = [
            'index',
            'title',
            'is_pinned',
            'version',
            'released_on',
            'learn_more_link',
            'description',
            'creator',
            'actions'
        ];
        this.page = 1;
        this.perPage = 25;
        this.isWorking = false;
        this.filterFormGroup = this.fb.group({
            search: new UntypedFormControl(''),
            version: new UntypedFormControl(''),
            sort_by: new UntypedFormControl('released_on|DESC'),
        });
    }
    ngOnInit() {
        this.loadData();
        this.listenChanges();
        this.updateCurrentUserUpdates();
    }
    listenChanges() {
        this.filterFormGroup.valueChanges.pipe(debounceTime(500), untilDestroyed(this))
            .subscribe(changes => {
            this.reload();
        });
    }
    ngOnDestroy() { }
    async loadData() {
        try {
            this.isWorking = true;
            var filters = this.filterFormGroup.value;
            filters.perPage = this.perPage;
            filters.page = this.page;
            let result = await this.techlifyUpdateService.getTechlifyUpdates(filters);
            this.lastPage = result.last_page || this.page;
            this.techlifyUpdates = this.techlifyUpdates.concat(result.data);
        }
        catch (error) {
            this.alertService.addAlert("Unable to process, try later", "warn");
        }
        finally {
            this.isWorking = false;
        }
    }
    reload() {
        this.techlifyUpdates = [];
        this.page = 1;
        if (!this.isWorking) {
            this.loadData();
        }
    }
    onScroll() {
        if (!this.isWorking && this.page < this.lastPage) {
            this.page += 1;
            this.loadData();
        }
    }
    resetFieldValue(field) {
        this.filterFormGroup.get(field).setValue("");
    }
    sortColumn(event) {
        var direction = event.direction.toString().toUpperCase();
        this.assignFilter(event.active, direction);
    }
    assignFilter(column, direction) {
        switch (column) {
            case 'title': {
                return this.filterFormGroup.get('sort_by').setValue("title|" + direction);
            }
            case 'released_on': {
                return this.filterFormGroup.get('sort_by').setValue("released_on|" + direction);
            }
            case 'version': {
                return this.filterFormGroup.get('sort_by').setValue("version|" + direction);
            }
            default: {
                return this.filterFormGroup.get('sort_by').setValue("created_at|DESC");
            }
        }
        ;
    }
    openUpdateView(techlifyUpdate) {
        const dialogRef = this.dialog.open(UpdateViewComponent, {
            width: "800px",
            autoFocus: false,
            data: {
                techlifyUpdate: techlifyUpdate,
                isFromHistory: true,
            } // Any data passed here will be injected into the model
        });
    }
    async updateCurrentUserUpdates() {
        try {
            await this.techlifyUpdateService.updateCurrentUserUpdates();
        }
        catch (error) {
            this.alertService.addAlert("Unable to process, try later", "warn");
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TechlifyUpdateHistoryComponent, deps: [{ token: i1.MatDialog }, { token: i2.TechlifyUpdateService }, { token: i3.UntypedFormBuilder }, { token: i4.AlertService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: TechlifyUpdateHistoryComponent, selector: "app-techlify-update-history", ngImport: i0, template: "<section class=\"p-4\" fxLayout=\"column\">\n  <h3 class=\"primary-color text-center\">\n    App Updates\n  </h3>\n  <form [formGroup]=\"filterFormGroup\" fxLayout=\"row wrap\" fxLayoutGap=\"0.5rem\" fxFlex=\"100%\" style=\"font-size: 12px;\">\n    <mat-form-field fxFlex=\"0 1 calc(100% - 0.5rem)\" fxFlex.gt-md=\"0 1 calc(15% - 0.5rem)\" appearance=\"outline\"\n      fxFlex.gt-sm=\"0 1 calc(20% - 0.5rem)\">\n      <input type=\"text\" matInput formControlName=\"search\" placeholder=\"Title\" autocomplete=\"off\" />\n      <button *ngIf=\"filterFormGroup.get('search').value\" matSuffix mat-icon-button (click)=\"resetFieldValue('search')\">\n        <mat-icon>close</mat-icon>\n      </button>\n    </mat-form-field>\n    <mat-form-field fxFlex=\"0 1 calc(100% - 0.5rem)\" fxFlex.gt-md=\"0 1 calc(15% - 0.5rem)\" appearance=\"outline\"\n      fxFlex.gt-sm=\"0 1 calc(20% - 0.5rem)\">\n      <input type=\"text\" matInput formControlName=\"version\" placeholder=\"Version\" autocomplete=\"off\" />\n      <button *ngIf=\"filterFormGroup.get('version').value\" matSuffix mat-icon-button\n        (click)=\"resetFieldValue('version')\">\n        <mat-icon>close</mat-icon>\n      </button>\n    </mat-form-field>\n  </form>\n\n  <table mat-table [dataSource]=\"techlifyUpdates\" class=\"mat-elevation-z8 w-100\" matSort multiTemplateDataRows\n    (matSortChange)=\"sortColumn($event)\" infiniteScroll [infiniteScrollDistance]=\"2\" [infiniteScrollThrottle]=\"50\"\n    (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=dataIndex\"> {{ i+1 }} </td>\n    </ng-container>\n\n    <!-- Course Column -->\n    <ng-container matColumnDef=\"title\">\n      <th mat-header-cell *matHeaderCellDef mat-sort-header disableClear> Title </th>\n      <td mat-cell *matCellDef=\"let element\"> {{element?.title}} </td>\n    </ng-container>\n\n    <!--Is Pinned Column-->\n    <ng-container matColumnDef=\"is_pinned\">\n      <th mat-header-cell *matHeaderCellDef mat-sort-header disableClear> Is Pinned </th>\n      <td mat-cell *matCellDef=\"let element\"> {{element?.is_pinned ? 'Yes' : 'No'}} </td>\n    </ng-container>\n\n    <!-- Version Column -->\n    <ng-container matColumnDef=\"version\">\n      <th mat-header-cell *matHeaderCellDef mat-sort-header disableClear> Version </th>\n      <td mat-cell *matCellDef=\"let element\"> {{element?.version}} </td>\n    </ng-container>\n\n    <!-- Released On Column -->\n    <ng-container matColumnDef=\"released_on\">\n      <th mat-header-cell *matHeaderCellDef mat-sort-header disableClear> Released On </th>\n      <td mat-cell *matCellDef=\"let element\"> {{element?.released_on | date:'mediumDate'}} </td>\n    </ng-container>\n\n    <!-- Learn More Link Column -->\n    <ng-container matColumnDef=\"learn_more_link\">\n      <th mat-header-cell *matHeaderCellDef> Learn more link </th>\n      <td mat-cell *matCellDef=\"let element\">\n        <a [href]=\"element?.learn_more_link\" target=\"_blank\">\n          {{element?.learn_more_link}}\n        </a>\n      </td>\n    </ng-container>\n\n    <!-- Description Column -->\n    <ng-container matColumnDef=\"description\">\n      <th mat-header-cell *matHeaderCellDef> Description </th>\n      <td mat-cell *matCellDef=\"let element\">\n        <app-read-more [text]=\"element?.description\" [maxLength]=\"50\"></app-read-more>\n      </td>\n    </ng-container>\n\n    <!-- Creator Column -->\n    <ng-container matColumnDef=\"creator\">\n      <th mat-header-cell *matHeaderCellDef> Creator </th>\n      <td mat-cell *matCellDef=\"let element\">\n        {{element?.creator?.name}}\n        <div fxLayout class=\"small\">\n          {{element?.created_at | date : 'mediumDate'}}\n        </div>\n      </td>\n    </ng-container>\n\n    <!-- Actions Column -->\n    <ng-container matColumnDef=\"actions\">\n      <th mat-header-cell *matHeaderCellDef> Actions </th>\n      <td mat-cell *matCellDef=\"let element\" class=\"secondary-color\">\n        <button type=\"button\" class=\"secondary-color\" mat-icon-button (click)=\"openUpdateView(element)\">\n          <mat-icon>remove_red_eye</mat-icon>\n        </button>\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>", styles: [""], dependencies: [{ kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i3.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i3.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i3.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i3.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "directive", type: i6.InfiniteScrollDirective, selector: "[infiniteScroll], [infinite-scroll], [data-infinite-scroll]", inputs: ["infiniteScrollDistance", "infiniteScrollUpDistance", "infiniteScrollThrottle", "infiniteScrollDisabled", "infiniteScrollContainer", "scrollWindow", "immediateCheck", "horizontal", "alwaysCallback", "fromRoot"], outputs: ["scrolled", "scrolledUp"] }, { kind: "directive", type: i7.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: i7.DefaultLayoutGapDirective, selector: "  [fxLayoutGap], [fxLayoutGap.xs], [fxLayoutGap.sm], [fxLayoutGap.md],  [fxLayoutGap.lg], [fxLayoutGap.xl], [fxLayoutGap.lt-sm], [fxLayoutGap.lt-md],  [fxLayoutGap.lt-lg], [fxLayoutGap.lt-xl], [fxLayoutGap.gt-xs], [fxLayoutGap.gt-sm],  [fxLayoutGap.gt-md], [fxLayoutGap.gt-lg]", inputs: ["fxLayoutGap", "fxLayoutGap.xs", "fxLayoutGap.sm", "fxLayoutGap.md", "fxLayoutGap.lg", "fxLayoutGap.xl", "fxLayoutGap.lt-sm", "fxLayoutGap.lt-md", "fxLayoutGap.lt-lg", "fxLayoutGap.lt-xl", "fxLayoutGap.gt-xs", "fxLayoutGap.gt-sm", "fxLayoutGap.gt-md", "fxLayoutGap.gt-lg"] }, { kind: "directive", type: i7.DefaultFlexDirective, selector: "  [fxFlex], [fxFlex.xs], [fxFlex.sm], [fxFlex.md],  [fxFlex.lg], [fxFlex.xl], [fxFlex.lt-sm], [fxFlex.lt-md],  [fxFlex.lt-lg], [fxFlex.lt-xl], [fxFlex.gt-xs], [fxFlex.gt-sm],  [fxFlex.gt-md], [fxFlex.gt-lg]", inputs: ["fxFlex", "fxFlex.xs", "fxFlex.sm", "fxFlex.md", "fxFlex.lg", "fxFlex.xl", "fxFlex.lt-sm", "fxFlex.lt-md", "fxFlex.lt-lg", "fxFlex.lt-xl", "fxFlex.gt-xs", "fxFlex.gt-sm", "fxFlex.gt-md", "fxFlex.gt-lg"] }, { kind: "component", type: i8.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }, { kind: "component", type: i9.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i9.MatSuffix, selector: "[matSuffix], [matIconSuffix], [matTextSuffix]", inputs: ["matTextSuffix"] }, { kind: "component", type: i10.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: i11.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl],      input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "directive", type: i12.MatSort, selector: "[matSort]", inputs: ["matSortActive", "matSortStart", "matSortDirection", "matSortDisableClear", "matSortDisabled"], outputs: ["matSortChange"], exportAs: ["matSort"] }, { kind: "component", type: i12.MatSortHeader, selector: "[mat-sort-header]", inputs: ["mat-sort-header", "arrowPosition", "start", "disabled", "sortActionDescription", "disableClear"], exportAs: ["matSortHeader"] }, { kind: "component", type: i13.MatTable, selector: "mat-table, table[mat-table]", exportAs: ["matTable"] }, { kind: "directive", type: i13.MatHeaderCellDef, selector: "[matHeaderCellDef]" }, { kind: "directive", type: i13.MatHeaderRowDef, selector: "[matHeaderRowDef]", inputs: ["matHeaderRowDef", "matHeaderRowDefSticky"] }, { kind: "directive", type: i13.MatColumnDef, selector: "[matColumnDef]", inputs: ["matColumnDef"] }, { kind: "directive", type: i13.MatCellDef, selector: "[matCellDef]" }, { kind: "directive", type: i13.MatRowDef, selector: "[matRowDef]", inputs: ["matRowDefColumns", "matRowDefWhen"] }, { kind: "directive", type: i13.MatHeaderCell, selector: "mat-header-cell, th[mat-header-cell]" }, { kind: "directive", type: i13.MatCell, selector: "mat-cell, td[mat-cell]" }, { kind: "component", type: i13.MatHeaderRow, selector: "mat-header-row, tr[mat-header-row]", exportAs: ["matHeaderRow"] }, { kind: "component", type: i13.MatRow, selector: "mat-row, tr[mat-row]", exportAs: ["matRow"] }, { kind: "component", type: i14.ReadMoreComponent, selector: "app-read-more", inputs: ["text", "maxLength"] }, { kind: "pipe", type: i5.DatePipe, name: "date" }] }); }
};
TechlifyUpdateHistoryComponent = __decorate([
    UntilDestroy()
], TechlifyUpdateHistoryComponent);
export { TechlifyUpdateHistoryComponent };
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TechlifyUpdateHistoryComponent, decorators: [{
            type: Component,
            args: [{ selector: 'app-techlify-update-history', template: "<section class=\"p-4\" fxLayout=\"column\">\n  <h3 class=\"primary-color text-center\">\n    App Updates\n  </h3>\n  <form [formGroup]=\"filterFormGroup\" fxLayout=\"row wrap\" fxLayoutGap=\"0.5rem\" fxFlex=\"100%\" style=\"font-size: 12px;\">\n    <mat-form-field fxFlex=\"0 1 calc(100% - 0.5rem)\" fxFlex.gt-md=\"0 1 calc(15% - 0.5rem)\" appearance=\"outline\"\n      fxFlex.gt-sm=\"0 1 calc(20% - 0.5rem)\">\n      <input type=\"text\" matInput formControlName=\"search\" placeholder=\"Title\" autocomplete=\"off\" />\n      <button *ngIf=\"filterFormGroup.get('search').value\" matSuffix mat-icon-button (click)=\"resetFieldValue('search')\">\n        <mat-icon>close</mat-icon>\n      </button>\n    </mat-form-field>\n    <mat-form-field fxFlex=\"0 1 calc(100% - 0.5rem)\" fxFlex.gt-md=\"0 1 calc(15% - 0.5rem)\" appearance=\"outline\"\n      fxFlex.gt-sm=\"0 1 calc(20% - 0.5rem)\">\n      <input type=\"text\" matInput formControlName=\"version\" placeholder=\"Version\" autocomplete=\"off\" />\n      <button *ngIf=\"filterFormGroup.get('version').value\" matSuffix mat-icon-button\n        (click)=\"resetFieldValue('version')\">\n        <mat-icon>close</mat-icon>\n      </button>\n    </mat-form-field>\n  </form>\n\n  <table mat-table [dataSource]=\"techlifyUpdates\" class=\"mat-elevation-z8 w-100\" matSort multiTemplateDataRows\n    (matSortChange)=\"sortColumn($event)\" infiniteScroll [infiniteScrollDistance]=\"2\" [infiniteScrollThrottle]=\"50\"\n    (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=dataIndex\"> {{ i+1 }} </td>\n    </ng-container>\n\n    <!-- Course Column -->\n    <ng-container matColumnDef=\"title\">\n      <th mat-header-cell *matHeaderCellDef mat-sort-header disableClear> Title </th>\n      <td mat-cell *matCellDef=\"let element\"> {{element?.title}} </td>\n    </ng-container>\n\n    <!--Is Pinned Column-->\n    <ng-container matColumnDef=\"is_pinned\">\n      <th mat-header-cell *matHeaderCellDef mat-sort-header disableClear> Is Pinned </th>\n      <td mat-cell *matCellDef=\"let element\"> {{element?.is_pinned ? 'Yes' : 'No'}} </td>\n    </ng-container>\n\n    <!-- Version Column -->\n    <ng-container matColumnDef=\"version\">\n      <th mat-header-cell *matHeaderCellDef mat-sort-header disableClear> Version </th>\n      <td mat-cell *matCellDef=\"let element\"> {{element?.version}} </td>\n    </ng-container>\n\n    <!-- Released On Column -->\n    <ng-container matColumnDef=\"released_on\">\n      <th mat-header-cell *matHeaderCellDef mat-sort-header disableClear> Released On </th>\n      <td mat-cell *matCellDef=\"let element\"> {{element?.released_on | date:'mediumDate'}} </td>\n    </ng-container>\n\n    <!-- Learn More Link Column -->\n    <ng-container matColumnDef=\"learn_more_link\">\n      <th mat-header-cell *matHeaderCellDef> Learn more link </th>\n      <td mat-cell *matCellDef=\"let element\">\n        <a [href]=\"element?.learn_more_link\" target=\"_blank\">\n          {{element?.learn_more_link}}\n        </a>\n      </td>\n    </ng-container>\n\n    <!-- Description Column -->\n    <ng-container matColumnDef=\"description\">\n      <th mat-header-cell *matHeaderCellDef> Description </th>\n      <td mat-cell *matCellDef=\"let element\">\n        <app-read-more [text]=\"element?.description\" [maxLength]=\"50\"></app-read-more>\n      </td>\n    </ng-container>\n\n    <!-- Creator Column -->\n    <ng-container matColumnDef=\"creator\">\n      <th mat-header-cell *matHeaderCellDef> Creator </th>\n      <td mat-cell *matCellDef=\"let element\">\n        {{element?.creator?.name}}\n        <div fxLayout class=\"small\">\n          {{element?.created_at | date : 'mediumDate'}}\n        </div>\n      </td>\n    </ng-container>\n\n    <!-- Actions Column -->\n    <ng-container matColumnDef=\"actions\">\n      <th mat-header-cell *matHeaderCellDef> Actions </th>\n      <td mat-cell *matCellDef=\"let element\" class=\"secondary-color\">\n        <button type=\"button\" class=\"secondary-color\" mat-icon-button (click)=\"openUpdateView(element)\">\n          <mat-icon>remove_red_eye</mat-icon>\n        </button>\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>" }]
        }], ctorParameters: () => [{ type: i1.MatDialog }, { type: i2.TechlifyUpdateService }, { type: i3.UntypedFormBuilder }, { type: i4.AlertService }] });
//# sourceMappingURL=data:application/json;base64, 