import { __decorate } from "tslib";
import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import * as i0 from "@angular/core";
import * as i1 from "@angular/material/dialog";
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/material/button";
let AuditLogViewModelComponent = class AuditLogViewModelComponent {
    constructor(dialogRef, data, http) {
        this.dialogRef = dialogRef;
        this.data = data;
        this.http = http;
        this.showDeltaChanges = false;
        this.changeList = [];
    }
    ngOnInit() {
        if (this.data) {
            this.http.get(`api/recent-log-for-model`, {
                params: {
                    model_type: this.data?.modelType,
                    model_id: this.data?.modelId
                }
            }).pipe(untilDestroyed(this)).subscribe((result) => {
                this.logInfo = result?.item;
                this.getTransformedChanges();
            });
        }
    }
    getTransformedChanges() {
        const changes = ((this.logInfo?.action === 'deleted') ? Object.keys(this.logInfo?.object) : Object.keys(this.logInfo?.data?.changes)) || [];
        changes.forEach((key) => {
            const displayAttribute = key.split('_').map(x => x.charAt(0).toUpperCase() + x.slice(1)).join(' ');
            this.changeList.push({ displayAttribute: displayAttribute, attribute: key, newValue: (this.logInfo?.action === 'deleted') ? '' : (this.logInfo?.object[key] ?? ''), oldValue: this.logInfo?.pre_object[key] ?? '' });
        });
    }
    close() {
        this.dialogRef.close();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AuditLogViewModelComponent, deps: [{ token: i1.MatDialogRef }, { token: MAT_DIALOG_DATA }, { token: i2.HttpService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: AuditLogViewModelComponent, selector: "app-audit-log-view", ngImport: i0, template: "<div fxLayout=\"column\" class=\"m-4\" fxLayoutGap=\"1.5rem\">\n    <h3 class=\"text-center\">Audit Log</h3>\n    <div fxLayout=\"column\" fxLayoutGap=\"0.5rem\" *ngIf=\"logInfo\">\n        <div>Object Type: {{logInfo?.object_type}}</div>\n        <div>Object Id: {{logInfo?.object_id}}</div>\n        <div>Action: {{logInfo?.action}}</div>\n        <div>Created At: {{logInfo?.created_at | date:'medium'}}</div>\n        <div>Created By: {{logInfo?.user?.email}}</div>\n    </div>\n\n\n    <div class=\"container\" *ngIf=\"changeList.length > 0\">\n        <h4 class=\"font-weight-bold\"> Changes in Attributes</h4>\n        <table class=\"table table-striped table-sm border\">\n            <thead>\n                <tr>\n                    <th scope=\"col\">#</th>\n                    <th scope=\"col\">Attribute</th>\n                    <th scope=\"col\">Old Value</th>\n                    <th scope=\"col\">New Value</th>\n                </tr>\n            </thead>\n            <tbody>\n                <tr *ngFor=\"let change of changeList; let i= index;\">\n                    <th scope=\"row\">{{i+1}}</th>\n                    <td>{{change?.displayAttribute}}</td>\n                    <td>{{change?.oldValue}}</td>\n                    <td>{{change?.newValue}}</td>\n                </tr>\n            </tbody>\n        </table>\n\n    </div>\n\n    <div>\n        <button mat-raised-button (click)=\"close()\">Close</button>\n    </div>\n</div>", styles: [".scroll-container{max-height:400px;overflow:auto}\n"], dependencies: [{ kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { 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: i4.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: "component", type: i5.MatButton, selector: "    button[mat-button], button[mat-raised-button], button[mat-flat-button],    button[mat-stroked-button]  ", exportAs: ["matButton"] }, { kind: "pipe", type: i3.DatePipe, name: "date" }] }); }
};
AuditLogViewModelComponent = __decorate([
    UntilDestroy()
], AuditLogViewModelComponent);
export { AuditLogViewModelComponent };
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AuditLogViewModelComponent, decorators: [{
            type: Component,
            args: [{ selector: 'app-audit-log-view', template: "<div fxLayout=\"column\" class=\"m-4\" fxLayoutGap=\"1.5rem\">\n    <h3 class=\"text-center\">Audit Log</h3>\n    <div fxLayout=\"column\" fxLayoutGap=\"0.5rem\" *ngIf=\"logInfo\">\n        <div>Object Type: {{logInfo?.object_type}}</div>\n        <div>Object Id: {{logInfo?.object_id}}</div>\n        <div>Action: {{logInfo?.action}}</div>\n        <div>Created At: {{logInfo?.created_at | date:'medium'}}</div>\n        <div>Created By: {{logInfo?.user?.email}}</div>\n    </div>\n\n\n    <div class=\"container\" *ngIf=\"changeList.length > 0\">\n        <h4 class=\"font-weight-bold\"> Changes in Attributes</h4>\n        <table class=\"table table-striped table-sm border\">\n            <thead>\n                <tr>\n                    <th scope=\"col\">#</th>\n                    <th scope=\"col\">Attribute</th>\n                    <th scope=\"col\">Old Value</th>\n                    <th scope=\"col\">New Value</th>\n                </tr>\n            </thead>\n            <tbody>\n                <tr *ngFor=\"let change of changeList; let i= index;\">\n                    <th scope=\"row\">{{i+1}}</th>\n                    <td>{{change?.displayAttribute}}</td>\n                    <td>{{change?.oldValue}}</td>\n                    <td>{{change?.newValue}}</td>\n                </tr>\n            </tbody>\n        </table>\n\n    </div>\n\n    <div>\n        <button mat-raised-button (click)=\"close()\">Close</button>\n    </div>\n</div>", styles: [".scroll-container{max-height:400px;overflow:auto}\n"] }]
        }], ctorParameters: () => [{ type: i1.MatDialogRef }, { type: undefined, decorators: [{
                    type: Inject,
                    args: [MAT_DIALOG_DATA]
                }] }, { type: i2.HttpService }] });
//# sourceMappingURL=data:application/json;base64, 