#_{:clj-kondo/ignore [:unused-namespace]}
(ns auto-ap.core
  (:require [reagent.core :as reagent]
            [reagent.dom :as rdom]
            [re-frame.core :as re-frame]
            [auto-ap.events :as events]
            [auto-ap.views.main :refer [active-page] ]
            [auto-ap.reload :as reload]
            [auto-ap.config :as config]
            [auto-ap.effects :as effects]
            [pushy.core :as pushy]
            [auto-ap.history :as p]
            [bidi.bidi :as bidi]))

#_(set! *warn-on-infer* true)

(defn dev-setup []
  (when true
    (enable-console-print!)
    (println "dev mode enabled")))

(defn mount-root []
  (re-frame/clear-subscription-cache!)
  (rdom/render [active-page]
                  (.getElementById js/document "app")))

(defn ^:export init []
  (dev-setup)
  
  

  
  ;; document.body.addEventListener('htmx:configRequest', function(evt) {
    ;;                                                                   evt.detail.parameters['auth_token'] = getAuthToken(); // add a new parameter into the request
      ;;;;                                                                  evt.detail.headers['Authentication-Token'] = getAuthToken(); // add a new header into the request
          ;;                                                             });
  
  (if-let [jwt (.get (js/URLSearchParams. (.-search (.-location js/window))) "jwt")]
    (do
      (.setItem js/localStorage "jwt" jwt)
      (re-frame/dispatch-sync [::events/initialize-db jwt]))
    (re-frame/dispatch-sync [::events/initialize-db (.getItem js/localStorage "jwt")]))
 (pushy/start! p/history) 
  (mount-root))
  
