// This file is auto generated by Microsoft 365 Agents Toolkit to provide you instructions and reference code to implement single sign on.
// This file will initialize TeamsFx SDK and show `GetUserProfile` component after initialization.

import { useTeamsFx } from "@microsoft/teamsfx-react";
import { GetUserProfile } from "./GetUserProfile";

export function InitTeamsFx() {
  // For usage of useTeamsFx(), please refer to: https://www.npmjs.com/package/@microsoft/teamsfx-react#useTeamsfx.
  // You need to wait until `loading == false` to use TeamsFx SDK.
  const { loading, error, teamsfx } = useTeamsFx({
    initiateLoginEndpoint: process.env.REACT_APP_START_LOGIN_PAGE_URL,
    clientId: process.env.REACT_APP_CLIENT_ID,
  });

  return (
    <div>
      {!loading && error && (
        <div className="error">Failed init TeamsFx. Please try again later.</div>
      )}
      {!loading && teamsfx && <GetUserProfile teamsfx={teamsfx} />}
    </div>
  );
}
