import { ofType } from 'redux-observable';
import { concat, of } from 'rxjs';
import { switchMap } from 'rxjs/operators';

import {
  getBudgetingTabAction,
  getFrequencyCapTabAction,
  getPricingTabAction,
  getSettingsTabAction,
  getTargetingTabAction,
  initializeDemandFormDataAction,
} from '../slices';

export default (action$) =>
  action$.pipe(
    ofType(initializeDemandFormDataAction.type),
    switchMap(() => {
      const actions = [
        of(getSettingsTabAction()),
        of(getPricingTabAction()),
        of(getTargetingTabAction()),
        of(getBudgetingTabAction()),
        of(getFrequencyCapTabAction()),
      ];
      return concat(...actions);
    }),
  );
