   (:require [om.core :as om :include-macros true]
             [sablono.core :as sab :include-macros true]
             [cljs.core.async :refer [chan put! <!] :as async]
+            [clojure.string :refer [join]]
             [netrunner.auth :as auth]
             [netrunner.cardbrowser :as cb]
             [netrunner.ajax :refer [POST GET]]


(om/root deck-builder app-state {:target (. js/document (getElementById "deckbuilder"))})

;; (defn load-deck [data]
;;   (let [cards (:cards @cb/app-state)
;;         decks (for [deck data line (:cards deck)]
;;                 (some #(when (= (:code %) (:card line)) %) cards)
;;                 )]
;;       ;; (swap! app-state assoc :decks data)
;;       (println decks)
;;       ))

(when-not (empty? (:user @auth/app-state))
  (go (swap! app-state assoc :decks (:json (<! (GET (str "/data/decks" (:username user))))))))

  (end-edit owner)
  (let [deck (om/get-state owner :deck)
        cards (for [card (:cards deck)]
                {:qty (:qty card) :card (get-in card [:card :title])})
        data (assoc deck :cards cards)]
    (swap! app-state assoc :decks (conj (:decks @app-state) deck))
    (go (let [response (<! (POST "/data/decks/" data :json))]))))

(defn handle-edit [event owner]
  (let [deck (-> owner (om/get-node "deck-edit") .-value)]
    (om/set-state! owner [:deck :cards] (parse-deck deck))))

(defn decklist-view [{:keys [name identity cards]} owner]
  (om/component
