 (ns app.app
-  (:require [cljs.core.async :as async :refer [<!]]
+  (:require [cljs.core.async :as async :refer [chan <! >!]]
             [reagent.core :as reagent]
             [kioo.reagent :as kioo]
             [cljs-http.client :as http])

  ;       terms "cardiovascular"]
  ;   (execute-query query-url terms))


  ; (let [{drugs :drugs rationale :rationale recommendation :recommendation
  ;       quality-of-evidence :quality-of-evidence
  ;       strength-of-recommendation :strength-of-recommendation
  ;       evidence :evidence}]

(defsnippet result-card "templates/results.html" [:.card] [result-map]
  {[:.list-column] (kioo/content [:li
                                   [:ul {:class "list-row"}
                                     (map result-data (get result-map :_source))]])})

(deftemplate result-cards "templates/results.html" []
  {[:.card] (map result-card @query-results)})

(deftemplate page "index.html" []
  {[:.search-field] (kioo/listen :on-change #(>!! query-chan .-value))
   [:.results] (kioo/content (result-cards))})

(defn init []
  (reagent/render-component [page] (.-body js/document)))
