{"version":3,"sources":["../src/hooks/popover/use-popover.tsx"],"names":["useState","usePopover","elementRef","hoverRef","spacing","isVisible","setIsVisible","popoverPosition","setPopoverPosition","event","height","rect","scrollY","scrollX","innerHeight","popoverTop","popoverLeft","popoverBottom","popoverHeight","adjustedTop"],"mappings":"4IAAA,OAAS,YAAAA,MAAgB,QA+ClB,IAAMC,EAAa,CACxBC,EACAC,EACAC,EAAU,IACP,CACH,GAAM,CAACC,EAAWC,CAAY,EAAIN,EAAS,EAAK,EAC1C,CAACO,EAAiBC,CAAkB,EAAIR,EAAmB,CAC/D,IAAK,EACL,KAAM,CACR,CAAC,EAsCD,MAAO,CACL,UAAAK,EACA,gBAAAE,EACA,mBAtCAE,GACG,CACHA,GAAO,gBAAgB,EACvB,IAAMC,EAASR,EAAW,SAAS,cAAgB,GACnD,GAAIA,EAAW,QAAS,CACtB,IAAMS,EAAOT,EAAW,QAAQ,sBAAsB,EAChD,CAAE,QAAAU,EAAS,QAAAC,EAAS,YAAAC,CAAY,EAAI,OAEpCC,EAAaJ,EAAK,OAASC,EAAUR,EACrCY,EAAcL,EAAK,KAAOE,EAC1BI,EAAgBF,EAAaL,EAC7BQ,EAAgBf,EAAS,SAAS,cAAgBO,EAElDS,EACJF,EAAgBL,EAAUE,EACtB,KAAK,IACHF,EAAUE,EAAcI,EAAgBR,EAASN,EACjDQ,CACF,EACAF,EACAN,EACAW,EAENP,EAAmB,CACjB,IAAKW,EACL,KAAMH,CACR,CAAC,EACDV,EAAa,EAAI,CACnB,CACF,EAUE,mBARyB,IAAM,CAC/BA,EAAa,EAAK,CACpB,CAOA,CACF","sourcesContent":["import { useState } from 'react'\n\ntype Position = {\n  /**\n   * @description This is the top position of the popover.\n   * @default 0\n   */\n  top: number\n  /**\n   * @description This is the left position of the popover.\n   * @default 0\n   */\n  left: number\n}\n\n/**\n * @deprecated This hook is deprecated and will be removed in v3.0.0.\n * Use the native Popover component instead, which provides better accessibility,\n * automatic layer management, and platform-native behavior.\n *\n * @see {@link ../components/popover/popover.tsx} New Popover Component\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/popover} HTML Popover API\n *\n * @description Legacy hook for custom popover positioning with pointer events.\n * Manually calculates popover position and handles show/hide logic.\n *\n * @param elementRef - Ref of the trigger element\n * @param hoverRef - Ref of the popover element\n * @param spacing - Spacing between trigger and popover (in pixels)\n *\n * @example\n * ```tsx\n * // ❌ Old approach (deprecated)\n * const { isVisible, popoverPosition, handlePointerEvent, handlePointerLeave } =\n *   usePopover(hoverRef, popOverRef, 1);\n *\n * // ✅ New approach (recommended)\n * import { Popover } from '@fpkit/acss';\n * <Popover id=\"my-popover\" triggerLabel=\"Open\">Content</Popover>\n * ```\n *\n * @returns Hook state and handlers\n * @returns isVisible - Boolean indicating popover visibility\n * @returns popoverPosition - Position object with top/left coordinates\n * @returns handlePointerEvent - Function to show popover on pointer enter\n * @returns handlePointerLeave - Function to hide popover on pointer leave\n */\nexport const usePopover = (\n  elementRef: React.RefObject<HTMLElement | HTMLDivElement>,\n  hoverRef: React.RefObject<HTMLElement | HTMLDivElement>,\n  spacing = 1,\n) => {\n  const [isVisible, setIsVisible] = useState(false)\n  const [popoverPosition, setPopoverPosition] = useState<Position>({\n    top: 0,\n    left: 0,\n  })\n\n  const handlePointerEvent = (\n    event: React.MouseEvent<HTMLButtonElement | HTMLElement>,\n  ) => {\n    event?.stopPropagation()\n    const height = elementRef.current?.offsetHeight || 40\n    if (elementRef.current) {\n      const rect = elementRef.current.getBoundingClientRect()\n      const { scrollY, scrollX, innerHeight } = window\n\n      const popoverTop = rect.bottom + scrollY + spacing\n      const popoverLeft = rect.left + scrollX\n      const popoverBottom = popoverTop + height // Adjust the popover height as needed\n      const popoverHeight = hoverRef.current?.offsetHeight ?? height // Adjust the popover height as needed\n\n      const adjustedTop =\n        popoverBottom > scrollY + innerHeight\n          ? Math.max(\n              scrollY + innerHeight - popoverHeight - height - spacing,\n              scrollY,\n            ) -\n            height -\n            spacing\n          : popoverTop\n\n      setPopoverPosition({\n        top: adjustedTop,\n        left: popoverLeft,\n      })\n      setIsVisible(true)\n    }\n  }\n\n  const handlePointerLeave = () => {\n    setIsVisible(false)\n  }\n\n  return {\n    isVisible,\n    popoverPosition,\n    handlePointerEvent,\n    handlePointerLeave,\n  }\n}\n\nexport default usePopover\n"]}