"use client" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { Button } from "@/components/ui/button" import { Share2, Copy, Check, Twitter, Facebook, Linkedin, Link as LinkIcon, MessageSquare, MessageCircle, Send, Gamepad2 } from "lucide-react" import { useState } from "react" import { cn } from "@/lib/utils" interface ShareMenuProps { artworkId: string prompt: string trigger?: React.ReactNode className?: string } export function ShareMenu({ artworkId, prompt, trigger, className }: ShareMenuProps) { const [copied, setCopied] = useState(false) const [isOpen, setIsOpen] = useState(false) // Base URL needed for client-side composition // Fallback to window.location if available logic to prevent SSR issues const baseUrl = typeof window !== "undefined" ? window.location.origin : "" const shareUrl = `${baseUrl}/artwork/${artworkId}` const encodedUrl = encodeURIComponent(shareUrl) const encodedText = encodeURIComponent(`Check out this AI art: "${prompt}" created on Imyra!`) const handleCopy = async () => { try { await navigator.clipboard.writeText(shareUrl) setCopied(true) setTimeout(() => setCopied(false), 2000) } catch (err) { console.error("Failed to copy", err) } } const shareLinks = [ { name: "Twitter / X", icon: Twitter, url: `https://twitter.com/intent/tweet?text=${encodedText}&url=${encodedUrl}`, color: "hover:text-blue-400" }, { name: "Facebook", icon: Facebook, url: `https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}`, color: "hover:text-blue-600" }, { name: "WhatsApp", icon: MessageCircle, url: `https://wa.me/?text=${encodedText}%20${encodedUrl}`, color: "hover:text-green-500" }, { name: "Telegram", icon: Send, url: `https://t.me/share/url?url=${encodedUrl}&text=${encodedText}`, color: "hover:text-blue-500" }, { name: "Discord", icon: Gamepad2, url: "", // Discord doesn't have a share URL, handled via onClick action: true, // Special flag to trigger copy color: "hover:text-indigo-500" }, { name: "Reddit", icon: MessageSquare, url: `https://www.reddit.com/submit?url=${encodedUrl}&title=${encodedText}`, color: "hover:text-orange-500" }, { name: "LinkedIn", icon: Linkedin, url: `https://www.linkedin.com/sharing/share-offsite/?url=${encodedUrl}`, color: "hover:text-blue-700" } ] return ( {trigger || ( )}

Share Artwork

{shareUrl}
{shareLinks.map((platform) => { if (platform.action) { return ( ) } return ( setIsOpen(false)} > {platform.name} ) })}
) }