      (render-player 1 player1)
      (render-player 2 player2)
      (om/build team-score-component
-               (get report-match (team-selector team-num))
+               (get match-report (team-selector team-num))
                {:opts {:score-ch score}})]))
 
 (defn matchdate-component [matchdate owner {:keys [change-ch]}]

            (render-team 2 team2)]

           (om/build matchdate-component
                     (:matchdate report-match)
                     {: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))}
                     (when-not enabled? {:disabled "disabled"}))
              "Report Match Result " [: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
                      :active-players (filterv :active players)})})
    (spinner)))

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

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

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

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

(defn handle-matchdate-update [match-report path js-date]
  (let [matchdate (dc/to-date-time js-date)]
    (om/update! match-report 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 match-report}]
  (and (valid-team-to-report? team1)
       (valid-team-to-report? team2)
       matchdate))

(defn submit-report! [match-report]
  (let [id (uuid/make-random-uuid)
        {:keys [team1 team2 matchdate]} @match-report
        report {:team1 team1
                :team2 team2
                :matchdate matchdate
                :id id
                :status :pending}]
    (debug "doing submit" report)
    (om/transact! match-report
                  (fn [mr] (merge mr {:submitting report})))))

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