import updateFetchedDataFiles from './fetch/updateFetchedDataFiles';
import pageBuildTimeAtom from './atoms/pageBuildTime';
import pageTypeAtom from './atoms/pageType';
import pagePathPrefixAtom from './atoms/pagePathPrefix';
import pagesManifestAtom from './atoms/pagesManifest';
import currentPageAtom from './atoms/currentPage';
import flatpackConfigAtom from './atoms/flatpackConfig';
import electionTimestampFormatAtom from './atoms/electionTimestampFormat';
const getElectionInitializer = function getElectionInitializer(opts) {
  const {
    flatpackConfig,
    pageBuildTime,
    pageType,
    pagePathPrefix,
    pagesManifest,
    currentPage,
    data,
    electionTimestampFormat = 'relative',
    set: snapshotSet
  } = opts;
  return snapshot => {
    const set = (atom, value) => {
      if (snapshot) return snapshot.set(atom, value);
      return snapshotSet(atom, value);
    };
    set(flatpackConfigAtom, flatpackConfig);
    set(pageBuildTimeAtom, pageBuildTime);
    set(pageTypeAtom, pageType);
    set(pagePathPrefixAtom, pagePathPrefix);
    set(pagesManifestAtom, pagesManifest);
    set(currentPageAtom, currentPage);
    set(electionTimestampFormatAtom, electionTimestampFormat);
    updateFetchedDataFiles({
      set,
      values: data
    });
  };
};
export default getElectionInitializer;