package de.kif.frontend.views

import de.kif.frontend.launch
import de.kif.frontend.repository.AnnouncementRepository
import org.w3c.dom.HTMLElement
import org.w3c.dom.get
import kotlin.browser.document

fun initAnnouncement() {
    val announcement = document.getElementsByClassName("announcement")[0] as? HTMLElement ?: return
    val span = announcement.children[0] as? HTMLElement ?: return

    AnnouncementRepository.onUpdate {
        launch {
            val text = AnnouncementRepository.getAnnouncement()

            announcement.classList.toggle("announcement-blank", text.isBlank())
            span.textContent = text
        }
    }
}
