import { computed, inject, reactive, ref, useId, type ComputedRef, type InjectionKey, type Ref, } from "vue"; import type { AlertDialogVariants } from "@heroui-vue/styles"; import type { OverlayState } from "../../composables/useOverlayState"; export type AlertDialogPlacement = "auto" | "top" | "center" | "bottom"; export type AlertDialogStatus = "default" | "accent" | "success" | "warning" | "danger"; export interface AlertDialogContext { state: OverlayState; contentId: Ref; defaultId: string; titles: Map; placement: ComputedRef; size: ComputedRef; /** Backdrop variant; defaults to opaque. */ variant: ComputedRef; dismissable: ComputedRef; keyboardDisabled: ComputedRef; } export const alertDialogKey: InjectionKey = Symbol("hv-alert-dialog"); export function useAlertDialog(required = true) { const ctx = inject(alertDialogKey, undefined); if (!ctx && required) { throw new Error( "AlertDialog parts require AlertDialog or AlertDialogBackdrop.", ); } return ctx!; } export function createAlertDialogContext( state: OverlayState, ): AlertDialogContext { const id = "hv-alert-dialog-" + useId(); return { state, contentId: ref(id), defaultId: id, titles: reactive(new Map()), // Alert dialogs require explicit action by default. placement: computed(() => "auto"), size: computed(() => "md"), variant: computed(() => "opaque"), dismissable: computed(() => false), keyboardDisabled: computed(() => true), }; }