 (ns sitetools.core
   (:require [clojure.string :as string]
             [goog.events :as evt]
-            [goog.history.EventType :as hevt]
             [reagent.core :as r]
             [reagent.debug :refer-macros [dbg log dev?]]
             [reagent.interop :as i :refer-macros [.' .!]])
   (:import goog.History
-           goog.history.Html5History))
-
-(when (exists? js/console)
-  (enable-console-print!))
+           [goog.history Html5History EventType]))
+
+(enable-console-print!)
 
 (defn rswap! [a f & args]
   ;; Like swap!, except that recursive swaps on the same atom are ok,

  (case id
    :set-content (let [page x
                       title (:title page)
                       _ (assert (vector? (:content page)))
                       title (if title
                               (str (:title-prefix state) title)
                               (str (:default-title state)))
                       page (assoc page :title title)]
                   (when r/is-client
                     (set! js/document.title title))
                   (assoc state :current-page page))
    :set-page (let [path x
                    _ (assert (string? path))
                    ps (:pages state)

       [:meta {:charset 'utf-8}]
       [:meta {:name 'viewport
               :content "width=device-width, initial-scale=1.0"}]
       [:base {:href (-> page-conf :page-path base)}]
       [:link {:href (str css-file timestamp) :rel 'stylesheet}]
       [:title title]]
      [:body
       [:div {:id main-div} (danger :div body-html)]
       (danger :script (str "var pageConfig = "
                            (-> page-conf clj->js js/JSON.stringify)))
       [:script {:src main :type "text/javascript"}]]])))

(defn gen-page [page-path conf]
  (dispatch [:set-page page-path])
  (let [conf (merge conf @config)
        b (:body conf)
        bhtml (r/render-component-to-string b)]
    (str "<!doctype html>\n"
         (html-template (assoc conf
                               :page-conf {:page-path page-path}
                               :body-html bhtml)))))

(defn fs [] (js/require "fs"))
