'use client'; import React, { useEffect, useRef, useState } from 'react'; interface NameDialogProps { open: boolean; title: string; initial: string; confirmText: string; onConfirm: (name: string) => void | Promise; onCancel: () => void; } // Malé okno na zadanie názvu (premenovanie, duplikovanie newslettera). // Pri každom otvorení sa obsah pripojí nanovo, takže začína s predvyplneným názvom. export const NameDialog: React.FC = ({ open, ...props }) => (open ? : null); const NameDialogBody: React.FC> = ({ title, initial, confirmText, onConfirm, onCancel }) => { const [value, setValue] = useState(initial); const [busy, setBusy] = useState(false); const inputRef = useRef(null); // predvyplnený názov označíme, aby sa dal hneď prepísať alebo len doplniť useEffect(() => { const t = setTimeout(() => inputRef.current?.select(), 30); return () => clearTimeout(t); }, []); const submit = async () => { const name = value.trim(); if (!name || busy) return; setBusy(true); try { await onConfirm(name); } finally { setBusy(false); } }; return (
e.stopPropagation()}>

{title}

setValue(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') submit(); if (e.key === 'Escape') onCancel(); }} placeholder="Názov newslettera" className="w-full text-sm border border-gray-300 rounded-xl px-3 py-2 outline-none focus:border-red-500 focus:ring-2 focus:ring-red-500/15" />
); };