   (:require [om.core :as om :include-macros true]
             [om.dom :as dom :include-macros true]
             [chord.client :refer [ws-ch]]
-            [cljs.core.async :as a]
+            [cljs.core.async :refer [chan <! >! put!] :as a]
             [sablono.core :as html :refer-macros [html]])
   (:require-macros [cljs.core.async.macros :refer [go]]))
 

(def sample-translation {:topic "German" :language "German" :content "Guten Tag"
                         :original-sha "XYZ" :content-sha "ABC" :user-name "bob"})

(def app-state (atom {:original [sample-source]
                      :translated [sample-translation]}))

(defn chat-view [app owner]
  (reify


(defn master-view [app owner]
  (reify
    om/IInitState
    (init-state [_]
      (let [listener-ch (chan)
            sender-ch (chan)]
        (make-socket listener-ch sender-ch)
        {:listener-ch listener-ch
         :sender-ch sender-ch
         :text ""}))
    om/IWillMount
    (will-mount [_]
      (let [listener-ch (om/get-state owner :listener-ch)
            sender-ch (om/get-state owner :sender-ch)]
        (go (loop []
              (let [msg (<! listener-ch)]
                ;; do something cool with the message
                (recur))))))
    om/IRenderState
    (render-state [this {:keys [sender-ch text] :as state}]
      (dom/div #js {:className "container"}
               (dom/h3 nil "Enter Chat stuff")
               (dom/div #js {:className "form-horizontal"}
                         (dom/div nil
                                  (dom/div nil
                                           (om/build users-view (:users app)))
                                  (dom/div nil
                                           (om/build chat-view (:original app)))
                                  (dom/div nil
                                           (om/build chat-view (:translated app))))
                         (dom/div #js {:className "form-group"}
                                  (dom/input #js {:className "form-control" :type "text"
                                                  :value text
                                                  :onKeyPress (fn [e] (check-for-enter e owner state))
                                                  :onChange #(text-entry % owner state)}))
                         (dom/div #js {:className "col-xs-offset-2 col-xs-10"}
                                  (dom/button #js {:type "button" :className "button"
                                                   :onClick (fn [e] (do
                                                                     (post-message sender-ch text)
                                                                     (clear-text owner))
                                                              )}
                                              "click me")))))))

(om/root
