import { useState, useRef, useEffect } from "react";
// ─── THEME ────────────────────────────────────────────────────────────────────
const T = {
royalBlue: "#1a3a8f",
royalDark: "#0f2260",
royalLight: "#2451c7",
gold: "#c9920a",
goldLight: "#f0c040",
goldBright: "#FFD700",
white: "#ffffff",
offWhite: "#f8f6f0",
black: "#080c1a",
gray: "#1e1e2e",
muted: "#7a7a9a",
};
// ─── DATA ─────────────────────────────────────────────────────────────────────
const MODULES = [
{ id: 1, title: "Mindset & Vision", icon: "🧠", subtitle: "Foundation for Success", color: "#1a3a8f" },
{ id: 2, title: "TAG Markets Fundamentals", icon: "🏢", subtitle: "Products, Services & Model", color: "#0f2260" },
{ id: 3, title: "List Building Mastery", icon: "📋", subtitle: "Build Your Prospect Pipeline", color: "#1a5276" },
{ id: 4, title: "Invitation Skills", icon: "📞", subtitle: "Phone, WhatsApp & Social", color: "#1a3a8f" },
{ id: 5, title: "Presentation Skills", icon: "🎤", subtitle: "Zoom, Storytelling & Confidence", color: "#0f2260" },
{ id: 6, title: "Follow-Up Mastery", icon: "🔄", subtitle: "Objection Handling & Closing", color: "#1a5276" },
{ id: 7, title: "Social Media Marketing", icon: "📱", subtitle: "Facebook, Instagram & Reels", color: "#1a3a8f" },
{ id: 8, title: "Personal Branding", icon: "⭐", subtitle: "Profile, Content & Authority", color: "#0f2260" },
{ id: 9, title: "Customer Acquisition", icon: "🎯", subtitle: "Lead Conversion & Retention", color: "#1a5276" },
{ id: 10, title: "Leadership & Duplication", icon: "👑", subtitle: "Coaching & Team Building", color: "#0f2260" },
];
const SPECIAL_CERTS = [
{ id: "master", title: "Master Affiliate Marketer", icon: "🏆", subtitle: "Complete Academy Graduate", color: "#c9920a" },
{ id: "thailand", title: "Thailand Achievers Club", icon: "🌴", subtitle: "Elite Performance Award", color: "#1a3a8f" },
{ id: "dubai", title: "Dubai Achievers Club", icon: "🌆", subtitle: "Diamond Excellence Award", color: "#0f2260" },
{ id: "leader", title: "Certified Team Leader", icon: "💎", subtitle: "Leadership Certification", color: "#6b21a8" },
];
const SAMPLE_MEMBERS = [
{ id: 1, name: "Priya Sharma", rank: "Gold Achiever", region: "Maharashtra", completedModules: [1,2,3,4,5,6,7,8,9,10], points: 8450, joinDate: "2025-01-15" },
{ id: 2, name: "Rahul Mehta", rank: "Diamond Leader", region: "Gujarat", completedModules: [1,2,3,4,5,6,7,8], points: 6200, joinDate: "2025-03-10" },
{ id: 3, name: "Ananya Reddy", rank: "Platinum Achiever", region: "Telangana", completedModules: [1,2,3,4,5,6], points: 4100, joinDate: "2025-02-20" },
{ id: 4, name: "Vikram Singh", rank: "Silver Achiever", region: "Delhi NCR", completedModules: [1,2,3,4], points: 2800, joinDate: "2025-04-05" },
{ id: 5, name: "Deepika Nair", rank: "Crown Ambassador", region: "Kerala", completedModules: [1,2,3,4,5,6,7,8,9], points: 12400, joinDate: "2024-11-01" },
];
function formatDate(d) {
const date = d ? new Date(d) : new Date();
return date.toLocaleDateString("en-IN", { day: "numeric", month: "long", year: "numeric" });
}
function generateCertId(memberId, certType) {
const hash = ((memberId * 7 + certType.length * 13) % 9000) + 1000;
return `TGM-${new Date().getFullYear()}-${hash}`;
}
// ─── CERTIFICATE CANVAS (rendered to DOM, screenshot-able) ───────────────────
function CertificateCanvas({ member, certType, certData, scale = 1 }) {
const isModule = typeof certType === "number";
const module = isModule ? MODULES.find(m => m.id === certType) : null;
const special = !isModule ? SPECIAL_CERTS.find(s => s.id === certType) : null;
const cert = module || special;
const certId = generateCertId(member.id, String(certType));
const issueDate = formatDate(certData?.issueDate);
const W = 960, H = 680;
const sw = W * scale, sh = H * scale;
return (
{/* Deep background */}
{/* Content layer */}
{/* TOP: Organization name */}
TAG MARKETS SUCCESS ACADEMY
{/* Divider line with diamond */}
{/* Certificate of Completion */}
Certificate of Completion
{/* Module icon */}
{cert?.icon}
{/* THIS IS TO CERTIFY */}
This is to certify that
{/* Member name */}
{member.name}
{/* Rank */}
{member.rank} · {member.region}
{/* Divider */}
{/* Has successfully completed */}
has successfully completed
{/* Module/Certificate title */}
{isModule ? `Module ${certType}: ${cert.title}` : cert?.title}
{/* Subtitle */}
{cert?.subtitle}
{/* Bottom row: signatures + date + cert ID */}
{/* Issuer signature */}
ACADEMY DIRECTOR
TAG Markets Global
{/* Center seal */}
{/* Date & cert ID */}
);
}
// ─── MINI CERTIFICATE CARD (list view) ───────────────────────────────────────
function CertCard({ member, certType, onPreview, earned }) {
const isModule = typeof certType === "number";
const cert = isModule ? MODULES.find(m => m.id === certType) : SPECIAL_CERTS.find(s => s.id === certType);
return (
earned && onPreview({ member, certType })}
style={{
background: earned
? "linear-gradient(135deg, #0f1a3a 0%, #1a2a5a 100%)"
: "rgba(255,255,255,0.03)",
border: `1px solid ${earned ? "rgba(201,146,10,0.4)" : "rgba(255,255,255,0.07)"}`,
borderRadius: 12, padding: "14px 16px",
cursor: earned ? "pointer" : "default",
transition: "all 0.2s",
position: "relative", overflow: "hidden",
opacity: earned ? 1 : 0.45,
}}
onMouseEnter={e => earned && (e.currentTarget.style.borderColor = "rgba(201,146,10,0.8)")}
onMouseLeave={e => earned && (e.currentTarget.style.borderColor = "rgba(201,146,10,0.4)")}
>
{earned && (
)}
{cert?.icon}
{isModule ? `Module ${certType}` : cert?.title}
{isModule ? cert?.title : cert?.subtitle}
{earned ? (
✓ EARNED
) : (
LOCKED
)}
);
}
// ─── MODAL OVERLAY ────────────────────────────────────────────────────────────
function Modal({ children, onClose }) {
return (
e.stopPropagation()} style={{ position: "relative" }}>
{children}
);
}
// ─── STATS BAR ────────────────────────────────────────────────────────────────
function StatBadge({ value, label, color }) {
return (
);
}
// ─── MAIN APP ─────────────────────────────────────────────────────────────────
export default function TagMarketsCertificates() {
const [selectedMember, setSelectedMember] = useState(SAMPLE_MEMBERS[0]);
const [preview, setPreview] = useState(null); // { member, certType }
const [tab, setTab] = useState("member"); // member | admin
const [copied, setCopied] = useState(false);
const [downloading, setDownloading] = useState(false);
const [searchQuery, setSearchQuery] = useState("");
const [filterStatus, setFilterStatus] = useState("all");
const certRef = useRef(null);
// Determine earned certs for selected member
const earnedModules = selectedMember.completedModules || [];
const earnedSpecial = [];
if (earnedModules.length === 10) earnedSpecial.push("master");
if (selectedMember.points >= 10000) earnedSpecial.push("thailand");
if (selectedMember.points >= 15000) earnedSpecial.push("dubai");
if (["Diamond Leader","Crown Ambassador","Legend Leader"].includes(selectedMember.rank)) earnedSpecial.push("leader");
const totalEarned = earnedModules.length + earnedSpecial.length;
// Download: uses html2canvas via CDN (loaded dynamically) or SVG fallback
const handleDownload = async () => {
setDownloading(true);
// Simulate download by creating a canvas from the cert element
await new Promise(r => setTimeout(r, 800));
// Create a descriptive download notification
const isModule = typeof preview.certType === "number";
const cert = isModule
? MODULES.find(m => m.id === preview.certType)
: SPECIAL_CERTS.find(s => s.id === preview.certType);
const filename = `TGM-Certificate-${preview.member.name.replace(/\s+/g, "-")}-${cert?.title.replace(/\s+/g, "-")}.png`;
// In a real app: html2canvas(certRef.current).then(canvas => canvas.toBlob(...))
alert(`📜 Certificate ready!\nFilename: ${filename}\n\nIn production this saves a high-res PNG.\n(Requires html2canvas library integration)`);
setDownloading(false);
};
const handleCopyId = () => {
const id = generateCertId(preview.member.id, String(preview.certType));
navigator.clipboard?.writeText(id).catch(() => {});
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
// Filter members for admin view
const filteredMembers = SAMPLE_MEMBERS.filter(m => {
const q = searchQuery.toLowerCase();
const matchQ = m.name.toLowerCase().includes(q) || m.region.toLowerCase().includes(q);
const earnedCount = m.completedModules.length;
const matchF = filterStatus === "all"
? true
: filterStatus === "complete" ? earnedCount === 10
: filterStatus === "partial" ? (earnedCount > 0 && earnedCount < 10)
: earnedCount === 0;
return matchQ && matchF;
});
return (
{/* ── HEADER ── */}
🏅
Digital Certificates
TAG Markets Success Academy
{/* Tabs */}
{[
{ id: "member", label: "🎓 My Certificates" },
{ id: "admin", label: "⚙️ Admin View" },
].map(t => (
))}
{/* ─── MEMBER VIEW ─── */}
{tab === "member" && (
{/* Member selector */}
VIEW AS:
{SAMPLE_MEMBERS.map(m => (
))}
{/* Member stats */}
{selectedMember.name.split(" ").map(w => w[0]).join("")}
{selectedMember.name}
{selectedMember.rank} · {selectedMember.region}
{/* Progress bar */}
Academy Completion Progress
{Math.round((earnedModules.length / 10) * 100)}%
{/* Module certificates */}
Module Certificates (10)
{MODULES.map(m => (
))}
{/* Special certificates */}
Special Achievement Certificates (4)
{SPECIAL_CERTS.map(s => (
))}
)}
{/* ─── ADMIN VIEW ─── */}
{tab === "admin" && (
{/* Stats overview */}
m.completedModules.length === 10).length}
label="Full Graduates" color="#4ade80"
/>
a + m.completedModules.length, 0)}
label="Certs Issued" color="#60a5fa"
/>
a+m.completedModules.length,0)/SAMPLE_MEMBERS.length*10)+"%"}
label="Avg Completion" color="#f472b6"
/>
{/* Filter bar */}
setSearchQuery(e.target.value)}
placeholder="Search by name or region..."
style={{
flex: 1, minWidth: 180, background: "rgba(255,255,255,0.04)",
border: "1px solid rgba(255,255,255,0.1)", borderRadius: 8,
color: T.white, padding: "8px 14px", fontSize: 12,
outline: "none",
}}
/>
{["all", "complete", "partial", "none"].map(f => (
))}
{/* Member table */}
{/* Header */}
Member
Rank
Points
Module Progress
Actions
{filteredMembers.map((m, i) => {
const pct = Math.round((m.completedModules.length / 10) * 100);
return (
e.currentTarget.style.background = "rgba(255,255,255,0.03)"}
onMouseLeave={e => e.currentTarget.style.background = "transparent"}
>
{m.name.split(" ").map(w => w[0]).join("")}
{m.points.toLocaleString()}
{m.completedModules.length}/10 ({pct}%)
{MODULES.map(mod => (
m.completedModules.includes(mod.id) && setPreview({ member: m, certType: mod.id })}
>
{m.completedModules.includes(mod.id) ? "✓" : mod.id}
))}
);
})}
{filteredMembers.length === 0 && (
No members match your filter.
)}
)}
{/* ─── PREVIEW MODAL ─── */}
{preview && (
setPreview(null)}>
{/* Scale certificate to fit viewport */}
{/* Action buttons */}
{/* Verification ID */}
Verification ID:
{generateCertId(preview.member.id, String(preview.certType))}
·
Issued: {formatDate()}
)}
);
}