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.BackgroundImageService
import dev.fyloz.plannervio.core.service.BoardService
import dev.fyloz.plannervio.core.service.IBackgroundImageService
import dev.fyloz.plannervio.core.service.IBoardService
import dev.fyloz.plannervio.ui.style.Style
import dev.fyloz.plannervio.ui.view.MainView
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<TodosApp>(args)
}

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

            bind<IBoardRepository>() with singleton { MemoryBoardRepository() }
            bind<IBoardService>() with singleton { BoardService(di) }
            bind<IBackgroundImageService>() with singleton { BackgroundImageService() }
        }

    init {
        loadFonts()
        reloadStylesheetsOnFocus()
    }

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