 
 (defn home-page []
   [:div [:h1 "Airhead"]
-   [server-form]
    [playlist-div]
    [tracks-div]])
 

  (:require [reagent.core :as r]
            [ajax.core :refer [GET PUT]]))

(def state (r/atom {:server "http://localhost:8080"
                    :playlist []
                    :tracks []
                    :query ""}))


  (swap! state assoc k value))

(defn get-playlist []
  (GET "/api/queue"
       {:handler #(update-state! :playlist (% "items"))
        :response-format :json}))

(defn get-tracks []
  (GET "/api/tracks"
       {:params {:q (@state :query)}
        :handler #(update-state! :tracks (% "items"))
        :response-format :json}))

(defn enqueue-track [track]
  (let [uuid (track "uuid")]
    (PUT (str "/api/enqueue/" uuid))))

;; -------------------------
;; Views

(defn track-span [track]
  (str (track "artist") " - " (track "title")))
