"use client" import React, { useState, useEffect } from "react" import { createPortal } from "react-dom" import { cn } from "@/lib/utils" interface CustomAlertDialogProps { title: string description: string cancelText?: string confirmText?: string onCancel?: () => void onConfirm?: () => void variant?: "default" | "destructive" } export function CustomAlertDialogTrigger({ children, dialogProps, }: { children: React.ReactNode dialogProps: CustomAlertDialogProps }) { const [isOpen, setIsOpen] = useState(false) const openDialog = () => setIsOpen(true) const closeDialog = () => setIsOpen(false) const handleCancel = () => { dialogProps.onCancel?.() closeDialog() } const handleConfirm = () => { dialogProps.onConfirm?.() closeDialog() } return ( <> {React.cloneElement(children as React.ReactElement, { onClick: openDialog })} {isOpen && ( )} ) } function CustomAlertDialog({ title, description, cancelText = "Cancel", confirmText = "Confirm", onCancel, onConfirm, variant = "default", isOpen, }: CustomAlertDialogProps & { isOpen: boolean }) { const [mounted, setMounted] = useState(false) useEffect(() => { setMounted(true) return () => setMounted(false) }, []) useEffect(() => { if (isOpen) { document.body.style.overflow = "hidden" } else { document.body.style.overflow = "" } return () => { document.body.style.overflow = "" } }, [isOpen]) const handleBackdropClick = (e: React.MouseEvent) => { if (e.target === e.currentTarget) { onCancel?.() } } const dialogContent = (
e.stopPropagation()} >

{title}

{description}

) if (!mounted) return null return createPortal(dialogContent, document.body) }