 (defn render-card
   ; TODO - Try to avoid the update-card! use and use messages / cursors
   ; * Fix the filter on top of the board to provide cursors down?
-  [card-cursor]
-  (let [card (deref card-cursor)
-        show-details (::show-details card)
-        toggle-details #(update-card! (update-in card [::show-details] not))
+  [card-ref]
+  (let [show-details (::show-details @card-ref)
+        toggle-details #(swap! card-ref update-in [::show-details] not)
         title-style (if show-details :div.card__title--is-open :div.card__title)
         details-style (when-not show-details {:style {:display "none"}})]
-    ;(js/alert (str card))
     [:div.card
-     [:div {:style (card-side-color card)}]
-     [title-style {:on-click toggle-details} (:title card)]
+     [:div {:style (card-side-color @card-ref)}]
+     [title-style {:on-click toggle-details} (:title @card-ref)]
      [:div.card__details details-style
-      (:description card)
-      [render-tasks card]
-      [render-add-task card]
+      (:description @card-ref)
+      [render-tasks card-ref]
+      [render-add-task card-ref]
     ]]
   ))
 

  ; - But you can create the card at the top
  ; - And then you can assemble them (group-by or filter)
  (let [filter (r/cursor app-state [:filter])
        card-ids (filter-by-title @filter (:cards @app-state))
        card-cursors (map #(r/cursor app-state [:cards %1]) card-ids)]
    [:div
     ; TODO - Try to add a button to show details to all tickets
     (render-filter filter)

  ])

(defn render-tasks
  [card-ref]
  (let [on-remove #(swap! card-ref api/remove-task-at %)
        on-check #(swap! card-ref update-in [:tasks % :done] not)]
    [:div.checklist
     [:ul
      (map
        (fn [idx t]
          ^{:key t} [render-task #(on-remove idx) #(on-check idx) t])
        (range) (:tasks @card-ref))]
     ]))

(defn render-add-task
  "Render the text field allowing to add new tasks to a card"
  [card-ref]
  [:input.checklist--add-task
   {:type "text"
    :placeholder "Type then hit Enter to add a task"
    :on-key-press
    (fn [e]
      (when (= "Enter" (.-key e))
        (swap! card-ref api/add-task (.. e -target -value))
        (set! (.. e -target -value) "")
      ))
   }])
