'use strict';
import * as sol from "../../solight/sol.js";
import * as serv from "../services/general.js";
const html = htm.bind(preact.h);
const dt = luxon.Duration.fromObject({minutes: 10});
const max_events = 5;
const title_string = 'Program:';
const local_room = 'Here';
const this_room = (config) => sol.optional(config.roomName);
const is_stale = (event, time) =>
!sol.isFutureEvent(event, time);
const is_lapse = (event, time) =>
serv.is_soon(sol.eventStartDate(event).plus(dt), time, 5);
const stale_class = (event, time) => is_stale(event, time) ? 'stale' : '';
const lapse_class = (event, time) => is_lapse(event, time) ? 'lapse' : '';
const this_location = (config) => {
const here = this_room(config);
return sol.defined(here) ? html`@${here}` : html``;
};
const schedule_table_header = () =>
html`
`;
const event_time = (event, time) => {
const esd = sol.eventStartDate(event);
const timeString = esd.setLocale('de').toLocaleString(luxon.DateTime.TIME_24_SIMPLE);
return html`${timeString}
`;
};
const event_location = (event, config) => {
const here_room = this_room(config);
const event_room = sol.eventRoomName(event);
let inner;
if (sol.defined(here_room) && (event_room === here_room)) {
inner = html`${local_room}
`;
} else {
inner = html`${event_room}
`;
}
return inner;
};
const event_title = (event, time) => {
const title = serv.fix_dash(sol.eventTitle(event));
return html`${title}
`;
};
const event_speaker = (event, time) => {
const speaker = serv.fix_dash(serv.person_names_concat(sol.eventPersons(event)));
return html`${speaker}
`;
};
const schedule_table_event = (event, time, config) => {
const ti = serv.type_index(sol.eventType(event));
return html`
${event_time(event, time)}
${event_title(event, time)}
${event_speaker(event, time)}
`;
};
const schedule_table_events = (events, time, config) =>
html`
${events.map(e => schedule_table_event(e, time, config))}
`;
const schedule_table = (events, time, config) =>
html`
${schedule_table_header()}
${schedule_table_events(events, time, config)}`;
const header = (config) =>
html`${this_location(config)}
`;
const update_main_slide = (data, time, config) => {
// console.group("Updating Main Slide with:");
// console.info(data);
// console.info(time);
// console.info(config);
// console.groupEnd();
if (sol.defined(data.scheduleData)) {
const schedule = data.scheduleData;
const events = sol.allEvents(schedule);
const startedEvents = sol.startedEvents(events, time, dt);
const futureEvents = sol.futureEvents(events, time);
const upcomingEvents = sol.distinctEvents(startedEvents.concat(futureEvents));
const upcomingEventsSorted = sol.sortEventsByStartDate(upcomingEvents);
const nextEvents = upcomingEventsSorted.slice(0, max_events);
// Assemble dom
const inner = html`
${header(config)}
${schedule_table(nextEvents, time, config)}
`;
// Add main slide to frame
const anchorElId = "main";
const el = document.getElementById(anchorElId);
preact.render(inner, el);
};
};
export {
update_main_slide
};