 (ns clj-gamification.handler
-  (:use compojure.core
-;;        ring.middleware.session.store ;; TODO delete
-        )
-;;  (:import java.util.UUID) ;; TODO rm
+  (:use compojure.core)
   (:require [compojure.handler :as handler]
             [compojure.route :as route]
             [hiccup.page :refer [html5 include-js]]

  (or
   (:voted? session)))

(defn show-page-for-step [{:keys [teams state]}
                          {:keys [remote-addr session] :as req}]
  "Show the right page for the current stage: gamemaster, team registr., voting"
  (let [first-visitor? (compare-and-set! state :not-started :brainstorming)
        gm? (:gamemaster? session)]
   (cond
    (or gm? first-visitor?) (do
                              (info (str "GM access; first? " first-visitor? ", session id" (-> req :cookies (get "ring-session") :value) ", ip " (:remote-addr req) ", sess " session))
                              {:session {:gamemaster? true},
                              :body (page-gamemaster)})
    (= @state :brainstorming) (page-team-registration)

  ([defaults]
     (let [system (system defaults)]
       (swap! current-system-for-repl (constantly system))
       (-> (handler/site (make-app-routes system)
                         {:session {:store (memory-store (:session-atom system))}})
           (wrap-bootstrap-resources)
           (wrap-file-info)))))

