                    [plumbing.core :refer [fnk]]
                    [lens.macros :refer [h]])
   (:require [cljs.core.async :as async]
+            [cljs.reader :as reader]
             [om.core :as om :include-macros true]
             [om-tools.core :refer-macros [defcomponent]]
             [om-tools.dom :as d :include-macros true]

        (condp = (:type term)
          :form (om/build form term {:opts opts})
          :item-group (om/build item-group term {:opts opts})
          :item (om/build item term {:opts opts})))
      (d/div {:class "query-col-or-badge text-muted"} "OR"))))

(defn show-item-dialog! [owner query-idx col-idx]

  (-> (update-in query [:query-grid :cols] #(vec (map-indexed assoc-idx %)))
      (assoc :idx idx)))

(defn resolve-code-list-item-ids [query]
  (update-in
    query [:query-grid :cols]
    (fn [cols]
      (mapv
        (fn [col]
          (update-in
            col [:cells]
            (fn [cells]
              (mapv
                (fn [{:keys [type] :as cell}]
                  (println :resolve :id :in cell)
                  (if (= :code-list-item type)
                    (update-in cell [:id] (fn [id] (println id) (reader/read-string id)))
                    cell))
                cells))))
        cols))))

(defn assoc-default-results [query]
  (assoc query :vc-by-se-result {} :vc-by-ad-result {}))

(defn prepare-queries [queries]
  (->> (map-indexed index-query queries)
       (map resolve-code-list-item-ids)
       (mapv assoc-default-results)))

(defn prepare-version
