'use strict';

import * as sol from "../../solight/sol.js";

import * as serv from "../services/service.js";


const html = htm.bind(preact.h);


const event_info = (event) =>
    html`
    <div class="speaker-box">
      <div class="speaker">
        <div class="names">${serv.fix_dash(serv.person_names_concat(sol.eventPersons(event)))}</div>
      </div>
    </div>`;


const update_main_slide = (data, time, config) => {
    if (sol.defined(data.scheduleData)) {
        const schedule = data.scheduleData;

        const thisRoom = config.roomName;

        // const dt = luxon.Duration.fromObject({minutes: 5});

        const events = sol.allEvents(schedule);
        const eventsHere = sol.eventsByRoomName(events, thisRoom);

        // const startingEventsHere = sol.startingEvents(eventsHere, time, dt);
        // const currentEventsHere = sol.currentEvents(eventsHere, time);
        // const endedEventsHere = sol.endedEvents(eventsHere, time, dt);
        // const upcomingEventsHere = sol.distinctEvents(startingEventsHere.concat(currentEventsHere, endedEventsHere));

        const upcomingEventsHere = sol.currentEvents(eventsHere, time);

        const inner = html`
        ${upcomingEventsHere.slice(0,1).map(e => event_info(e))}`;

        // Add main slide to frame
        const anchorElId = "main";
        const el = document.getElementById(anchorElId);
        preact.render(inner, el);
    };
};


export {
    update_main_slide
};
