 
 (defn handle-layout-change
   [layout]
-  (-> (optimize-layout layout)
+  (.log js/console "layout changed")
+  (-> (optimize-layout layout (get-card-deps))
       apply-layout))
 
 (defn listen-drag

      (gdom/removeChildren card-list)
      (doseq [card cards] (gdom/appendChild card-list card)))))

(defn get-layout-score
  [layout]
  0)

(defn better-score
  [left right]

     (fn [[ungrouped grouped]]
       [column-id
        (reduce into []
                (concat
                 (interleave ungrouped grouped)
                 (drop (count grouped) ungrouped)))])
     (cartesian-product [ungrouped-slices grouped-permutations]))))

(defn layout-permuations
  [layout card-deps]
  (->> (map (partial column-permutations card-deps) layout)
       cartesian-product
       (map (partial into {}))))

(defn optimize-layout
  [layout card-deps]
  (let [permutations (layout-permuations layout card-deps)]
    (transduce
     (map (fn [layout] [(get-layout-score layout card-deps) layout]))
     (fn
       ([final]
          (second final))
       ([best current]
          (if best
            (let [[best-score _] best
                  [current-score l] current]
              (if (better-score current-score best-score)
                current
                best))
