"use strict";

exports.__esModule = true;
exports.useSyncCollectionOnEntityCreate = useSyncCollectionOnEntityCreate;
var _react = require("react");
var _useSyncCollectionOnEntityReturn = require("./useSyncCollectionOnEntityReturn");
function useSyncCollectionOnEntityCreate(cachedState, getCollectionsToUpdate) {
  const updateCollection = (0, _react.useCallback)((collection, entity) => {
    collection.addItem(entity);
  }, []);
  const checkIfViewSynced = (0, _react.useCallback)(async (collection, entity) => {
    const updatedData = await collection.fetchData({
      ...collection.query.asComputed,
      page: 1,
      cursor: null,
      offset: 0
    });
    return collection.itemKey(updatedData.items[0]) === collection.itemKey(entity);
  }, [cachedState]);
  (0, _useSyncCollectionOnEntityReturn.useSyncCollectionOnEntityReturn)({
    cachedState,
    updateCollection,
    checkIfViewSynced,
    getEntityFromRouterState: state => state._createdEntity,
    getCollectionsToUpdate
  });
}
//# sourceMappingURL=useSyncCollectionOnEntityCreate.js.map