import { useEffect, useRef, useState, useCallback } from "react"; import { useSearchParams } from "react-router-dom"; import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { getVideoByYtId, updateProgress, createDownload, followChannelByUrl, getDownload } from "../api"; function formatDuration(s) { if (!s) return ""; const h = Math.floor(s / 3600), m = Math.floor((s % 3600) / 60), sec = s % 60; if (h > 0) return `${h}:${String(m).padStart(2, "0")}:${String(sec).padStart(2, "0")}`; return `${m}:${String(sec).padStart(2, "0")}`; } function CloseIcon() { return ( ); } function YoutubeEmbed({ youtubeId, startAt, onTimeUpdate }) { useEffect(() => { const handler = (e) => { if (e.origin !== "https://www.youtube.com") return; try { const data = JSON.parse(e.data); if (data.event === "infoDelivery" && data.info?.currentTime != null) { onTimeUpdate(Math.floor(data.info.currentTime)); } } catch {} }; window.addEventListener("message", handler); return () => window.removeEventListener("message", handler); }, [onTimeUpdate]); const start = startAt > 10 ? startAt : 0; const src = `https://www.youtube.com/embed/${youtubeId}?autoplay=1&rel=0&modestbranding=1&enablejsapi=1&start=${start}&origin=${encodeURIComponent(window.location.origin)}`; return (