{"version":3,"sources":["../src/components/Popover/PopoverSurface/usePopoverSurface.ts"],"sourcesContent":["'use client';\n\nimport type * as React from 'react';\nimport { useMergedRefs, slot, useEventCallback } from '@fluentui/react-utilities';\nimport { usePopoverContext } from '../popoverContext';\nimport { toDataAttributeValue } from '../../../utils';\nimport type { PopoverSurfaceProps, PopoverSurfaceState } from './PopoverSurface.types';\n\n/**\n * Returns the state for a PopoverSurface component.\n */\nexport const usePopoverSurface = (\n  props: PopoverSurfaceProps,\n  ref: React.Ref<HTMLDialogElement | HTMLDivElement>,\n): PopoverSurfaceState => {\n  const contentRef = usePopoverContext(context => context.contentRef);\n  const openOnHover = usePopoverContext(context => context.openOnHover);\n  const setOpen = usePopoverContext(context => context.setOpen);\n  const arrowRef = usePopoverContext(context => context.arrowRef);\n  const withArrow = usePopoverContext(context => context.withArrow);\n  const open = usePopoverContext(context => context.open);\n  const positioningCtx = usePopoverContext(context => context.positioning);\n  const surfaceId = usePopoverContext(context => context.surfaceId);\n  const trapFocus = usePopoverContext(context => context.trapFocus);\n\n  if (process.env.NODE_ENV !== 'production' && trapFocus && props.as === 'div') {\n    // eslint-disable-next-line no-console\n    console.warn(\n      '@fluentui/react-headless-components-preview [PopoverSurface]: ' +\n        '`as=\"div\"` is incompatible with `Popover trapFocus`. ' +\n        'Use the default `dialog` element when focus trapping is enabled.',\n    );\n  }\n\n  const state: PopoverSurfaceState = {\n    withArrow,\n    arrowRef,\n    components: { root: 'dialog' },\n    root: slot.always(\n      {\n        ref: useMergedRefs(ref, contentRef, positioningCtx.containerRef),\n        role: trapFocus ? 'dialog' : 'group',\n        ...props,\n        id: surfaceId,\n        'data-popover-surface': '',\n        'data-open': toDataAttributeValue(open),\n      },\n      {\n        defaultProps: {\n          popover: trapFocus ? undefined : 'auto',\n        },\n        elementType: 'dialog',\n      },\n    ) as PopoverSurfaceState['root'],\n  };\n\n  const { onMouseEnter: onMouseEnterOriginal, onMouseLeave: onMouseLeaveOriginal } = state.root;\n\n  state.root.onMouseEnter = useEventCallback((e: React.MouseEvent<HTMLDialogElement & HTMLDivElement>) => {\n    if (openOnHover) {\n      setOpen(e, true);\n    }\n    onMouseEnterOriginal?.(e);\n  });\n\n  state.root.onMouseLeave = useEventCallback((e: React.MouseEvent<HTMLDialogElement & HTMLDivElement>) => {\n    if (openOnHover) {\n      setOpen(e, false);\n    }\n    onMouseLeaveOriginal?.(e);\n  });\n\n  return state;\n};\n"],"names":["usePopoverSurface","props","ref","contentRef","usePopoverContext","context","openOnHover","setOpen","arrowRef","withArrow","open","positioningCtx","positioning","surfaceId","trapFocus","process","env","NODE_ENV","as","console","warn","state","components","root","slot","always","useMergedRefs","containerRef","role","id","toDataAttributeValue","defaultProps","popover","undefined","elementType","onMouseEnter","onMouseEnterOriginal","onMouseLeave","onMouseLeaveOriginal","useEventCallback","e"],"mappings":"AAAA;;;;;+BAWaA;;;eAAAA;;;gCARyC;gCACpB;uBACG;AAM9B,MAAMA,oBAAoB,CAC/BC,OACAC;IAEA,MAAMC,aAAaC,IAAAA,iCAAiB,EAACC,CAAAA,UAAWA,QAAQF,UAAU;IAClE,MAAMG,cAAcF,IAAAA,iCAAiB,EAACC,CAAAA,UAAWA,QAAQC,WAAW;IACpE,MAAMC,UAAUH,IAAAA,iCAAiB,EAACC,CAAAA,UAAWA,QAAQE,OAAO;IAC5D,MAAMC,WAAWJ,IAAAA,iCAAiB,EAACC,CAAAA,UAAWA,QAAQG,QAAQ;IAC9D,MAAMC,YAAYL,IAAAA,iCAAiB,EAACC,CAAAA,UAAWA,QAAQI,SAAS;IAChE,MAAMC,OAAON,IAAAA,iCAAiB,EAACC,CAAAA,UAAWA,QAAQK,IAAI;IACtD,MAAMC,iBAAiBP,IAAAA,iCAAiB,EAACC,CAAAA,UAAWA,QAAQO,WAAW;IACvE,MAAMC,YAAYT,IAAAA,iCAAiB,EAACC,CAAAA,UAAWA,QAAQQ,SAAS;IAChE,MAAMC,YAAYV,IAAAA,iCAAiB,EAACC,CAAAA,UAAWA,Q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