import { Selector } from '@ngxs/store';
import { AppState, AppStateModel } from '../state/app.state';
import { FormsState, FormsStateModel } from '../state/forms.state';
import { isNullOrUndefined } from 'util';
import { USER_EXTRAS_FORM_STATE_KEY } from '../../utils/app.constants';

export class FormsSelectors {
  @Selector([AppState, FormsState])
  static getFormState(state: AppStateModel, forms: FormsStateModel) {
    return (key: string) => {
      const currentProcessId = state.currentProcesssId;
      if (!isNullOrUndefined(forms.form[currentProcessId]) && !isNullOrUndefined(forms.form[currentProcessId][key])) {
        return forms.form[currentProcessId][key];
      }
      return undefined;
    };
  }
}
