import { Component, Input, Output, EventEmitter, forwardRef } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ReactiveFormsModule } from '@angular/forms';
import { ReferenceComponent } from '../reference/reference.component';
import { ComponentMapperComponent } from '../../../_bridge/component-mapper/component-mapper.component';
import * as i0 from "@angular/core";
import * as i1 from "../../../_services/idle-detection.service";
import * as i2 from "../../../_services/server-config.service";
import * as i3 from "@angular/common";
import * as i4 from "@angular/forms";
export class AssignmentCardComponent {
    constructor(idleService, scservice) {
        this.idleService = idleService;
        this.scservice = scservice;
        this.actionButtonClick = new EventEmitter();
    }
    ngOnInit() {
        // Children may contain 'reference' component, so we need to normalize them
        this.arChildren$ = ReferenceComponent.normalizePConnArray(this.arChildren$);
        this.checkAndEnableAutoSave();
    }
    ngOnChanges() {
        // Children may contain 'reference' component, so we need to normalize them
        this.arChildren$ = ReferenceComponent.normalizePConnArray(this.arChildren$);
    }
    ngOnDestroy() {
        this.idleService.stopWatching();
    }
    async checkAndEnableAutoSave() {
        const sdkConfig = await this.scservice.getSdkConfig();
        const autoSave = sdkConfig.serverConfig.autoSave;
        if (autoSave) {
            this.idleService.startWatching(() => this.autoSave(), autoSave);
        }
    }
    onActionButtonClick(oData) {
        this.actionButtonClick.emit(oData);
    }
    autoSave() {
        const context = this.pConn$.getContextName();
        if (PCore.getFormUtils().isStateModified(context)) {
            this.pConn$.getActionsApi().saveAssignment(context);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AssignmentCardComponent, deps: [{ token: i1.IdleDetectionService }, { token: i2.ServerConfigService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: AssignmentCardComponent, isStandalone: true, selector: "app-assignment-card", inputs: { pConn$: "pConn$", formGroup$: "formGroup$", arMainButtons$: "arMainButtons$", arSecondaryButtons$: "arSecondaryButtons$", arChildren$: "arChildren$", updateToken$: "updateToken$" }, outputs: { actionButtonClick: "actionButtonClick" }, usesOnChanges: true, ngImport: i0, template: "<form [formGroup]=\"formGroup$\" name=\"flowContainer\" class=\"psdk-flow-container\">\n  <div *ngFor=\"let kid of arChildren$\">\n    <div [ngSwitch]=\"kid.getPConnect().getComponentName()\">\n      <component-mapper *ngSwitchCase=\"'View'\" name=\"View\" [props]=\"{ formGroup$, pConn$: kid.getPConnect() }\"></component-mapper>\n      <component-mapper\n        *ngSwitchCase=\"'CaseCreateStage'\"\n        name=\"CaseCreateStage\"\n        [props]=\"{ formGroup$, pConn$: kid.getPConnect() }\"\n      ></component-mapper>\n      <component-mapper *ngSwitchCase=\"'Region'\" name=\"Region\" [props]=\"{ formGroup$, pConn$: kid.getPConnect() }\"></component-mapper>\n      <div *ngSwitchDefault>Assignment Card wants component not yet available: {{ kid.getPConnect().getComponentName() }}</div>\n    </div>\n  </div>\n</form>\n\n<div>\n  <br />\n  <div class=\"psdk-case-view-divider\"></div>\n\n  <component-mapper\n    *ngIf=\"arMainButtons$ && arSecondaryButtons$\"\n    name=\"ActionButtons\"\n    [props]=\"{ arMainButtons$, arSecondaryButtons$ }\"\n    [parent]=\"this\"\n    [outputEvents]=\"{ actionButtonClick: onActionButtonClick }\"\n  ></component-mapper>\n</div>\n", styles: [".psdk-case-view-divider{border-bottom:.0625rem solid var(--app-neutral-light-color)}.psdk-flow-container{padding:0rem 1rem}\n"], dependencies: [{ kind: "ngmodule", type: i0.forwardRef(function () { return CommonModule; }) }, { kind: "directive", type: i0.forwardRef(function () { return i3.NgForOf; }), selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i0.forwardRef(function () { return i3.NgIf; }), selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i0.forwardRef(function () { return i3.NgSwitch; }), selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i0.forwardRef(function () { return i3.NgSwitchCase; }), selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: i0.forwardRef(function () { return i3.NgSwitchDefault; }), selector: "[ngSwitchDefault]" }, { kind: "ngmodule", type: i0.forwardRef(function () { return ReactiveFormsModule; }) }, { kind: "directive", type: i0.forwardRef(function () { return i4.ɵNgNoValidate; }), selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i0.forwardRef(function () { return i4.NgControlStatusGroup; }), selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i0.forwardRef(function () { return i4.FormGroupDirective; }), selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "component", type: i0.forwardRef(function () { return ComponentMapperComponent; }), selector: "component-mapper", inputs: ["name", "props", "errorMsg", "outputEvents", "parent"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AssignmentCardComponent, decorators: [{
            type: Component,
            args: [{ selector: 'app-assignment-card', standalone: true, imports: [CommonModule, ReactiveFormsModule, forwardRef(() => ComponentMapperComponent)], template: "<form [formGroup]=\"formGroup$\" name=\"flowContainer\" class=\"psdk-flow-container\">\n  <div *ngFor=\"let kid of arChildren$\">\n    <div [ngSwitch]=\"kid.getPConnect().getComponentName()\">\n      <component-mapper *ngSwitchCase=\"'View'\" name=\"View\" [props]=\"{ formGroup$, pConn$: kid.getPConnect() }\"></component-mapper>\n      <component-mapper\n        *ngSwitchCase=\"'CaseCreateStage'\"\n        name=\"CaseCreateStage\"\n        [props]=\"{ formGroup$, pConn$: kid.getPConnect() }\"\n      ></component-mapper>\n      <component-mapper *ngSwitchCase=\"'Region'\" name=\"Region\" [props]=\"{ formGroup$, pConn$: kid.getPConnect() }\"></component-mapper>\n      <div *ngSwitchDefault>Assignment Card wants component not yet available: {{ kid.getPConnect().getComponentName() }}</div>\n    </div>\n  </div>\n</form>\n\n<div>\n  <br />\n  <div class=\"psdk-case-view-divider\"></div>\n\n  <component-mapper\n    *ngIf=\"arMainButtons$ && arSecondaryButtons$\"\n    name=\"ActionButtons\"\n    [props]=\"{ arMainButtons$, arSecondaryButtons$ }\"\n    [parent]=\"this\"\n    [outputEvents]=\"{ actionButtonClick: onActionButtonClick }\"\n  ></component-mapper>\n</div>\n", styles: [".psdk-case-view-divider{border-bottom:.0625rem solid var(--app-neutral-light-color)}.psdk-flow-container{padding:0rem 1rem}\n"] }]
        }], ctorParameters: function () { return [{ type: i1.IdleDetectionService }, { type: i2.ServerConfigService }]; }, propDecorators: { pConn$: [{
                type: Input
            }], formGroup$: [{
                type: Input
            }], arMainButtons$: [{
                type: Input
            }], arSecondaryButtons$: [{
                type: Input
            }], arChildren$: [{
                type: Input
            }], updateToken$: [{
                type: Input
            }], actionButtonClick: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 