import { useEffect } from "react";

import { useTalentProfileId } from "../redux/User/utils";
import { initProfileId } from "../services";

/**
 * Fetches & initializes the profile id from the user data.
 * This ensures all SDKs are initialized with the correct profile id.
 * @returns The profile id.
 */
export function useInitProfileId() {
  const profileId = useTalentProfileId();

  useEffect(() => {
    if (profileId) {
      initProfileId(profileId);
    }
  }, [profileId]);

  return profileId;
}
