import { inject, reactive, ref, shallowRef, useId, type InjectionKey, type Ref, } from "vue"; import type { OverlayState } from "../../composables/useOverlayState"; export interface PopoverContext { state: OverlayState; contentId: Ref; triggerId: string; contentNonModal: Ref; titles: Map; dialogAttrs: Ref>; } export const popoverKey: InjectionKey = Symbol("hv-popover"); export function usePopover() { const ctx = inject(popoverKey); if (!ctx) throw new Error("Popover parts require Popover."); return ctx; } export function createPopoverContext(state: OverlayState): PopoverContext { const id = "hv-popover-" + useId(); return { state, contentId: ref(id + "-content"), triggerId: id + "-trigger", contentNonModal: ref(undefined), titles: reactive(new Map()), dialogAttrs: shallowRef({}), }; }