"use strict";

exports.__esModule = true;
exports.useEntityPageLoadReporting = void 0;
var _bi = require("@wix/bex-core/bi");
var _react = require("@wix/bex-core/react");
var _react2 = require("react");
const useEntityPageLoadReporting = ({
  startTime,
  withinRouter,
  isFetching,
  initTask
}) => {
  const getBIParams = () => {
    const loadingTime = Math.round(performance.now() - startTime);
    return {
      componentType: 'Entity',
      loadingTime,
      withinRouter,
      routerUsage: withinRouter
    };
  };
  const {
    createBILogger
  } = (0, _react.useWixPatternsContainer)();
  const reportBI = createBILogger({
    pageType: 'Entity'
  });
  const reportPageInteractive = () => {
    const params = getBIParams();
    reportBI((0, _bi.wixPatternsPageInteractiveSrc144Evid1000)(params));
  };
  const reportPageFullyLoaded = () => {
    const params = getBIParams();
    reportBI((0, _bi.wixPatternsFullPageLoadCompletedSrc144Evid1001)(params));
  };
  (0, _react2.useEffect)(() => {
    if (isFetching) {
      reportPageInteractive();
      return;
    }
    if (initTask.status.isSuccess) {
      reportPageFullyLoaded();
      return;
    }
  }, [isFetching, initTask.status.isSuccess]);
};
exports.useEntityPageLoadReporting = useEntityPageLoadReporting;
//# sourceMappingURL=useEntityPageLoadReporting.js.map