package dev.fyloz.plannervio.ui

import dev.fyloz.plannervio.core.repository.IBoardRepository
import dev.fyloz.plannervio.core.repository.memory.MemoryBoardRepository
import dev.fyloz.plannervio.core.service.BoardServiceImpl
import dev.fyloz.plannervio.core.service.IBoardService
import dev.fyloz.plannervio.ui.style.Style
import dev.fyloz.plannervio.ui.view.MainView
import mu.KLogger
import mu.KotlinLogging
import org.kodein.di.DI
import org.kodein.di.DIAware
import org.kodein.di.bind
import org.kodein.di.singleton
import org.kodein.di.tornadofx.installTornadoSource
import tornadofx.App
import tornadofx.launch
import tornadofx.loadFont
import tornadofx.reloadStylesheetsOnFocus

fun main(args: Array<String>) {
    launch<Plannervio>(args)
}

val logger: KLogger by lazy {
    System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "trace")
    KotlinLogging.logger(Plannervio::class.simpleName!!)
}

class Plannervio : App(MainView::class, Style::class), DIAware {
    override val di: DI
        get() = DI {
            installTornadoSource()

            bind<IBoardRepository>() with singleton { MemoryBoardRepository() }
            bind<IBoardService>() with singleton { BoardServiceImpl(di) }
        }

    init {
        loadFonts()
        reloadStylesheetsOnFocus()
    }

    private fun loadFonts() {
        loadFont("/fonts/biryani/Biryani-Regular.ttf", 12)
        loadFont("/fonts/biryani/Biryani-DemiBold.ttf", 12)
    }
}
