(ns auto-ap.history
  (:require [bidi.bidi :as bidi]
            [pushy.core :as pushy]
            [auto-ap.routes :as routes]
            [auto-ap.views.utils :as u]
            [re-frame.core :as re-frame]))

(defn parse-url [url]
  (println "parsing url" url)
  (bidi/match-route routes/routes url))

(defn dispatch-route [matched-route]
  (println "Matched route" matched-route)
  (re-frame/dispatch [:auto-ap.events/set-active-route (:handler matched-route) (u/query-params) (:route-params matched-route)]))


(def history (pushy/pushy dispatch-route parse-url))
