"use client"; import type React from "react"; import { useState, useRef, useEffect } from "react"; import { Code, Image, Type } from "lucide-react"; import { toast } from "sonner"; import { useTheme } from "next-themes"; import type { StaticImageData } from "next/image"; interface LogoAssets { darkSvg: string; whiteSvg: string; darkWordmark: string; whiteWordmark: string; darkPng: StaticImageData; whitePng: StaticImageData; } interface ContextMenuProps { logo: React.ReactNode; logoAssets: LogoAssets; } export default function LogoContextMenu({ logo, logoAssets, }: ContextMenuProps) { const [showMenu, setShowMenu] = useState(false); const menuRef = useRef(null); const logoRef = useRef(null); const { theme } = useTheme(); const handleContextMenu = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); const rect = logoRef.current?.getBoundingClientRect(); if (rect) { setShowMenu(true); } }; const copySvgToClipboard = ( e: React.MouseEvent, svgContent: string, type: string, ) => { e.preventDefault(); e.stopPropagation(); navigator.clipboard .writeText(svgContent) .then(() => { toast.success("", { description: `${type} copied to clipboard`, }); }) .catch((err) => { toast.error("", { description: `Failed to copy ${type} to clipboard`, }); }); setShowMenu(false); }; const downloadPng = ( e: React.MouseEvent, pngData: StaticImageData, fileName: string, ) => { e.preventDefault(); e.stopPropagation(); const link = document.createElement("a"); link.href = pngData.src; link.download = fileName; document.body.appendChild(link); link.click(); document.body.removeChild(link); toast.success(`Downloading the asset...`); setShowMenu(false); }; const downloadAllAssets = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); const link = document.createElement("a"); link.href = "/branding/better-auth-brand-assets.zip"; link.download = "better-auth-branding-assets.zip"; document.body.appendChild(link); link.click(); document.body.removeChild(link); toast.success("Downloading all assets..."); setShowMenu(false); }; useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (menuRef.current && !menuRef.current.contains(event.target as Node)) { setShowMenu(false); } }; document.addEventListener("mousedown", handleClickOutside); return () => { document.removeEventListener("mousedown", handleClickOutside); }; }, []); const getAsset = (darkAsset: T, lightAsset: T): T => { return theme === "dark" ? darkAsset : lightAsset; }; return (
{logo}
{showMenu && (



)}
); }