"use client"; import { AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@ui/components/alert-dialog"; import { Button } from "@ui/components/button"; import { useTranslations } from "next-intl"; import { type PropsWithChildren, createContext, useContext, useState, } from "react"; type ConfirmOptions = { title: string; message?: string; cancelLabel?: string; confirmLabel?: string; destructive?: boolean; onConfirm: () => Promise | void; }; const ConfirmationAlertContext = createContext<{ confirm: (options: ConfirmOptions) => void; }>({ confirm: async () => false, }); export function ConfirmationAlertProvider({ children }: PropsWithChildren) { const t = useTranslations(); const [confirmOptions, setConfirmOptions] = useState( null, ); const confirm = (options: ConfirmOptions) => { setConfirmOptions(options); }; return ( {children} setConfirmOptions(open ? confirmOptions : null) } > {confirmOptions?.title} {confirmOptions?.message} {confirmOptions?.cancelLabel ?? t("common.confirmation.cancel")} ); } export const useConfirmationAlert = () => { const context = useContext(ConfirmationAlertContext); if (!context) { throw new Error( "useConfirmationAlert must be used within a ConfirmationAlertProvider", ); } return context; };