 (ns gtfve.maps
   (:require-macros [cljs.core.async.macros :refer [go go-loop]])
-  (:require [reagent.core :as r :refer [atom]]
-            [secretary.core :as secretary :include-macros true]
+  (:require [om.core :as om]
+            [sablono.core :as html :refer-macros [html]]
             [cljs.core.async :as async :refer [put! chan <! close!]]
             [goog.events :as events]
             [goog.history.EventType :as EventType]

      :component-function (fn [state]
                            [:div {:id :map-canvas
                                   :style {:height "100%"
                                           :margin 0
                                           :padding 0}}
                             (doall
                              (for [{id :route/id
                                     :as route-data} (:routes @state)]

                                      :strokeOpacity 1.0
                                      :strokeWeight 2}))))

(defn map-object [data owner]
  (reify
    om/IRender
    (render [_]
      [:noscript])
    om/IInitState
    (init-state [_]
      (let [{:keys [class opts]} data]
        {:object (class. (clj->js opts))}))
    om/IDidMount
    (did-mount [_]
      (let [{:keys [opts gmap]} data
            object (om/get-state owner :object)]
        (->> {:map gmap}
             (merge opts)
             (clj->js)
             (.setOptions object))))
    om/IDidUpdate
    (did-update [_ _ _]
      (let [{:keys [opts gmap]} data
            object (om/get-state owner :object)]
        (->> {:map gmap}
             (merge opts)
             (clj->js)
             (.setOptions object))))
    om/IWillUnmount
    (will-unmount [_]
      (let [object (om/get-state owner :object)]
        (.setMap object nil)))))

(defn e-map [data owner]
  (reify
    om/IDidMount
    (did-mount [_]
      (let [{:keys [opts]} data
            node (om/get-node owner)]
        (om/set-state! owner :gmap (Maps.Map. node (clj->js opts)))))
    om/IRenderState
    (render-state [_ state]
      (html [:div {:id :map-canvas}]))))

(defn map-listen
  "Return a channel listening on events of type in obj."
