             [untangled.client.core :as uc]
             [untangled.client.mutations :as m]))
 
+(declare add-phone-mutation ValidatedPhoneForm)
+
 (defn field-with-label
   "A non-library helper function, written by you to help lay out your form."
   ([comp form name label] (field-with-label comp form name label nil))


(defui ValidatedPhoneRoot
  static om/IQuery
  (query [this] [{:phone (om/get-query ValidatedPhoneForm)}])
  static uc/InitialAppState
  (initial-state [this params]
    (let [phone-number {:db/id 1 :phone/type :home :phone/number "555-1212"}]


(defn add-phone-mutation [{:keys [state]} k {:keys [id person]}]
  {:action (fn []
             (let [new-phone (uc/initial-state ValidatedPhoneForm {:db/id id :phone/type :home :phone/number ""})
                   person-ident [:people/by-id person]
                   phone-ident (om/ident ValidatedPhoneForm new-phone)]
               (swap! state assoc-in phone-ident new-phone)
               (uc/integrate-ident! state phone-ident :append (conj person-ident :person/phone-numbers))))})

