                   name))))))
 
 (defcomponent value-picker [values owner]
-
-  (render-state [_ state]
+  (render-state [_ {:keys [selected-value]}]
     (dom/div
       (dom/h2
         "possible values")
       (dom/ul
-        (for [value values]
-          (dom/li (:name value)))))))
+        (for [{:keys [name value]} values]
+          (dom/li
+            {:on-click (fn [e]
+                         (let [{:keys [pick-channel]} (om/get-shared owner)]
+                           (om/set-state! owner :selected-value value)
+                           (put! pick-channel
+                                 {:selected-value value})))
+             :style    {:font-weight (if (= value selected-value)
+                                       "bold")}}
+            name))))))
 
 (defcomponent slave-fields-picker [ticket-fields owner {:keys [slave-fields-picker-chan]}]
+  (init-state [_]
+    {:selected-slave-fields #{}})
   (will-mount [_]
     (go-loop []
-      (let [{:keys [selected-master-field-id]} (<! slave-fields-picker-chan)]
-        (om/set-state! owner :selected-master-field-id selected-master-field-id)
+      (let [{:keys [selected-master-field-id
+                    wipe-selected-slave-fields]} (<! slave-fields-picker-chan)]
+        (when selected-master-field-id
+          (om/set-state! owner :selected-master-field-id selected-master-field-id))
+        (when wipe-selected-slave-fields
+          (println "wtf")
+          (om/set-state! owner :selected-slave-fields #{}))
         (recur))))
-  (render-state [_ {:keys [selected-master-field-id]}]
+  (render-state [_ {:keys [selected-master-field-id
+                           selected-slave-fields]}]
     (dom/div
       (dom/h2
         "fields to show")
       (dom/ul
-        (for [ticket-field ticket-fields]
-          (if-not (= (:id ticket-field) selected-master-field-id)
-            (dom/li (:name ticket-field))))))))
+        (for [{:keys [name id]} (filter #(not= (:id %) selected-master-field-id)
+                                        ticket-fields)]
+          (dom/li
+            {:on-click (fn [e]
+                         (let [updated-slave-fields
+                               (if (selected-slave-fields id)
+                                 (disj selected-slave-fields id)
+                                 (conj selected-slave-fields id))]
+                           (om/set-state! owner
+                                          :selected-slave-fields
+                                          updated-slave-fields)
+
+                           (let [{:keys [pick-channel]} (om/get-shared owner)]
+                             (println updated-slave-fields)
+                             (put! pick-channel
+                                   {:selected-slave-fields updated-slave-fields}))))
+             :style    {:font-weight (if (selected-slave-fields id)
+                                       "bold")}}
+            name))))))
+
+(defn remove-condition [selected-field selected-value conditions]
+  (set (remove (fn [{:keys [master-field-id value]}]
+                 (and (= master-field-id selected-field)
+                      (= value selected-value)))
+               conditions)))
 
 (defcomponent app [app-state owner]
   (init-state [_]

  (will-mount [_]
    (let [{:keys [pick-channel]} (om/get-shared owner)]
      (go-loop []
        (when-let [{:keys [selected-field-id]} (<! pick-channel)]
          (put! (om/get-state owner :slave-fields-picker-chan)
                {:selected-master-field-id selected-field-id})
          (om/set-state! owner :selected-field-id selected-field-id))
        (recur))))
  (render-state [_ {:keys [selected-field-id slave-fields-picker-chan]}]
    (dom/div
      (om/build master-field-picker (:ticket-fields app-state) {:opts selected-field-id})
      (let [selected-field (first (filter #(= selected-field-id (:id %))

                      {:name "High" :value "high"}
                      {:name "Urgent" :value "urgent"}]}

   {:name            "custom field"
    :id              4321
    :type            :tagger
    :possible-values [{:name "asdfasd" :value "asdfasd"}
                      {:name "12345" :value "12345"}]}
   {:name            "a third field"
    :id              9999
    :type            :tagger
    :possible-values [{:name "value number one" :value "v1"}
                      {:name "value number two" :value "v2"}]}])

(defonce app-state (atom {:ticket-fields dummy-ticket-fields
                          :conditions    #{}}))

(declare render-state)
(declare init-state)
(declare will-mount)

(defcomponent conditions-manager [conditions owner]
  (render-state [_ state]
    (dom/div
      (dom/h2
        "conditions")
      (pr-str conditions))))



(defcomponent master-field-picker [ticket-fields owner]
  (render-state [_ {:keys [selected-field-id]}]
