 ;;              [{:competitor/name "Ringo Stingo" :competitor/number 20, :competitor/club "Kapangg"}
 ;;               {:competitor/name "Greve Turbo", :competitor/number 21, :competitor/club "OOoost"}]}]}]}))
 
-(defonce app-state
-  (atom {:competitions []}))
+;; TODO - Let the server return dancers in a UI-normalized way
+(defn get-dancers [competitions]
+  (into #{}
+        (map #(dissoc % :competitor/number) 
+             (for [competition competitions
+                   classes (:competition/classes competition)
+                   competitors (:class/competitors classes)]
+               competitors))))
 
 (defonce component-state
   (atom {:competitions-visible false}))
 
-;(def app-state (atom []))
-
-(defn competitor-component [competitors]
+(defn competitor-component [competitors include-number?]
   [:div ""
    [:ul
     (for [competitor competitors]
       ^{:key competitor}
-      [:li
-       (str "Competitor number: "
-            (:competitor/number competitor)
-            " - "
-            (:competitor/name competitor)
-            " / "
-            (:competitor/club competitor))])]])
+      [:li 
+       (str (if include-number?
+              (str "Tävlande nummer : " (:competitor/number competitor) " - "))
+            (str (:competitor/name competitor)
+                 " från "
+                 (:competitor/club competitor)))])]])
 
 (defn class-component [classes]
   [:h3 "Classes"]
   [:div
    (for [cls classes]
-     ^{:key cls} [:div
-                  (:class/name cls)
-                  [competitor-component (:class/competitors cls)]
-                  ])])
-
-;; (defn competition-component []
-;;   [:div
-;;    [:h2 "Competition"]
-;;    [:h3 (str "Name :" (:competition/name @app-state)) ]
-;;    [:h3 (str "Date :" (:competition/date @app-state)) ]
-;;    [:h3 (str "Location :" (:competition/location @app-state))]
-;;    [:h3 (str "Classes :")] 
-;;    [class-component (:competition/classes @app-state)]])
-
-;(defn competition-component [])
+     ^{:key cls}
+     [:div
+      (:class/name cls)
+      [competitor-component (:class/competitors cls) true]])])
 
 (defn competition-item []
   (let [open (atom false)]

      ^{:key competition} [competition-item competition])]
   [:h2 "Importera en ny tävling : "]
   [:input.btn.btn-default {:type "file" :value "Import file"
                            :onChange #(on-click-import-file %)}]
   ])

(defn menu-component []
  (let [visible-component (atom :competitions;:none
                   )]
    (fn []
      [:div.container
       [:div.header

         {:type "button" :value "Domare" :on-click #(reset! visible-component :adjudicators)}]
        ;[:h2 (str "visible-component " @visible-component)]
        ]
       (condp = @visible-component
         :competitions [import-component]
         :competitors [competitors-component]
         :adjudicators [:div]
         :none [:div])
       ])))

(defn ^:export run []
  (reagent/render-component [menu-component] (.-body js/document)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Socket handling
