 (defn build-main []
   (om/root alert-list app-state {:target app-root}))
 
-
 (defn main []
   (current-alerts)
   (build-main))

       {:response-format :json
        :keywords? true
        :handler callback}))


(defn ajax-post [url params callback]

             #(swap! app-state assoc :alerts
                     (get-in % [:aggregations :current-alerts :buckets]))))


(defn alert-history [id cb]
  (ajax-post "http://localhost:9250/.watch_history*/_search"
             {:filter {:term {:watch_id id}}}
             cb))

(def app-root (. js/document (getElementById "app")) )


(declare build-main)


(defcomponent alert-history-item [{{{:keys [execution_time]} :result} :_source}
                                  _]
  (render [_]
    (dom/tr
     (dom/td (tfmt/unparse
              (tfmt/formatter "MM/dd/YYYY hh:mm:ss a")
              (tfmt/parse (tfmt/formatters :date-time)  execution_time))))))

(defcomponent alert-detail [{:keys [history]} _]
  (render [_]
    (dom/div
     (dom/h2 {:class "subheader"} "Alert Detail")
     (dom/table
      (om/build-all alert-history-item history))
     (dom/a {:href "#"
             :onClick #(build-main)} "Back"))))

