   (:require [reagent.core :as r]
             [ajax.core :refer [GET PUT]]))
 
-(def state (r/atom {:server "http://localhost:8080"
-                    :playlist []
+(def state (r/atom {:playlist []
                     :tracks []
                     :query ""}))
 

  (swap! state assoc k value))

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

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

(defn enqueue-track [track]
  (let [uuid (track "uuid")]
    (PUT (str (@state :server) "/api/enqueue/" uuid))))

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

(defn server-form []
  [:form
   [:input {:type "text"
            :value (@state :server)
            :on-change #(update-state! :server
                                       (-> % .-target .-value))}]])

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


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

