import { useState, useEffect, useCallback, useRef } from 'react'; import { createPortal } from 'react-dom'; import { S, api } from '../lib.js'; const POSTER = 'https://image.tmdb.org/t/p/w342'; const BACKDROP = 'https://image.tmdb.org/t/p/w780'; const TOOL_DEFS = [ { id: 'kino', label: 'π¬ Kino', desc: 'Aktuell im Kino (DE) β alle laufenden Filme', ready: true }, { id: 'demnΓ€chst', label: 'π DemnΓ€chst', desc: 'Neustarts wochenweise β nΓ€chste Wochen', ready: true }, { id: 'favoriten', label: 'β€ Favoriten', desc: 'Deine gespeicherten Lieblingsfilme', ready: true }, { id: 'suchen', label: 'π Suchen', desc: 'Filme suchen und Infos abrufen', ready: true }, ]; const getIcon = lbl => [...lbl][0] ?? 'π¬'; const getText = lbl => { const c = [...lbl]; return c.slice(1).join('').trim() || lbl; }; const fmtDE = d => d ? new Date(d).toLocaleDateString('de-DE', { day:'2-digit', month:'2-digit', year:'numeric' }) : ''; const fmtWeek = dateStr => { const d = new Date(dateStr); // KW berechnen const jan4 = new Date(d.getFullYear(), 0, 4); const kw = Math.ceil(((d - jan4) / 86400000 + jan4.getDay() + 1) / 7); const end = new Date(d); end.setDate(d.getDate() + 6); return `KW ${kw} Β· ${d.toLocaleDateString('de-DE',{day:'2-digit',month:'2-digit'})} β ${end.toLocaleDateString('de-DE',{day:'2-digit',month:'2-digit',year:'numeric'})}`; }; const FSK_COLOR = fsk => { if (!fsk) return null; const n = parseInt(fsk); if (n === 0) return { bg:'#fff', color:'#000' }; if (n === 6) return { bg:'#f9e200', color:'#000' }; if (n === 12) return { bg:'#00a859', color:'#fff' }; if (n === 16) return { bg:'#0070bb', color:'#fff' }; if (n === 18) return { bg:'#e2001a', color:'#fff' }; return { bg:'#444', color:'#fff' }; }; export default function Media({ toast, mobile, initTab, onInitTabConsumed }) { const [activeTool, setActiveTool] = useState('kino'); const [favIds, toggleFav] = useFavIds(); // Wenn von auΓen ein Tab vorgegeben wird (z.B. Dashboard-Badge) useEffect(() => { if (initTab) { setActiveTool(initTab); onInitTabConsumed?.(); } }, [initTab]); const [modal, setModal] = useState(null); // { id, media_type } const [xrelIds, setXrelIds] = useState(new Set()); // tmdb_ids mit bekannten Releases const chipScrollRef = useRef(null); const [chipScroll, setChipScroll] = useState({ left: false, right: true }); const onChipScroll = () => { const el = chipScrollRef.current; if (!el) return; setChipScroll({ left: el.scrollLeft > 4, right: el.scrollLeft < el.scrollWidth - el.clientWidth - 4 }); }; const active = TOOL_DEFS.find(t => t.id === activeTool); return (