"use client"; import { useState } from "react"; import { useCopyFeedback } from "./shared"; import { buildShortHighlightUrl } from "@/lib/text-highlight"; import { createPortal } from "react-dom"; import { X, MessageSquare, ExternalLink } from "lucide-react"; import { Drawer, DrawerClose, DrawerContent, DrawerHeader, DrawerTitle, } from "@/components/ui/drawer"; export function ShareModal({ open, onClose, selectedText, isMobile, }: { open: boolean; onClose: () => void; selectedText: string; isMobile: boolean; }) { const { copied, copy } = useCopyFeedback(); const [generating, setGenerating] = useState(false); async function handleCopyShareLink() { if (generating) return; setGenerating(true); try { const url = await buildShortHighlightUrl(selectedText); await copy(url); } finally { setGenerating(false); } } const shareOptions = [ { key: "feed", label: "Share to Feed", icon: , description: "Post this quote to your feed", onClick: () => { // TODO: Implement share to feed onClose(); }, }, { key: "link", label: "Share Link", icon: , description: "Copy a shareable link", onClick: handleCopyShareLink, }, ]; function linkLabel(optKey: string, optLabel: string) { if (optKey !== "link") return optLabel; if (copied) return "Link Copied!"; if (generating) return "Generating link…"; return optLabel; } if (isMobile) { return ( !o && onClose()}> Share {selectedText && (

“{selectedText.slice(0, 120)} {selectedText.length > 120 ? "…" : ""}”

)}
{shareOptions.map((opt) => ( ))}
); } // Desktop modal if (!open) return null; return createPortal( <>

Share

{selectedText && (

“{selectedText.slice(0, 120)} {selectedText.length > 120 ? "…" : ""}”

)}
{shareOptions.map((opt) => ( ))}
, document.body, ); }