{"version":3,"file":"Main.mjs","sources":["../../../../../../../../../web/src/ui/b2b/screens/Main.tsx"],"sourcesContent":["import { useLingui } from '@lingui/react/macro';\nimport { AuthFlowType } from '@stytch/core/public';\nimport React from 'react';\n\nimport Column from '../../components/atoms/Column';\nimport Typography from '../../components/atoms/Typography';\nimport Divider from '../../components/molecules/Divider';\nimport { LoadingScreen } from '../../components/molecules/Loading';\nimport { usePresentation } from '../../components/PresentationConfig';\nimport { generateProductComponentsOrdering, isButtonsComponent } from '../generateProductComponentsOrdering';\nimport { useConfig, useGlobalReducer } from '../GlobalContextProvider';\nimport { useEffectiveAuthConfig } from '../hooks/useEffectiveAuthConfig';\nimport { ButtonComponent, MainScreenComponent } from '../types/AppScreens';\nimport { useProductComponents } from '../utils';\n\nfunction isButtonGroup(group: MainScreenComponent[]): group is ButtonComponent[] {\n  return group.every(isButtonsComponent);\n}\n\nexport const MainScreen = () => {\n  const { options } = usePresentation();\n  const [state] = useGlobalReducer();\n  const { t } = useLingui();\n\n  const { primaryAuthMethods, email, emailVerified } = state.primary;\n\n  const config = useConfig();\n  const { products } = useEffectiveAuthConfig();\n\n  const isLoading = state.flowState.type === AuthFlowType.Organization && !state.flowState.organization;\n\n  // Generate ordering and types of product components\n  const productComponentsOrdering = generateProductComponentsOrdering(products, state.flowState);\n  const mainScreenComponents = useProductComponents(config, 'mainScreen')!;\n  const { SsoAndOAuthButtons } = useProductComponents(config, 'ssoAndOAuthButtons')!;\n\n  const organizationName = state.flowState.organization?.organization_name;\n  let title: string;\n  switch (state.flowState.type) {\n    case AuthFlowType.Discovery:\n      title = t({ id: 'login.title', message: 'Sign up or log in' });\n      break;\n    case AuthFlowType.PasswordReset:\n      title = '';\n      break;\n    default:\n      title = organizationName\n        ? t({\n            id: 'organizationLogin.title',\n            message: `Continue to ${organizationName}`,\n          })\n        : t({\n            id: 'organizationLogin.titleUnknown',\n            message: 'Continue to ...',\n            comment: 'Used instead of organizationLogin.title when the organization name is not available',\n          });\n      break;\n  }\n\n  // Show a targeted message if the member has an unverified email address and\n  // additional primary auth is required\n  const showVerifyEmailCopy = email && emailVerified === false && primaryAuthMethods;\n\n  if (isLoading) {\n    return <LoadingScreen />;\n  }\n\n  return (\n    <Column gap={6}>\n      {!options.hideHeaderText &&\n        (showVerifyEmailCopy ? (\n          <>\n            <Typography variant=\"header\">\n              {t({ id: 'emailVerification.title', message: 'Verify your email' })}\n            </Typography>\n\n            <Typography>\n              {t({\n                id: 'emailVerification.content',\n                message: 'Confirm your email address with one of the following:',\n              })}\n            </Typography>\n          </>\n        ) : (\n          title && (\n            <Typography variant=\"header\" align=\"center\">\n              {title}\n            </Typography>\n          )\n        ))}\n\n      <Column gap={4}>\n        {productComponentsOrdering.map((group) =>\n          isButtonGroup(group) ? (\n            <SsoAndOAuthButtons key=\"buttons\" buttons={group} />\n          ) : (\n            group.map((component, index) => {\n              const Component = mainScreenComponents[component];\n              if (Component) {\n                return <Component key={component} />;\n              }\n              if (component === MainScreenComponent.Divider) {\n                return <Divider key={'divider' + index} />;\n              }\n              return null;\n            })\n          ),\n        )}\n      </Column>\n    </Column>\n  );\n};\n"],"names":["isButtonGroup","group","every","isButtonsComponent","MainScreen","options","usePresentation","state","useGlobalReducer","useLingui","primaryAuthMethods","email","emailVerified","primary","config","useConfig","products","useEffectiveAuthConfig","isLoading","flowState","type","AuthFlowType","Organization","organization","productComponentsOrdering","generateProductComponentsOrdering","mainScreenComponents","useProductComponents","SsoAndOAuthButtons","organizationName","organization_name","title","Discovery","PasswordReset","showVerifyEmailCopy","React","LoadingScreen","Column","gap","hideHeaderText","Typography","variant","align","map","key","buttons","component","index","Component","MainScreenComponent","Divider"],"mappings":";;;;;;;;;;;;;;AAeA,SAASA,cAAcC,KAA4B,EAAA;IACjD,OAAOA,KAAAA,CAAMC,KAAK,CAACC,kBAAAA,CAAAA;AACrB;MAEaC,UAAAA,GAAa,IAAA;IACxB,MAAM,EAAEC,OAAO,EAAE,GAAGC,eAAAA,EAAAA;IACpB,MAAM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