HubAPI / components /CyberTicketModal.tsx
samirhosninet's picture
feat: update icon system with LobeHub provider logos
d3e44c7
Raw History Blame Contribute Delete
18.4 kB
"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<HTMLDivElement>(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<HTMLDivElement>) => {
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 (
<AnimatePresence>
{isOpen && (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
{/* Backdrop Blur */}
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
onClick={onClose}
className="absolute inset-0 bg-black/80 backdrop-blur-md cursor-pointer"
aria-hidden="true"
/>
{/* Modal Container */}
<motion.div
ref={modalRef}
role="dialog"
aria-modal="true"
aria-labelledby="ticket-modal-title"
tabIndex={-1}
initial={{ opacity: 0, scale: 0.9, y: 20 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
exit={{ opacity: 0, scale: 0.9, y: 20 }}
transition={{ type: "spring", damping: 25, stiffness: 200 }}
className="relative w-full max-w-lg bg-black/90 border border-primary/20 p-6 md:p-8 rounded-lg shadow-[0_0_50px_rgba(255,170,64,0.1)] z-10 overflow-hidden font-mono focus:outline-none"
>
{/* Ambient Background Glow */}
<div className="absolute -top-32 -left-32 w-64 h-64 bg-primary/10 rounded-full blur-3xl pointer-events-none" />
<div className="absolute -bottom-32 -right-32 w-64 h-64 bg-indigo-500/10 rounded-full blur-3xl pointer-events-none" />
{/* Corner Bracket Borders */}
<div className="absolute top-0 left-0 w-8 h-8 border-t-2 border-l-2 border-primary/30" />
<div className="absolute top-0 right-0 w-8 h-8 border-t-2 border-r-2 border-primary/30" />
<div className="absolute bottom-0 left-0 w-8 h-8 border-b-2 border-l-2 border-primary/30" />
<div className="absolute bottom-0 right-0 w-8 h-8 border-b-2 border-r-2 border-primary/30" />
{/* Header */}
<div className="flex justify-between items-center mb-6">
<span
id="ticket-modal-title"
className="text-xs text-amber-400 tracking-widest uppercase flex items-center gap-2"
>
<span className="w-1.5 h-1.5 bg-amber-400 rounded-full animate-ping" />
{t("logo")} {"//"} {t("ticketConfirmed")}
</span>
<button
onClick={onClose}
className="text-zinc-400 hover:text-white transition-colors p-1 bg-white/5 border border-white/10 rounded-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-amber-500"
aria-label="Close modal"
>
<X className="w-4 h-4" />
</button>
</div>
<div className="text-center space-y-2 mb-8">
<h2 className="text-xl md:text-2xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-amber-400 via-zinc-100 to-indigo-400">
{t("ticketConfirmed")}
</h2>
<p className="text-xs text-zinc-400 max-w-sm mx-auto">
{t("ticketDescription")}
</p>
</div>
{/* 3D Holographic Card Box (Real Three.js WebGL) */}
<div className="flex justify-center py-4 mb-6">
<ThreeTicketCard
email={email}
ticketNumber={ticketNumber}
rotateX={rotateX}
rotateY={rotateY}
glareX={glareX}
glareY={glareY}
onMouseMove={handleMouseMove}
onMouseLeave={handleMouseLeave}
/>
</div>
{/* Action Buttons */}
<div className="flex flex-col gap-3">
<div className="flex flex-col sm:flex-row gap-3">
<a
href={xShareLink}
target="_blank"
rel="noopener noreferrer"
className="flex-1 flex items-center justify-center gap-2 h-12 bg-white text-black hover:bg-white/90 transition-colors uppercase font-bold text-xs tracking-wider cursor-pointer border-none [clip-path:polygon(8px_0,100%_0,100%_calc(100%_-_8px),calc(100%_-_8px)_100%,0_100%,0_8px)]"
>
<svg
className="w-4 h-4 fill-current"
viewBox="0 0 24 24"
aria-hidden="true"
>
<path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z" />
</svg>
<span>{t("shareOnX")}</span>
</a>
<button
onClick={exportTicketAsImage}
className="flex-1 flex items-center justify-center gap-2 h-12 bg-amber-500 text-black hover:bg-amber-400 transition-colors uppercase font-bold text-xs tracking-wider cursor-pointer border-none [clip-path:polygon(8px_0,100%_0,100%_calc(100%_-_8px),calc(100%_-_8px)_100%,0_100%,0_8px)]"
>
<Download className="w-4 h-4" />
<span>
{language === "ar" ? "تحميل التذكرة" : "Download Pass"}
</span>
</button>
</div>
<button
onClick={handleCopyCode}
className="w-full flex items-center justify-center gap-2 h-12 bg-transparent text-zinc-400 hover:text-white hover:bg-white/5 border border-zinc-800 transition-colors uppercase font-bold text-xs tracking-wider cursor-pointer [clip-path:polygon(8px_0,100%_0,100%_calc(100%_-_8px),calc(100%_-_8px)_100%,0_100%,0_8px)]"
>
{copied ? (
<>
<Check className="w-4 h-4 text-emerald-500" />
<span className="text-emerald-500">
{language === "ar"
? "تم نسخ الرمز"
: "Access Code Copied"}
</span>
</>
) : (
<>
<Copy className="w-4 h-4" />
<span>{t("copyLink")}</span>
</>
)}
</button>
</div>
<div className="mt-6 flex items-center justify-center gap-2 text-[9px] text-white/35 text-center select-none">
<Activity className="w-3.5 h-3.5 text-amber-500/40" />
<span>
SYS_ENCRYPT // ACC_TOKEN SHA256 VALIDATED BY HUBAPI GATEWAYS
</span>
</div>
</motion.div>
</div>
)}
</AnimatePresence>
);
}