package be.simplenotes.app.views import be.simplenotes.app.extensions.summary import be.simplenotes.app.utils.StaticFileResolver import be.simplenotes.app.views.components.Alert import be.simplenotes.app.views.components.alert import be.simplenotes.app.views.components.input import be.simplenotes.domain.security.JwtPayload import io.konform.validation.ValidationError import kotlinx.html.* import kotlinx.html.ButtonType.submit class SettingView(staticFileResolver: StaticFileResolver) : View(staticFileResolver) { fun settings( jwtPayload: JwtPayload, error: String? = null, validationErrors: List = emptyList(), ) = renderPage("Settings", jwtPayload = jwtPayload) { div("container mx-auto") { section("m-4 p-4 bg-gray-800 rounded") { h1("text-xl") { +"Welcome " span("text-teal-200 font-semibold") { +jwtPayload.username } } } section("m-4 p-4 bg-gray-800 rounded") { p(classes = "mb-4") { +"Export all my data" } form(method = FormMethod.post, action = "/export") { button(name = "display", classes = "inline btn btn-teal block", type = submit) { +"Display my data" } button(name = "download", classes = "inline btn btn-green block ml-2 mt-2", type = submit) { +"Download my data" } } } section(classes = "m-4 p-4 bg-gray-800 rounded") { h2(classes = "mb-4 text-red-400 text-lg font-semibold") { +"Delete my account" } error?.let { alert(Alert.Warning, error) } details { if (error != null || validationErrors.isNotEmpty()) { attributes["open"] = "" } summary { span(classes = "mb-4 font-semibold underline") { +"Are you sure? " +"You are about to delete this user, and this process is irreversible !" } } form(classes = "mt-4", method = FormMethod.post) { input( id = "password", placeholder = "Password", autoComplete = "off", type = InputType.password, error = validationErrors.find { it.dataPath == ".password" }?.message ) checkBoxInput(name = "checked") { id = "checked" attributes["required"] = "" label { attributes["for"] = "checked" +" Do you want to proceed ?" } } button( type = submit, classes = "block mt-4 btn btn-red", name = "delete" ) { +"I'm sure" } } } } } } }