{"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 { stringifyDataAttribute } 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>,\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  const state: PopoverSurfaceState = {\n    withArrow,\n    arrowRef,\n    components: { root: 'dialog' },\n    root: slot.always(\n      {\n        ref: useMergedRefs(ref, contentRef, positioningCtx.containerRef) as React.Ref<HTMLDialogElement>,\n        role: trapFocus ? 'dialog' : 'group',\n        ...props,\n        id: surfaceId,\n        popover: trapFocus ? undefined : 'auto',\n        'data-popover-surface': '',\n        'data-open': stringifyDataAttribute(open),\n      },\n      { elementType: 'dialog' },\n    ),\n    'data-open': open ? 'true' : 'false',\n  };\n\n  const { onMouseEnter: onMouseEnterOriginal, onMouseLeave: onMouseLeaveOriginal } = state.root;\n\n  state.root.onMouseEnter = useEventCallback((e: React.MouseEvent<HTMLDialogElement>) => {\n    if (openOnHover) {\n      setOpen(e, true);\n    }\n    onMouseEnterOriginal?.(e);\n  });\n\n  state.root.onMouseLeave = useEventCallback((e: React.MouseEvent<HTMLDialogElement>) => {\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","state","components","root","slot","always","useMergedRefs","containerRef","role","id","popover","undefined","stringifyDataAttribute","elementType","onMouseEnter","onMouseEnterOriginal","onMouseLeave","onMouseLeaveOriginal","useEventCallback","e"],"mappings":"AAAA;;;;;+BAWaA;;;eAAAA;;;gCARyC;gCACpB;uBACK;AAMhC,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,QAAQS,SAAS;IAEhE,MAAMC,QAA6B;QACjCN;QACAD;QACAQ,YAAY;YAAEC,MAAM;QAAS;QAC7BA,MAAMC,oBAAI,CAACC,MAAM,CACf;YACEjB,KAAKkB,IAAAA,6BAAa,EAAClB,KAAKC,YAAYQ,eAAeU,YAAY;YAC/DC,MAAMR,YAAY,WAAW;YAC7B,GAAGb,KAAK;YACRsB,IAAIV;YACJW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