             (render-team 2 team2)]
 
            (om/build matchdate-component
-                     (:matchdate report-match)
+                     (:matchdate match-report)
                      {:opts {:change-ch matchdate}})
 
            [:div.form-group.col-lg-12
             [:div.form-group.col-lg-5.pull-right
              [:button.btn.btn-primary.btn-lg.btn-block
-              (merge {:on-click (fn [e] (submit-report! @report-match))}
+              (merge {:on-click (fn [e] (submit-report! match-report))}
                      (when-not enabled? {:disabled "disabled"}))
-              "Report Match Result " [:span.glyphicon.glyphicon-ok]]]]]])))))
+              "Report Match Result " (if submitting
+                                       [:span.glyphicon.glyphicon-time]
+                                       [:span.glyphicon.glyphicon-ok])]]]]])))))
 
 (defn render [app]
   (if (:auth app)
-    (om/build report-match-component app
-              {:fn (fn [{:keys [report-match players]}]
-                     {:report-match   report-match
+    (om/build match-report-component app
+              {:fn (fn [{:keys [match-report players]}]
+                     {:match-report   match-report
                       :active-players (filterv :active players)})})
     (spinner)))

(defn valid-score? [this other]
  (:team1score (vm/validate-scores [this other])))

(defn update-score! [report-match team score other-score]
  (let [valid-score? (valid-score? score other-score)]
    (om/transact! report-match team (fn [v] (merge v
                                                  {:score score}
                                                  {:valid-score? valid-score?})))))

(defn handle-score-update [report-match [team _] [type val]]
  (when (= :foosball.editable/blur type)
    (if-let [score (c/->int val)]
      (let [other (other-team team)
            other-score (get-in @report-match [other :score])]
        (update-score! report-match team score other-score)
        (when other-score
          (update-score! report-match other other-score score))))))

(defn handle-player-update [report-match path player]
  (om/update! report-match path player))

(defn handle-matchdate-update [report-match path js-date]
  (let [matchdate (dc/to-date-time js-date)]
    (om/update! report-match path matchdate)))

(defn valid-team-to-report? [{:keys [player1 player2 valid-score?]}]
  (and player1 player2 valid-score?))

(defn valid-report? [{:keys [team1 team2 matchdate] :as report-match}]
  (and (valid-team-to-report? team1)
       (valid-team-to-report? team2)
       matchdate))

(defn submit-report! [{:keys [team1 team2 matchdate] :as report-match}]
  (let [id (uuid/make-random-uuid)
        report {:team1 team1
                :team2 team2
                :matchdate matchdate
                :id id
                :status :pending}]
    (debug "submitting" report)
    (om/transact! report-match :submits (fn [s] (if s
                                                 (conj s report)
                                                 [report])))))

(defn report-match-component [{:keys [active-players report-match submits] :as app} owner]
  (reify
    om/IInitState
    (init-state [_]

        (when-not (@app :players)
          (data/go-update-data! "/api/players" app :players))
        (let [empty-team {:player1 nil :player2 nil :score nil :valid-score? true}]
          (om/transact! app [:match-report] (fn [rm] (merge rm
                                                           {:team1 empty-team
                                                            :team2 empty-team
                                                            :matchdate (tc/now)}))))
