{"version":3,"file":"Dialog.cjs","names":["_Button","require","_styles","_react","_Button2","_createOdysseyStyledComponent","_FullScreenOverlay","_i18n","_index","_useMediaQuery","_useStackedBackdropProps","_useUniqueId","_jsxRuntime","_interopRequireDefault","e","__esModule","default","DialogTitleContainer","createOdysseyStyledComponent","tag","odysseyDesignTokens","display","justifyContent","alignItems","marginBlockEnd","padding","paddingBlockStart","Spacing5","paddingBlockEnd","Spacing4","paddingInline","Spacing6","fontFamily","TypographyFamilyHeading","buttonClasses","root","alignSelf","marginInlineEnd","Spacing3","flexShrink","Dialog","primaryCallToActionComponent","secondaryCallToActionComponent","tertiaryCallToActionComponent","callToActionFirstComponent","callToActionSecondComponent","callToActionLastComponent","children","isOpen","onClose","testId","title","translate","variant","t","useTranslation","isContentScrollable","setIsContentScrollable","useState","dialogContentRef","useRef","dialogLabelId","useUniqueId","useEffect","frameId","handleContentScroll","dialogContentElement","current","cancelAnimationFrame","scrollHeight","clientHeight","requestAnimationFrame","content","jsx","_DialogContentText2","actionButtons","filter","Boolean","handleCloseButtonClick","useCallback","event","muiTheme","useTheme","stackedBackdropProps","useStackedBackdropProps","layer","zIndex","modal","slotProps","useMemo","backdrop","isWithinCompactWidthOrHeight","useCompactViewportMatches","FullScreenOverlay","jsxs","_Dialog2","fullScreen","open","scroll","_DialogTitle2","id","Button","ariaLabel","onClick","size","startIcon","CloseIcon","_DialogContent2","tabIndex","dividers","ref","length","_DialogActions2","map","actionButton","index","cloneElement","key","MemoizedDialog","exports","memo","displayName"],"sources":["../../src/Dialog.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport {\n  Dialog as MuiDialog,\n  DialogActions as MuiDialogActions,\n  DialogContent as MuiDialogContent,\n  DialogContentText as MuiDialogContentText,\n  DialogProps as MuiDialogProps,\n  DialogTitle as MuiDialogTitle,\n} from \"@mui/material\";\nimport { buttonClasses } from \"@mui/material/Button\";\nimport { useTheme } from \"@mui/material/styles\";\nimport {\n  cloneElement,\n  memo,\n  ReactElement,\n  ReactNode,\n  useCallback,\n  useEffect,\n  useMemo,\n  useRef,\n  useState,\n} from \"react\";\n\nimport type { HtmlProps } from \"./HtmlProps.js\";\n\nimport { Button, ButtonProps } from \"./Buttons/Button.js\";\nimport { createOdysseyStyledComponent } from \"./createOdysseyStyledComponent.js\";\nimport { FullScreenOverlay } from \"./FullScreenOverlay.js\";\nimport { useTranslation } from \"./i18n.generated/i18n.js\";\nimport { CloseIcon } from \"./icons.generated/index.js\";\nimport { useCompactViewportMatches } from \"./theme/useMediaQuery.js\";\nimport { useStackedBackdropProps } from \"./useStackedBackdropProps.js\";\nimport { useUniqueId } from \"./useUniqueId.js\";\n\ntype MuiOnCloseEvent = Parameters<Required<MuiDialogProps>[\"onClose\"]>[0];\ntype MuiOnCloseReason = Parameters<Required<MuiDialogProps>[\"onClose\"]>[1];\nexport type DialogOnCloseReason = MuiOnCloseReason | \"closeButtonClick\";\n\nexport type DialogProps = {\n  /**\n   * @deprecated `aria-label` for close button comes from translation file\n   */\n  ariaLabel?: string;\n\n  /**\n   * @deprecated Will be removed in a future Odyssey version. Use `primaryCallToActionComponent` instead.\n   */\n  callToActionFirstComponent?: ReactElement<typeof Button>;\n  /**\n   * @deprecated Will be removed in a future Odyssey version. Use `tertiaryCallToActionComponent` instead.\n   */\n  callToActionLastComponent?: ReactElement<typeof Button>;\n  /**\n   * @deprecated Will be removed in a future Odyssey version. Use `secondaryCallToActionComponent` instead.\n   */\n  callToActionSecondComponent?: ReactElement<typeof Button>;\n  /**\n   * The content of the Dialog. May be a `string` or any other `ReactNode` or array of `ReactNode`s.\n   */\n  children: ReactNode;\n  /**\n   * If `true`, the dialog is visible.\n   */\n  isOpen: boolean;\n  /**\n   * Called when the dialog is dismissed. Receives the event and the reason for closing.\n   */\n  onClose: (event: MuiOnCloseEvent, reason: DialogOnCloseReason) => void;\n  /**\n   * An optional Button object to be situated in the Dialog footer as the primary call to action.\n   */\n  primaryCallToActionComponent?: ReactElement<typeof Button>;\n  /**\n   * An optional Button object to be situated in the Dialog footer as the secondary call to action, alongside the `primaryCallToActionComponent`.\n   */\n  secondaryCallToActionComponent?: ReactElement<typeof Button>;\n\n  /**\n   * An optional Button object to be situated in the Dialog footer as the tertiary call to action, alongside the other `callToAction` components.\n   */\n  tertiaryCallToActionComponent?: ReactElement<typeof Button>;\n\n  /**\n   * The title of the Dialog.\n   */\n  title: string;\n\n  /**\n   * Controls the opacity of the Dialog backdrop.\n   * - If `'default'`, semi-transparent backdrop.\n   * - If `'security'`, fully opaque backdrop, used for security-sensitive dialogs.\n   * @default \"default\"\n   */\n  variant?: \"default\" | \"security\";\n} & Pick<HtmlProps, \"testId\" | \"translate\">;\n\nconst DialogTitleContainer = createOdysseyStyledComponent({ tag: \"div\" })(\n  ({ odysseyDesignTokens }) => ({\n    display: \"flex\",\n    justifyContent: \"space-between\",\n    alignItems: \"center\",\n    marginBlockEnd: 0,\n    padding: 0,\n    paddingBlockStart: odysseyDesignTokens.Spacing5,\n    paddingBlockEnd: odysseyDesignTokens.Spacing4,\n    paddingInline: odysseyDesignTokens.Spacing6,\n    fontFamily: odysseyDesignTokens.TypographyFamilyHeading,\n\n    [`& > .${buttonClasses.root}`]: {\n      alignSelf: \"baseline\",\n      // Pull close button by inline padding amount\n      marginInlineEnd: `-${odysseyDesignTokens.Spacing3}`,\n      flexShrink: 0,\n    },\n  }),\n);\n\n/**\n * A modal overlay that interrupts the user to present critical information, collect input, or require confirmation before proceeding.\n */\nconst Dialog = ({\n  primaryCallToActionComponent,\n  secondaryCallToActionComponent,\n  tertiaryCallToActionComponent,\n  callToActionFirstComponent,\n  callToActionSecondComponent,\n  callToActionLastComponent,\n  children,\n  isOpen,\n  onClose,\n  testId,\n  title,\n  translate,\n  variant = \"default\",\n}: DialogProps) => {\n  const { t } = useTranslation();\n\n  const [isContentScrollable, setIsContentScrollable] = useState(false);\n  const dialogContentRef = useRef<HTMLDivElement>(null);\n  const dialogLabelId = useUniqueId();\n\n  useEffect(() => {\n    let frameId: number;\n\n    const handleContentScroll = () => {\n      const dialogContentElement = dialogContentRef.current;\n      if (dialogContentElement) {\n        cancelAnimationFrame(frameId);\n        setIsContentScrollable(\n          dialogContentElement.scrollHeight > dialogContentElement.clientHeight,\n        );\n      }\n      frameId = requestAnimationFrame(handleContentScroll);\n    };\n\n    if (isOpen) {\n      frameId = requestAnimationFrame(handleContentScroll);\n    }\n\n    return () => {\n      cancelAnimationFrame(frameId);\n    };\n  }, [isOpen]);\n\n  const content =\n    typeof children === \"string\" ? (\n      <MuiDialogContentText>{children}</MuiDialogContentText>\n    ) : (\n      children\n    );\n\n  // Prioritize new action button format (|| used as a fallback)\n  const actionButtons = [\n    tertiaryCallToActionComponent || callToActionLastComponent,\n    secondaryCallToActionComponent || callToActionSecondComponent,\n    primaryCallToActionComponent || callToActionFirstComponent,\n  ].filter(Boolean);\n\n  const handleCloseButtonClick = useCallback<\n    NonNullable<ButtonProps[\"onClick\"]>\n  >((event) => onClose(event, \"closeButtonClick\"), [onClose]);\n\n  const muiTheme = useTheme();\n\n  const stackedBackdropProps = useStackedBackdropProps({\n    isOpen,\n    layer: muiTheme.zIndex.modal,\n  });\n\n  const slotProps = useMemo<MuiDialogProps[\"slotProps\"]>(\n    () => ({\n      backdrop: { ...stackedBackdropProps, variant: variant },\n    }),\n    [stackedBackdropProps, variant],\n  );\n\n  const { isWithinCompactWidthOrHeight } = useCompactViewportMatches();\n\n  return (\n    <FullScreenOverlay>\n      <MuiDialog\n        aria-labelledby={dialogLabelId}\n        data-se={testId}\n        fullScreen={isWithinCompactWidthOrHeight}\n        onClose={onClose}\n        open={isOpen}\n        scroll={isWithinCompactWidthOrHeight ? \"body\" : \"paper\"}\n        slotProps={slotProps}\n      >\n        <DialogTitleContainer>\n          <MuiDialogTitle id={dialogLabelId} translate={translate}>\n            {title}\n          </MuiDialogTitle>\n          <Button\n            ariaLabel={t(\"close.text\")}\n            onClick={handleCloseButtonClick}\n            size=\"small\"\n            startIcon={<CloseIcon />}\n            variant=\"floating\"\n          />\n        </DialogTitleContainer>\n\n        <MuiDialogContent\n          {...(isContentScrollable && {\n            // Sets tabIndex on content element if scrollable so content is easier to navigate with the keyboard\n            tabIndex: 0,\n          })}\n          dividers={isContentScrollable}\n          ref={dialogContentRef}\n        >\n          {content}\n        </MuiDialogContent>\n\n        {actionButtons.length > 0 && (\n          <MuiDialogActions>\n            {actionButtons.map((actionButton, index) =>\n              actionButton ? cloneElement(actionButton, { key: index }) : null,\n            )}\n          </MuiDialogActions>\n        )}\n      </MuiDialog>\n    </FullScreenOverlay>\n  );\n};\n\nconst MemoizedDialog = memo(Dialog);\nMemoizedDialog.displayName = \"Dialog\";\n\nexport { MemoizedDialog as Dialog };\n"],"mappings":";;;;;;;;;;;AAoBA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAcA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,6BAAA,GAAAJ,OAAA;AACA,IAAAK,kBAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,cAAA,GAAAR,OAAA;AACA,IAAAS,wBAAA,GAAAT,OAAA;AACA,IAAAU,YAAA,GAAAV,OAAA;AAA+C,IAAAW,WAAA,GAAAX,OAAA;AAAA,SAAAY,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;A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