import { api } from '../api.js'; import { showToast } from '../components/toast.js'; import { t } from '../i18n.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); 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 today = new Date(); const weekStart = new Date(today); weekStart.setDate(today.getDate() - today.getDay()); weekStart.setHours(0, 0, 0, 0); const DAYS = [ t('schedule.day.sun'), t('schedule.day.mon'), t('schedule.day.tue'), t('schedule.day.wed'), t('schedule.day.thu'), t('schedule.day.fri'), t('schedule.day.sat'), ]; container.innerHTML = `