import { useEffect, useId, useRef, useState } from "react"; import { Download, File as FileIcon, Link2, Lock, PlayCircle, Repeat } from "lucide-react"; import { Button } from "./ui/Button"; import { Chip } from "./ui/Chip"; import { formatBytes } from "../lib/format"; import { exposeVideoToBackgroundPlay } from "../lib/browserBackgroundPlay"; import { LS, readJSON, writeJSON } from "../lib/storage"; import { send } from "../lib/http"; import { Input } from "./ui/Input"; import { SURFACE } from "./ui/surfaces"; import { LinkButton } from "./ui/LinkButton"; // Standalone, login-free video page for a shared /watch/ link. Rendered OUTSIDE the app // tree (no auth, no providers) — like the /privacy and /terms pages. Uses plain fetch and a tiny // self-contained i18n dict (the public viewer has no app language preference). // Advertise the playing video to the OS via the Media Session API: lock-screen / control-center // metadata + play/pause handlers. This is also what lets a browser's own "background playback" // feature keep the audio going when the page is backgrounded — it's exactly how youtube.com stays // playing in the background on Brave iOS. We deliberately do NOT route the audio through the Web // Audio API: `createMediaElementSource` pulls the element out of the normal media pipeline that the // background feature (and iOS) hooks into, and iOS then suspends the AudioContext on background — // which STOPPED playback instead of keeping it alive (measured on iPad Brave). A plain