import { api } from '../api.js'; import { showToast } from '../components/toast.js'; const API = (url, opts = {}) => fetch('/api' + url, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${localStorage.getItem('token')}`, ...opts.headers }, ...opts }).then(r => r.json()); const HOURS = Array.from({ length: 24 }, (_, i) => i); const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; function esc(str) { const d = document.createElement('div'); d.textContent = str; return d.innerHTML; } export async function render(container) { const [devices, content, groups, playlists, layoutsRaw] = await Promise.all([ api.getDevices(), api.getContent(), api.getGroups(), api.getPlaylists(), API('/layouts'), ]); const layouts = (Array.isArray(layoutsRaw) ? layoutsRaw : []).filter(l => !l.is_template); const selectedDevice = devices[0]?.id || ''; const today = new Date(); const weekStart = new Date(today); weekStart.setDate(today.getDate() - today.getDay()); weekStart.setHours(0, 0, 0, 0); container.innerHTML = `