package de.kif.backend.view

import io.ktor.html.*
import kotlinx.html.*


class TableTemplate(private val classes: String = "") : Template<FlowContent> {

    var searchValue = ""

    val action = Placeholder<FlowContent>()
    val header = Placeholder<TR>()
    val entry = PlaceholderList<TABLE, TR>()

    override fun FlowContent.apply() {
        val c = "table-layout" + if (classes.isEmpty()) "" else " $classes"
        div(c) {
            form(classes = "form-group table-layout-search") {
                div("input-group") {
                    input(InputType.search, name = "search", classes = "form-control") {
                        placeholder = "Search"
                        value = searchValue
                    }
                    button(type = ButtonType.submit, classes = "form-btn btn-search") {
                        i("material-icons") { +"search" }
                    }
                }
            }
            div("table-layout-action") {
                insert(action)
            }

        }
        table("table-layout-table") {
            tr {
                insert(header)
            }
            each(entry) {
                tr {
                    insert(it)
                }
            }
        }
    }
}
