"use client"; import { useState, useEffect, useCallback } from "react"; import { createPortal } from "react-dom"; import { X, Instagram, Send, CheckCircle, Phone } from "lucide-react"; import { BRAND } from "@/lib/constants"; interface BookingModalProps { open: boolean; onClose: () => void; groupInfo?: string; contact?: { instagram: string; phone: string }; } const DEFAULT_CONTACT = { instagram: BRAND.instagram, phone: "+375 29 389-70-01", }; export function BookingModal({ open, onClose, groupInfo, contact: contactProp }: BookingModalProps) { const contact = contactProp ?? DEFAULT_CONTACT; const [name, setName] = useState(""); const [phone, setPhone] = useState("+375 "); // Format phone: +375 (XX) XXX-XX-XX function handlePhoneChange(raw: string) { // Strip everything except digits let digits = raw.replace(/\D/g, ""); // Ensure starts with 375 if (!digits.startsWith("375")) { digits = "375" + digits.replace(/^375?/, ""); } // Limit to 12 digits (375 + 9 digits) digits = digits.slice(0, 12); // Format let formatted = "+375"; const rest = digits.slice(3); if (rest.length > 0) formatted += " (" + rest.slice(0, 2); if (rest.length >= 2) formatted += ") "; if (rest.length > 2) formatted += rest.slice(2, 5); if (rest.length > 5) formatted += "-" + rest.slice(5, 7); if (rest.length > 7) formatted += "-" + rest.slice(7, 9); setPhone(formatted); } const [submitted, setSubmitted] = useState(false); // Close on Escape useEffect(() => { if (!open) return; function onKey(e: KeyboardEvent) { if (e.key === "Escape") onClose(); } document.addEventListener("keydown", onKey); return () => document.removeEventListener("keydown", onKey); }, [open, onClose]); // Lock body scroll useEffect(() => { if (open) { document.body.style.overflow = "hidden"; } else { document.body.style.overflow = ""; } return () => { document.body.style.overflow = ""; }; }, [open]); const handleSubmit = useCallback( (e: React.FormEvent) => { e.preventDefault(); // Build Instagram DM message with pre-filled text const groupText = groupInfo ? ` (${groupInfo})` : ""; const message = `Здравствуйте! Меня зовут ${name}, хочу записаться на занятие${groupText}. Мой телефон: ${phone}`; const instagramUrl = `https://ig.me/m/blackheartdancehouse?text=${encodeURIComponent(message)}`; window.open(instagramUrl, "_blank"); setSubmitted(true); }, [name, phone, groupInfo, contact] ); const handleClose = useCallback(() => { onClose(); // Reset after animation setTimeout(() => { setName(""); setPhone("+375 "); setSubmitted(false); }, 300); }, [onClose]); if (!open) return null; return createPortal(
{/* Backdrop */}
{/* Modal */}
e.stopPropagation()} > {/* Close button */} {submitted ? ( /* Success state */

Отлично!

Сообщение отправлено в Instagram. Мы свяжемся с вами в ближайшее время!

) : ( <> {/* Header */}

Записаться

Оставьте данные и мы свяжемся с вами, или напишите нам напрямую

{/* Form */}
setName(e.target.value)} placeholder="Ваше имя" required className="w-full rounded-xl border border-white/[0.08] bg-white/[0.04] px-4 py-3 text-sm text-white placeholder-neutral-500 outline-none transition-colors focus:border-gold/40 focus:bg-white/[0.06]" />
handlePhoneChange(e.target.value)} placeholder="+375 (__) ___-__-__" required className="w-full rounded-xl border border-white/[0.08] bg-white/[0.04] px-4 py-3 text-sm text-white placeholder-neutral-500 outline-none transition-colors focus:border-gold/40 focus:bg-white/[0.06]" />
{/* Divider */}
или напрямую
{/* Direct links */}
Instagram Позвонить
)}
, document.body ); }