import { useState } from 'react' import { Copy, Check, CalendarPlus, Calendar } from 'lucide-react' interface SubscribeLinksProps { httpsUrl: string webcalUrl: string } /** * Shared presentation for calendar subscription URLs. Renders one-click * subscribe actions (Google deep link + webcal handoff) plus a copy fallback. * Used by both the per-trip and all-trips subscribe modals. */ export function SubscribeLinks({ httpsUrl, webcalUrl }: SubscribeLinksProps) { const [copied, setCopied] = useState<'https' | 'webcal' | null>(null) // Google Calendar's add-by-URL deep link. The cid must carry the webcal:// // scheme (not https), URL-encoded, and the feed must be served over HTTPS. const googleUrl = `https://www.google.com/calendar/render?cid=${encodeURIComponent(webcalUrl)}` const copy = async (url: string, which: 'https' | 'webcal') => { try { if (navigator.clipboard && window.isSecureContext) { await navigator.clipboard.writeText(url) } else { // Fallback for non-secure contexts (plain HTTP) where navigator.clipboard is unavailable const ta = document.createElement('textarea') ta.value = url ta.style.position = 'fixed' ta.style.left = '-9999px' document.body.appendChild(ta) ta.focus() ta.select() document.execCommand('copy') document.body.removeChild(ta) } setCopied(which) setTimeout(() => setCopied(null), 2000) } catch { /* ignore */ } } return (