package pl.treksoft.kvision import com.lightningkite.kotlin.observable.list.observableListOf import pl.treksoft.kvision.basic.Label import pl.treksoft.kvision.core.* import pl.treksoft.kvision.data.DataComponent import pl.treksoft.kvision.data.DataContainer import pl.treksoft.kvision.dropdown.DD.* import pl.treksoft.kvision.dropdown.DropDown import pl.treksoft.kvision.form.Form import pl.treksoft.kvision.form.FormPanel import pl.treksoft.kvision.form.INPUTSIZE import pl.treksoft.kvision.form.bool import pl.treksoft.kvision.form.check.CheckBox import pl.treksoft.kvision.form.check.Radio import pl.treksoft.kvision.form.check.RadioGroup import pl.treksoft.kvision.form.date import pl.treksoft.kvision.form.select.AjaxOptions import pl.treksoft.kvision.form.select.SELECTWIDTHTYPE import pl.treksoft.kvision.form.select.Select import pl.treksoft.kvision.form.select.SelectInput import pl.treksoft.kvision.form.select.SelectOptGroup import pl.treksoft.kvision.form.select.SelectOption import pl.treksoft.kvision.form.spinner.FORCETYPE import pl.treksoft.kvision.form.spinner.Spinner import pl.treksoft.kvision.form.spinner.SpinnerInput import pl.treksoft.kvision.form.string import pl.treksoft.kvision.form.text.Password import pl.treksoft.kvision.form.text.RichText import pl.treksoft.kvision.form.text.TEXTINPUTTYPE import pl.treksoft.kvision.form.text.Text import pl.treksoft.kvision.form.text.TextArea import pl.treksoft.kvision.form.text.TextAreaInput import pl.treksoft.kvision.form.text.TextInput import pl.treksoft.kvision.form.time.DateTime import pl.treksoft.kvision.form.time.DateTimeInput import pl.treksoft.kvision.html.* import pl.treksoft.kvision.html.TAG.DIV import pl.treksoft.kvision.html.TAG.H1 import pl.treksoft.kvision.modal.Alert import pl.treksoft.kvision.modal.Confirm import pl.treksoft.kvision.modal.Modal import pl.treksoft.kvision.panel.* import pl.treksoft.kvision.routing.routing import pl.treksoft.kvision.snabbdom.obj import pl.treksoft.kvision.utils.perc import pl.treksoft.kvision.utils.px import pl.treksoft.kvision.utils.toDateF import kotlin.js.Date class Showcase : ApplicationBase() { override fun start(state: Map) { data class DataForm(val a: String?, val b: Boolean?, val c: Date?) val f = DataForm("ala", true, Date()) val form = Form { DataForm(it.string("a"), it.bool("b"), it.date("c")) } form.add("a", Text()) form.add("b", CheckBox()) form.add("c", DateTime()) form.setData(f) val ret = form.getData() console.log(ret) class DataFormMap(map: Map) { val name: String by map val age: Date by map } val fm = DataFormMap(mapOf("name" to "Ala", "age" to Date())) val formm = Form { DataFormMap(it) } formm.add("name", Text()) formm.add("age", DateTime()) formm.setData(fm) val retm = formm.getData() console.log(retm.name) console.log(retm.age) val root = Root("showcase") class Model(p: Boolean, t: String) : DataComponent() { var p: Boolean by obs(p) var t: String by obs(t) } val model = observableListOf(Model(true, "Pierwszy"), Model(false, "Drugi"), Model(false, "Trzeci")) val datac = DataContainer(model, { element, index -> CheckBox(value = element.p, label = if (element.p) "" + (index + 1) + " " + element.t + "" else element.t, rich = true).setEventListener({ click = { element.p = self.value } }) }) root.add(datac) val mbutton = Button("Pokaż wartości").setEventListener