import classNames from "classnames"; import { useCallback } from "react"; import { Icon, Icons } from "@/components/Icon"; import { usePlayerMeta } from "@/components/player/hooks/usePlayerMeta"; import { Transition } from "@/components/Transition"; import { PlayerMetaEpisode } from "@/stores/player/slices/source"; import { usePlayerStore } from "@/stores/player/store"; function shouldShowNextEpisodeButton( time: number, duration: number ): "always" | "hover" | "none" { const percentage = time / duration; const secondsFromEnd = duration - time; if (secondsFromEnd <= 30) return "always"; if (percentage >= 0.9) return "hover"; return "none"; } function Button(props: { className: string; onClick?: () => void; children: React.ReactNode; }) { return ( ); } export function NextEpisodeButton(props: { controlsShowing: boolean }) { const duration = usePlayerStore((s) => s.progress.duration); const isHidden = usePlayerStore((s) => s.interface.hideNextEpisodeBtn); const meta = usePlayerStore((s) => s.meta); const { setDirectMeta } = usePlayerMeta(); const hideNextEpisodeButton = usePlayerStore((s) => s.hideNextEpisodeButton); const metaType = usePlayerStore((s) => s.meta?.type); const time = usePlayerStore((s) => s.progress.time); const showingState = shouldShowNextEpisodeButton(time, duration); const status = usePlayerStore((s) => s.status); let show = false; if (showingState === "always") show = true; else if (showingState === "hover" && props.controlsShowing) show = true; if (isHidden || status !== "playing" || duration === 0) show = false; const animation = showingState === "hover" ? "slide-up" : "fade"; let bottom = "bottom-24"; if (showingState === "always") bottom = props.controlsShowing ? "bottom-24" : "bottom-12"; const nextEp = meta?.episodes?.find( (v) => v.number === (meta?.episode?.number ?? 0) + 1 ); const loadNextEpisode = useCallback(() => { if (!meta || !nextEp) return; const metaCopy = { ...meta }; metaCopy.episode = nextEp; setDirectMeta(metaCopy); }, [setDirectMeta, nextEp, meta]); if (!meta?.episode || !nextEp) return null; if (metaType !== "show") return null; return (
); }