import { Injectable } from '@angular/core';
import {Observable, Subject} from "rxjs";

@Injectable()
export class DictionaryService {
    fieldsParameters: {[field_id: string]: string[]} = {}
    parameters: string[] = []
    parameters$: Subject<string[]> = new Subject<string[]>()

    updateParameters(field_id: string, newParameters: string[]) {
        this.fieldsParameters[field_id] = newParameters;

        this.parameters = [].concat();
        for (const field of Object.values(this.fieldsParameters)) {
            this.parameters = this.parameters.concat(field);
        }
        this.parameters = this.parameters.filter(
            (item,index) => this.parameters.indexOf(item) === index
        );

        this.parameters$.next(this.parameters)
    }
}