{"version":3,"file":"IDPConsentManifest.mjs","sources":["../../../../../../../../../web/src/ui/components/organisms/IDPConsentManifest.tsx"],"sourcesContent":["import { useLingui } from '@lingui/react/macro';\nimport { IDPConsentItem, IDPConsentScreenManifest, IDPConsentSection } from '@stytch/core/public';\nimport classNames from 'classnames';\nimport React, { MouseEvent } from 'react';\n\nimport { Chevron } from '../../../assets';\nimport { getTransitionDuration } from '../atoms/animation';\nimport Column from '../atoms/Column';\nimport Typography from '../atoms/Typography';\nimport styles from './IDPConsentManifest.module.css';\n\nconst Item = ({ item, as = 'li' }: { item: IDPConsentItem; as?: 'li' | 'div' }) => {\n  if (typeof item === 'string') {\n    item = { text: item };\n  }\n\n  const summary = <Typography variant=\"helper\">{item.text}</Typography>;\n  const Element = as;\n\n  if (!item.details?.length) {\n    return <Element className={classNames(styles.summaryNoDetail, styles.borderBetween)}>{summary}</Element>;\n  }\n\n  return (\n    <Element className={styles.borderBetween}>\n      <details className={styles.details}>\n        <summary onClick={animateToggleDetail}>\n          {summary}\n          <Chevron className={styles.chevron} role=\"presentation\" />\n        </summary>\n\n        <ul className={styles.nestedList}>\n          {item.details?.map((details) => (\n            <Typography as=\"li\" variant=\"helper\" key={details}>\n              {details}\n            </Typography>\n          ))}\n        </ul>\n      </details>\n    </Element>\n  );\n};\n\nconst Section = ({ section }: { section: IDPConsentSection }) => (\n  <Column gap={2}>\n    <Typography weight=\"medium\">{section.header}</Typography>\n\n    <ul className={styles.outerList}>\n      {section.items.map((item: IDPConsentItem, i) => (\n        <Item key={i} item={item} />\n      ))}\n    </ul>\n  </Column>\n);\n\nexport const ConsentManifest = ({\n  manifest,\n  clientName,\n}: {\n  manifest: IDPConsentScreenManifest;\n  clientName: string;\n}) => {\n  const { t } = useLingui();\n  const sections =\n    typeof manifest[0] === 'object' && 'header' in manifest[0]\n      ? (manifest as IDPConsentSection[])\n      : [\n          {\n            header: t({\n              id: 'idpConsent.allowClientTo',\n              message: `Allow ${clientName} to:`,\n            }),\n            items: manifest as IDPConsentItem[],\n          },\n        ];\n\n  return (\n    <div className={styles.manifest}>\n      {sections.map((item, i) => (\n        <Section key={i} section={item} />\n      ))}\n    </div>\n  );\n};\n\nexport const UngrantableScopes = ({\n  clientName,\n  ungrantableScopeDescriptions,\n}: {\n  clientName: string;\n  ungrantableScopeDescriptions: string[];\n}) => {\n  const { t } = useLingui();\n  if (!ungrantableScopeDescriptions.length) return null;\n\n  // Map it to a consent item so we can reuse <Item>\n  const item: IDPConsentItem = {\n    text: t({\n      id: 'idpConsent.noPermissionsToGrant',\n      message: `You do not have permissions to grant ${clientName} access to some of the requested scopes.`,\n    }),\n    details: ungrantableScopeDescriptions,\n  };\n\n  return (\n    <div className={styles.ungrantable}>\n      <Item item={item} as=\"div\" />\n    </div>\n  );\n};\n\nfunction animateToggleDetail(evt: MouseEvent<HTMLElement>) {\n  const parent = evt.currentTarget.parentElement;\n  if (parent?.tagName !== 'DETAILS') return;\n  const detail = parent as HTMLDetailsElement;\n  evt.preventDefault();\n\n  const wasOpen = detail.open;\n  const summaryHeight = evt.currentTarget.clientHeight + 'px';\n  const detailStyles = getComputedStyle(detail);\n  const closedHeight = `calc(${summaryHeight} + ${detailStyles.paddingTop} + ${detailStyles.paddingBottom})`;\n  const animationOptions = {\n    duration: getTransitionDuration(evt.currentTarget),\n    easing: 'ease-in-out',\n  };\n\n  if (wasOpen) {\n    const detailHeight = detail.clientHeight + 'px';\n    const animation = detail.animate([{ height: detailHeight }, { height: closedHeight }], animationOptions);\n\n    // Need to delay open being changed, otherwise the content will disappear immediately\n    // while the animation is still running\n    animation.finished.then(() => {\n      detail.open = false;\n    });\n  } else {\n    detail.open = true;\n    requestAnimationFrame(() => {\n      const detailHeight = detail.clientHeight + 'px';\n      detail.animate([{ height: closedHeight }, { height: detailHeight }], animationOptions);\n    });\n  }\n}\n"],"names":["Item","item","as","text","summary","React","Typography","variant","Element","details","length","className","classNames","styles","summaryNoDetail","borderBetween","onClick","animateToggleDetail","Chevron","chevron","role","ul","nestedList","map","key","Section","section","Column","gap","weight","header","outerList","items","i","ConsentManifest","manifest","clientName","useLingui","sections","div","UngrantableScopes","ungrantableScopeDescriptions","ungrantable","evt","parent","currentTarget","parentElement","tagName","detail","preventDefault","wasOpen","open","summaryHeight","clientHeight","detailStyles","getComputedStyle","closedHeight","paddingTop","paddingBottom","animationOptions","duration","getTransitionDuration","easing","detailHeight","animation","animate","height","finished","then","requestAnimationFrame"],"mappings":";;;;;;;;;AAWA,MAAMA,OAAO,CAAC,EAAEC,IAAI,EAAEC,EAAAA,GAAK,IAAI,EAA+C,GAAA;IAC5E,IAAI,OAAOD,SAAS,QAAA,EAAU;QAC5BA,IAAAA,GAAO;YAAEE,IAAAA,EAAMF;AAAK,SAAA;AACtB,IAAA;AAEA,IAAA,MAAMG,wBAAUC,EAAA,CAAA,aAAA,CAACC,UAAAA,EAAAA;QAAWC,OAAAA,EAAQ;AAAUN,KAAAA,EAAAA,IAAAA,CAAKE,IAAI,CAAA;AACvD,IAAA,MAAMK,OAAAA,GAAUN,EAAAA;AAEhB,IAAA,IAAI,CAACD,IAAAA,CAAKQ,OAAO,EAAEC,MAAAA,EAAQ;AACzB,QAAA,qBAAOL,EAAA,CAAA,aAAA,CAACG,OAAAA,EAAAA;AAAQG,YAAAA,SAAAA,EAAWC,UAAAA,CAAWC,gBAAAA,CAAOC,eAAe,EAAED,iBAAOE,aAAa;AAAIX,SAAAA,EAAAA,OAAAA,CAAAA;AACxF,IAAA;AAEA,IAAA,qBACEC,EAAA,CAAA,aAAA,CAACG,OAAAA,EAAAA;AAAQG,QAAAA,SAAAA,EAAWE,iBAAOE;qBACzBV,EAAA,CAAA,aAAA,CAACI,SAAAA,EAAAA;AAAQE,QAAAA,SAAAA,EAAWE,iBAAOJ;qBACzBJ,EAAA,CAAA,aAAA,CAACD,SAAAA,EAAAA;QAAQY,OAAAA,EAASC;AACfb,KAAAA,EAAAA,OAAAA,gBACDC,EAAA,CAAA,aAAA,CAACa,OAAAA,EAAAA;AA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