package de.kif.frontend.views.board

import de.kif.common.model.Schedule
import de.kif.frontend.views.overview.getByClassOrCreate
import de.westermann.kwebview.View
import org.w3c.dom.HTMLElement
import org.w3c.dom.HTMLSpanElement
import org.w3c.dom.get

class BoardSchedule(
    view: HTMLElement
) : View(view) {
    private val roomView = view.getByClassOrCreate<HTMLSpanElement>("board-schedule-room")
    private val timeView = view.getByClassOrCreate<HTMLSpanElement>("board-schedule-time")
    private val colorView = view.getByClassOrCreate<HTMLSpanElement>("board-schedule-color")
    private val nameView = view.getByClassOrCreate<HTMLSpanElement>("board-schedule-name")

    private var time: Long = timeView.dataset["time"]?.toLongOrNull() ?: 0L

    fun updateTime(now: Long) {
        //console.log(time.toString(), now.toString())
        timeView.textContent = Schedule.timeDifferenceToString(time + now)
    }
}
