import { EventEmitter } from '@angular/core';
import { VariableStateEnum } from '../../../communication';
import { VariableUtil } from '../../../utils/variable-util';
import { VariableDefinition } from '../../../communication/variable/variable-definition';
export class TranslationObserver {
    constructor(model, variableCommunicator, variableStore, signalRAppId) {
        this.translationValueChanged = new EventEmitter();
        if (!model.variableName) {
            return;
        }
        const variable = new VariableDefinition(model.variableName, model.variableGroupName, model.dataSourceCode, model.variableVersion);
        const variableName = VariableUtil.getConvertedVariableName(variableStore, variable);
        if (!variableName) {
            return;
        }
        variableCommunicator.subscribeVariableState(variableName).subscribe(variableValue => {
            if (variableValue.state === VariableStateEnum.Normal) {
                variableCommunicator.openVariable(variableName, signalRAppId).subscribe(value => {
                    if (value.state === VariableStateEnum.DataNormal) {
                        this.currentValue = value;
                        this.translationValueChanged.emit(this.currentValue.value);
                    }
                });
            }
        });
    }
}
