 (ns clj-money.views.imports
   (:require-macros [cljs.core.async.macros :refer [go]])
   (:require [reagent.core :as r]
+            [reagent.ratom :refer [make-reaction]]
             [secretary.core :as secretary :include-macros true]
             [cljs.core.async :refer [timeout
                                      <!]]


(defn- load-import
  [page-state]
  (+busy page-state)
  (imports/get (get-in @page-state [:active :id])
               #(receive-import % page-state)
               (handle-error page-state "Unable to load the import: %s")))

(defn- start-import
  [imp page-state]


(defn- refresh-button
  [page-state]
  (let [busy? (busy page-state)
        css-class (make-reaction #(if @auto-refresh "btn-danger" "btn-success"))
        title (make-reaction #(if @auto-refresh
                                "Click here to stop the auto-refresh."
                                "Click here to auto-refresh the page."))
        icon-image (make-reaction #(if @auto-refresh :stop :arrow-repeat))]
    (fn []
      ; TODO: either don't use busy-button, or change it to allow class, title, and icon to change
      [bs/busy-button {:html {:class @css-class
                              :title @title
                              :on-click (fn []
                                          (swap! auto-refresh not)
                                          (when @auto-refresh
                                            (load-import page-state)))}
                       :icon @icon-image
                       :busy? busy?}])))

(defn- progress-card
  [page-state]
