import { useEffect, useRef } from 'react' export default function ConfirmDialog({ open, title, message, confirmText = 'Подтвердить', cancelText = 'Отмена', onConfirm, onCancel, destructive = false, size = 'md' }) { const ref = useRef(null) useEffect(() => { if (open && ref.current) { try { ref.current.querySelector('button[data-primary]')?.focus() } catch {} } }, [open]) if (!open) return null return (
{ if (e.key === 'Escape') onCancel?.() }}>
{ if (e.key === 'Tab') { const focusable = ref.current?.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])') if (!focusable || focusable.length === 0) return const first = focusable[0] const last = focusable[focusable.length - 1] if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); } else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); } } }}>
{title || 'Подтверждение'}

{message}

) }