             [untangled.client.mutations :as m]
             [untangled.client.logging :as log]
             [untangled.client.data-fetch :as df]))
+
+(defn increment-counter [counter] (update counter :counter/n inc))
 
 (defui ^:once Counter
   static uc/InitialAppState

(def ui-counter (om/factory Counter {:keyfn :counter/id}))

(defmethod m/mutate 'counter/inc [{:keys [state] :as env} k {:keys [id] :as params}]
  {:remote true
   :action (fn [] (swap! state update-in [:counter/by-id id :counter/n] inc))})

(defmethod m/mutate 'add-counters-to-panel [{:keys [state] :as env} k {:keys [id] :as params}]
  {:action (fn []
             (let [ident-list (get @state :all-counters)]
               (js/console.log :idents ident-list :state @state)
               (swap! state update-in [:panels/by-kw :counter] assoc :counters ident-list)))})

(defui ^:once CounterPanel

  Object
  (render [this]
    (let [{:keys [counters]} (om/props this)
          click-callback (fn [id] (om/transact! this
                                                `[(counter/inc {:id ~id}) :counter-sum]))]
      (dom/div nil
        ; embedded style: kind of silly in a real app, but doable
        (dom/style nil ".counter { width: 400px; padding-bottom: 20px; }
                        button { margin-left: 10px; }")
        (map #(ui-counter (om/computed % {:onClick click-callback})) counters)))))

(def ui-counter-panel (om/factory CounterPanel))
