/* eslint-disable no-underscore-dangle */
import { sourcepoint as sourcepointAtom } from "../../../atoms/tracking/index.js";
import { useEffect } from 'react';
import { useSetRecoilState } from 'recoil';
const useIsComplianceLocation = function useIsComplianceLocation() {
  const setSourcepoint = useSetRecoilState(sourcepointAtom);
  useEffect(() => {
    if (!window._sp_) {
      window._sp_queue = [];
      window._sp_ = {
        config: {
          accountId: 1962,
          baseEndpoint: 'https://cdn.privacy-mgmt.com',
          usnat: {},
          isSPA: true,
          events: {
            onMessageReceiveData(_type, data) {
              try {
                setSourcepoint(data.messageId);
              } catch (error) {
                // eslint-disable-next-line no-console
                console.error('Failed to initialize Sourcepoint: ', error);
              }
            }
          }
        }
      };
    }
  }, []);
};
export default useIsComplianceLocation;