 (ns clojure-rest.core
   (:require-macros
+    [clojure-rest.store :refer [def-multi-reducer]]
     [reagent.ratom :refer [reaction]])
   (:require
-    [reagent.core :as r]
     [clojure-rest.api :as api]
     [clojure-rest.fake-data :as fake]
+    [clojure-rest.store :as store]
     [clojure-rest.utils :as utils]
+    [reagent.core :as r]
   ))
 
 ; https://github.com/reagent-project/reagent/blob/master/src/reagent/core.cljs


(defn render-toggle-all
  "[Pure] Render the button to expand all cards" 
  [on-toggle-all]
  (fn []
    [:button.header-button
     {:type "button" :on-click on-toggle-all} "Expand all"]
  ))

(defn render-add-card
  "[Pure] Render the button to expand add a new card" 
  [on-add-card]
  (fn []
    [:button.header-button
     {:on-click on-add-card :type "button"} "Add card"]
  ))

(defn render-app

  (let [filter (r/atom "")
        cards (r/cursor app-state [:cards])
        filtered (reaction (filter-by-title @filter @cards))
        
        card-store (store/reducer-store cards app-reducer)
        card-store-dispatch (store/dispatcher card-store)
        
        card-renderer (render-card card-store-dispatch)
        column-rendered (render-column card-renderer card-store-dispatch)
        board-renderer (render-board column-rendered)]
    (fn []
      [:div
       (render-filter filter)
       [render-add-card card-store-dispatch]
       [render-toggle-all card-store-dispatch]
       [board-renderer @filtered]
      ])
    ))
