             [goog.dom :as gdom]
             [om.core :as om :include-macros true]
             [om.dom :as dom :include-macros true]
-            [ago.core :refer [make-ago-world ago-chan ago-timeout ago-snapshot]]
+            [ago.core :refer [make-ago-world ago-chan ago-timeout
+                              ago-snapshot ago-restore]]
             [cbfg.vis :refer [listen-el get-el-value get-el-innerHTML]]
             [cbfg.net :refer [make-net]]
             [cbfg.lane]

            [cbfg.world.lane]
            [cbfg.world.base :refer [world-cmd-loop]]))

(def prog-base    (atom {}))  ; Stable parts of prog.
(def prog-curr    (atom {}))  ; The current prog-frame.
(def prog-hover   (atom nil)) ; A past prog-frame while hovering over prog-history.
(def prog-history (atom []))  ; Each event is [ts label prog-frame agw-snapshot].

(defn prog-init [world]
  (reset! prog-base {:world world

         (map (fn [[k v]] (dom/li nil (str k ":" (count v))))
              prog-frame)))

(defn on-prog-frame-restore [ts label prog-frame]
  ; Time-travel to the past if snapshot is available.
  (when-let [ago-ss (get @prog-ss ts)]
    (reset! prog-curr prog-frame)
    (swap! prog-history #(vec (take (+ ts 1) %)))
    (ago-restore ((:get-agw (first (:world @prog-base)))) ago-ss)))

(defn on-prog-frame-focus [ts label prog-frame]
  (reset! prog-hover prog-frame)
