(ns wanijo.instance.view.bulk-link-selection
  (:require [hiccup.form :as hform]
            [hiccup.core :refer [h]]
            [wanijo.infrastructure.view :as view]
            [wanijo.infrastructure.routing :refer [path]]
            [formulare.core :as form]
            [ring.util.anti-forgery :refer [anti-forgery-field]]))

(defn bulk-link-selection [instance forms req]
  (clojure.pprint/pprint forms)
  (view/layout
    :request req
    :content
    [[:h1
      [:small "Link " (-> instance :schema :name h) " "]
      (h (:name instance))
      [:small " with..."]]
     (hform/form-to
       [:post (path :instance-bulk-link-create instance)]
       (anti-forgery-field)
       (for [{:keys [schema form]} forms]
         [:fieldset
          [:legend "Schema " [:strong (-> schema :name h)]]
          (form/render-widgets form
                               nil
                               req
                               {:render-anti-forgery-field? false})])
       (hform/submit-button "Link!"))]))
