"use client"; import { useEffect, useState } from "react"; import type { LinkPreview } from "@/lib/forum"; type Device = "android" | "ios" | "desktop"; function detect(): Device { const ua = navigator.userAgent; if (/Android/i.test(ua)) return "android"; // iPadOS reports itself as a Mac with touch. if (/iPhone|iPad|iPod/i.test(ua) || (/Macintosh/.test(ua) && navigator.maxTouchPoints > 1)) return "ios"; return "desktop"; } /** * A YouTube link under a post: our own copy of the thumbnail (nothing is * loaded from YouTube until someone plays it). On a computer a click plays * it here; on a phone it opens the YouTube app (Android: an intent with the * web page as fallback; iOS: the link, which the app takes over), and * "Lejátszás itt" plays it here. */ function YouTubeCard({ link }: { link: LinkPreview }) { const [playing, setPlaying] = useState(false); const [device, setDevice] = useState("desktop"); useEffect(() => setDevice(detect()), []); const at = link.start ? `&t=${link.start}s` : ""; const watch = `https://www.youtube.com/watch?v=${link.id}${at}`; const app = device === "android" ? `intent://www.youtube.com/watch?v=${link.id}${at}#Intent;scheme=https;package=com.google.android.youtube;` + `S.browser_fallback_url=${encodeURIComponent(watch)};end` : watch; const mobile = device !== "desktop"; if (playing) { const start = link.start ? `&start=${link.start}` : ""; return (