"use client" import React, { useState } from "react" import { Copy, FileText, MoreHorizontal, Check, ChevronDown, CopyIcon } from "lucide-react" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { Icons } from "@/components/icons" import { motion, Variants } from 'motion/react' interface CopyPageMenuProps { title: string content: string // The main content to copy currentUrl: string // Current page URL for markdown link generation } const copyIconVariants: Variants = { idle: { opacity: 1, scale: 1, transition: { duration: 0.2, ease: "easeOut" } }, copying: { opacity: 0, scale: 0.8, transition: { duration: 0.2, ease: "easeOut" } }, copied: { opacity: 0, scale: 0.8, transition: { duration: 0.2, ease: "easeOut" } } } const checkIconVariants: Variants = { idle: { opacity: 0, scale: 0.8, transition: { duration: 0.2, ease: "easeOut" } }, copying: { opacity: 0, scale: 0.8, transition: { duration: 0.2, ease: "easeOut" } }, copied: { opacity: 1, scale: 1, transition: { duration: 0.2, ease: "easeOut" } } } const checkPathVariants: Variants = { idle: { pathLength: 0, opacity: 0, transition: { duration: 0.2, ease: "easeOut" } }, copying: { pathLength: 0, opacity: 1, transition: { duration: 0.2, ease: "easeOut" } }, copied: { pathLength: 1, opacity: 1, transition: { duration: 0.3, ease: "easeOut" } } } export function CopyPageMenu({ title, content, currentUrl }: CopyPageMenuProps) { const [status, setStatus] = useState<"idle" | "copying" | "copied">("idle") const copyToClipboard = async (text: string) => { try { await navigator.clipboard.writeText(text) } catch (error) { console.error("Failed to copy to clipboard:", error) throw error } } const handleCopyAsMarkdown = async () => { if (status !== "idle") return setStatus("copying") try { const url = new URL(currentUrl) const markdownPath = `${url.pathname}.md` const response = await fetch(markdownPath) if (!response.ok) { throw new Error(`Failed to fetch markdown: ${response.statusText}`) } const fullMarkdownContent = await response.text() await copyToClipboard(fullMarkdownContent) setTimeout(() => { setStatus("copied") }, 100) setTimeout(() => { setStatus("idle") }, 2000) } catch (error) { console.error("Failed to copy markdown:", error) setStatus("idle") } } const handleViewAsMarkdown = () => { const markdownUrl = `${currentUrl}.md` window.open(markdownUrl, "_blank") } const handleOpenInChatGPT = () => { const prompt = `Please help me understand this documentation: ${currentUrl}.md` const chatGPTUrl = `https://chat.openai.com/?model=gpt-4&q=${encodeURIComponent(prompt)}` window.open(chatGPTUrl, "_blank") } const handleOpenInClaude = () => { const prompt = `Please help me understand this documentation: ${currentUrl}.md` const claudeUrl = `https://claude.ai/new?q=${encodeURIComponent(prompt)}` window.open(claudeUrl, "_blank") } return (
{/* Copy Icon */} {/* Check Icon */}
) }