"use client"; import { useState } from "react"; import { usePathname } from "next/navigation"; export function CopyPageButton() { const pathname = usePathname(); const [state, setState] = useState<"idle" | "loading" | "copied">("idle"); const handleCopy = async () => { setState("loading"); try { const response = await fetch( `/api/docs-markdown?path=${encodeURIComponent(pathname)}`, ); if (!response.ok) { throw new Error("Failed to fetch markdown"); } const markdown = await response.text(); await navigator.clipboard.writeText(markdown); setState("copied"); setTimeout(() => setState("idle"), 2000); } catch { setState("idle"); } }; return ( ); }