"use client"; import React, { useState, useEffect, useMemo, useRef } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { X, Copy, Check, Activity, Download } from "lucide-react"; import { ThreeTicketCard } from "./ThreeTicketCard"; import { useLanguage } from "@/components/LanguageContext"; const SITE_URL = ( process.env.NEXT_PUBLIC_SITE_URL ?? "https://darkslategrey-nightingale-132659.hostingersite.com" ).replace(/\/$/, ""); interface CyberTicketModalProps { isOpen: boolean; onClose: () => void; email: string; } export function CyberTicketModal({ isOpen, onClose, email, }: CyberTicketModalProps) { const { t, language } = useLanguage(); const [copied, setCopied] = useState(false); const modalRef = useRef(null); // Card tilt states for the 3D Holographic effect const [rotateX, setRotateX] = useState(0); const [rotateY, setRotateY] = useState(0); const [glareX, setGlareX] = useState(50); const [glareY, setGlareY] = useState(50); // Generate a reproducible/stable ticket number purely based on email const ticketNumber = useMemo(() => { if (!email) return ""; let hash = 0; for (let i = 0; i < email.length; i++) { hash = email.charCodeAt(i) + ((hash << 5) - hash); } const number = Math.abs(hash % 90000) + 10000; // Generate a 5-digit number return `00${number}`.slice(-6).replace(/\B(?=(\d{3})+(?!\d))/g, ","); }, [email]); useEffect(() => { if (isOpen) { // Simple futuristic terminal beep on render try { const audioCtx = new ( window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }) .webkitAudioContext )(); // Beep 1 const osc1 = audioCtx.createOscillator(); const gain1 = audioCtx.createGain(); osc1.type = "sine"; osc1.frequency.setValueAtTime(880, audioCtx.currentTime); // A5 note gain1.gain.setValueAtTime(0.04, audioCtx.currentTime); gain1.gain.exponentialRampToValueAtTime( 0.0001, audioCtx.currentTime + 0.15, ); osc1.connect(gain1); gain1.connect(audioCtx.destination); osc1.start(); osc1.stop(audioCtx.currentTime + 0.15); // Beep 2 (quick delay) setTimeout(() => { const osc2 = audioCtx.createOscillator(); const gain2 = audioCtx.createGain(); osc2.type = "sine"; osc2.frequency.setValueAtTime(1320, audioCtx.currentTime); // E6 note gain2.gain.setValueAtTime(0.03, audioCtx.currentTime); gain2.gain.exponentialRampToValueAtTime( 0.0001, audioCtx.currentTime + 0.25, ); osc2.connect(gain2); gain2.connect(audioCtx.destination); osc2.start(); osc2.stop(audioCtx.currentTime + 0.25); }, 80); } catch { // AudioContext blocked or not supported } } }, [isOpen, email]); // Gyroscope mobile support (Device Orientation) useEffect(() => { if (!isOpen) return; const handleOrientation = (e: DeviceOrientationEvent) => { // beta: front-back tilt (-180 to 180) // gamma: left-right tilt (-90 to 90) if (e.beta === null || e.gamma === null) return; // Restrict angles for moderate tilt effect (up to 20 degrees) const beta = Math.min(Math.max(e.beta, -30), 30); const gamma = Math.min(Math.max(e.gamma, -30), 30); // Map degrees to card transform values setRotateX((beta / 30) * -15); setRotateY((gamma / 30) * 15); setGlareX(50 + (gamma / 30) * 50); setGlareY(50 + (beta / 30) * 50); }; window.addEventListener("deviceorientation", handleOrientation); return () => { window.removeEventListener("deviceorientation", handleOrientation); }; }, [isOpen]); // Focus trap and escape key listener useEffect(() => { if (!isOpen) return; const modal = modalRef.current; if (!modal) return; // Find focusable elements const focusableElements = modal.querySelectorAll( 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])', ); const firstElement = focusableElements[0] as HTMLElement; const lastElement = focusableElements[ focusableElements.length - 1 ] as HTMLElement; // Save previous active element to restore later const previousActiveElement = document.activeElement as HTMLElement; // Set a tiny timeout to ensure animation didn't disrupt focus const focusTimeout = setTimeout(() => { if (firstElement) { firstElement.focus(); } else { modal.focus(); } }, 50); const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") { onClose(); } if (e.key !== "Tab") return; if (e.shiftKey) { if (document.activeElement === firstElement) { lastElement.focus(); e.preventDefault(); } } else { if (document.activeElement === lastElement) { firstElement.focus(); e.preventDefault(); } } }; window.addEventListener("keydown", handleKeyDown); return () => { clearTimeout(focusTimeout); window.removeEventListener("keydown", handleKeyDown); if (previousActiveElement) { previousActiveElement.focus(); } }; }, [isOpen, onClose]); const exportTicketAsImage = () => { const canvas = document.createElement("canvas"); canvas.width = 800; canvas.height = 500; const ctx = canvas.getContext("2d"); if (!ctx) return; // 1. Draw Background Gradient const bgGrad = ctx.createLinearGradient(0, 0, 800, 500); bgGrad.addColorStop(0, "#09090b"); bgGrad.addColorStop(0.5, "#020202"); bgGrad.addColorStop(1, "#0f0f13"); ctx.fillStyle = bgGrad; ctx.fillRect(0, 0, 800, 500); // 2. Draw Subtle Cyber Grid Pattern ctx.strokeStyle = "rgba(255, 255, 255, 0.03)"; ctx.lineWidth = 1; const gridSpacing = 20; for (let x = 0; x < 800; x += gridSpacing) { ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, 500); ctx.stroke(); } for (let y = 0; y < 500; y += gridSpacing) { ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(800, y); ctx.stroke(); } // 3. Draw Ambient Glowing Edges (Top-Right and Bottom-Left) // Diagonal top-right orange glow const trGrad = ctx.createLinearGradient(600, 0, 800, 0); trGrad.addColorStop(0, "rgba(245, 158, 11, 0)"); trGrad.addColorStop(1, "rgba(245, 158, 11, 0.4)"); ctx.fillStyle = trGrad; ctx.fillRect(550, 0, 250, 10); // Diagonal bottom-left indigo glow const blGrad = ctx.createLinearGradient(0, 500, 200, 500); blGrad.addColorStop(0, "rgba(99, 102, 241, 0.4)"); blGrad.addColorStop(1, "rgba(99, 102, 241, 0)"); ctx.fillStyle = blGrad; ctx.fillRect(0, 490, 250, 10); // 4. Draw outer border ctx.strokeStyle = "rgba(255, 255, 255, 0.1)"; ctx.lineWidth = 2; ctx.strokeRect(20, 20, 760, 460); // Corner brackets inside the ticket for styling ctx.strokeStyle = "rgba(245, 158, 11, 0.4)"; ctx.lineWidth = 3; // Top-Left corner ctx.beginPath(); ctx.moveTo(35, 60); ctx.lineTo(35, 35); ctx.lineTo(60, 35); ctx.stroke(); // Top-Right corner ctx.beginPath(); ctx.moveTo(765, 60); ctx.lineTo(765, 35); ctx.lineTo(740, 35); ctx.stroke(); // Bottom-Left corner ctx.beginPath(); ctx.moveTo(35, 440); ctx.lineTo(35, 465); ctx.lineTo(60, 465); ctx.stroke(); // Bottom-Right corner ctx.beginPath(); ctx.moveTo(765, 440); ctx.lineTo(765, 465); ctx.lineTo(740, 465); ctx.stroke(); // 5. Draw Header Logo text (HUBAPI) ctx.font = "bold 32px monospace"; ctx.fillStyle = "#fbbf24"; // Amber 400 ctx.fillText("CPU_HUBAPI", 50, 85); ctx.font = "9px monospace"; ctx.fillStyle = "rgba(255, 255, 255, 0.4)"; ctx.fillText("NEURAL GATEWAY MESH ACCESS", 50, 105); // Draw SECURE // LINK badge ctx.fillStyle = "rgba(245, 158, 11, 0.1)"; ctx.fillRect(580, 55, 160, 30); ctx.strokeStyle = "rgba(245, 158, 11, 0.3)"; ctx.lineWidth = 1; ctx.strokeRect(580, 55, 160, 30); ctx.font = "bold 10px monospace"; ctx.fillStyle = "#fbbf24"; ctx.textAlign = "center"; ctx.fillText("SECURE // LINK", 660, 74); ctx.textAlign = "left"; // reset // 6. Draw Middle Title ctx.font = "14px monospace"; ctx.fillStyle = "rgba(255, 255, 255, 0.3)"; ctx.fillText("ACCESS PASS IDENTIFICATION", 50, 200); ctx.font = "extrabold 64px monospace"; ctx.fillStyle = "#ffffff"; ctx.fillText(`# ${ticketNumber}`, 50, 270); // 7. Draw Bottom Info: Masked Email & Date ctx.font = "12px monospace"; ctx.fillStyle = "rgba(255, 255, 255, 0.3)"; ctx.fillText("AUTHORIZED SIGNATORY", 50, 370); ctx.font = "bold 18px monospace"; ctx.fillStyle = "#fbbf24"; ctx.fillText(getMaskedEmail(), 50, 395); ctx.font = "10px monospace"; ctx.fillStyle = "rgba(255, 255, 255, 0.25)"; ctx.fillText( `ISSUED_AT // ${new Date().toISOString().substring(0, 10)}`, 50, 420, ); // 8. Draw Barcode const barcodeX = 540; const barcodeY = 320; const barcodeWeights = [4, 2, 6, 2, 4, 8, 2, 4, 2, 6, 4, 2, 8, 2, 4, 6, 2]; ctx.fillStyle = "rgba(255, 255, 255, 0.8)"; let currX = barcodeX; barcodeWeights.forEach((w) => { ctx.fillRect(currX, barcodeY, w * 1.5, 60); currX += w * 1.5 + 3; }); ctx.font = "10px monospace"; ctx.fillStyle = "rgba(255, 255, 255, 0.3)"; ctx.fillText(`HUBAPI_${ticketNumber.replace(",", "")}`, barcodeX + 15, 400); // 9. Generate Download URL const imageURL = canvas.toDataURL("image/png"); const link = document.createElement("a"); link.href = imageURL; link.download = `HUBAPI-ACCESS-PASS-${ticketNumber.replace(",", "")}.png`; document.body.appendChild(link); link.click(); document.body.removeChild(link); }; const handleMouseMove = (e: React.MouseEvent) => { const card = e.currentTarget; const rect = card.getBoundingClientRect(); const x = e.clientX - rect.left; const y = e.clientY - rect.top; const px = x / rect.width; const py = y / rect.height; // Tilt calculations (-15 to 15 degrees) const rx = (py - 0.5) * -22; const ry = (px - 0.5) * 22; setRotateX(rx); setRotateY(ry); setGlareX(px * 100); setGlareY(py * 100); }; const handleMouseLeave = () => { setRotateX(0); setRotateY(0); setGlareX(50); setGlareY(50); }; const handleCopyCode = () => { const accessCode = `HUBAPI-ACC-${ticketNumber.replace(",", "")}-${email.split("@")[0].toUpperCase()}`; navigator.clipboard.writeText(accessCode); setCopied(true); setTimeout(() => setCopied(false), 2000); }; const shareText = `I just secured early access to @HUBAPI — the Neural API Gateway & AI Automation Mesh! 🚀\n\nClaimed Ticket: #${ticketNumber}\n\nJoin the pre-launch waitlist here:`; const xShareLink = `https://twitter.com/intent/tweet?text=${encodeURIComponent(shareText)}&url=${encodeURIComponent(SITE_URL)}`; // Mask email for aesthetics, e.g. u***r@domain.com const getMaskedEmail = () => { const parts = email.split("@"); if (parts.length !== 2) return email; const name = parts[0]; const domain = parts[1]; if (name.length <= 2) return `${name}***@${domain}`; return `${name.charAt(0)}***${name.charAt(name.length - 1)}@${domain}`; }; return ( {isOpen && (
{/* Backdrop Blur */}