(ns wanijo.user.view
  (:require [hiccup.form :as hform]
            [ring.util.anti-forgery :refer [anti-forgery-field]]
            [formulare.core :as form]
            [wanijo.infrastructure.view :as view]
            [wanijo.infrastructure.routing :refer [path]]
            [wanijo.user.db :as domain]))

(def edit-form
  {:fields {:ident {:label "Ident"
                    :required false
                    :spec ::domain/ident}}})

(defn profile! [req user]
  (view/layout
   :session (:session req)
   :content
   [[:h1 "Hi, " (get-in req [:session :ident])]
    (hform/form-to [:post (path :user-edit)]
                   (anti-forgery-field)
                   (form/render-widgets edit-form user req))]))
