(ns auto-ap.views.pages
  (:require-macros [cljs.core.async.macros :refer [go]])
  (:require [re-frame.core :as re-frame]
            [reagent.core :as reagent]
            [auto-ap.subs :as subs]
            [auto-ap.events :as events]
            [auto-ap.views.pages.login :refer [login-page]]
            [auto-ap.views.pages.index :refer [index-page]]
            [auto-ap.views.pages.admin :refer [admin-page]]
            [auto-ap.views.pages.needs-activation :refer [needs-activation-page]]
            [auto-ap.views.pages.check :refer [check-page]]
            [auto-ap.views.pages.admin.companies :refer [admin-companies-page]]
            [auto-ap.views.pages.admin.users :refer [admin-users-page]]
            [auto-ap.views.pages.admin.vendors :refer [admin-vendors-page]]
            [auto-ap.views.pages.admin.reminders :refer [admin-reminders-page]]
            [auto-ap.views.pages.unpaid-invoices :refer [unpaid-invoices-page]]
            [auto-ap.views.pages.new-invoice :refer [new-invoice-page]]
            [auto-ap.views.pages.import-invoices :refer [import-invoices-page]]
            [auto-ap.views.pages.admin.excel-import :refer [admin-excel-import-page]]
            [auto-ap.views.pages.paid-invoices :refer [paid-invoices-page]]
            [cljs.reader :as edn]
            [cljsjs.dropzone :as dz]
            [auto-ap.routes :as routes]
            [bidi.bidi :as bidi]
            [cljs-http.client :as http]
            [cljs.core.async :refer [<!]]))


(defmulti active-page identity)

(defmethod active-page :login []
  login-page)

(defmethod active-page :index []
  index-page)

(defmethod active-page :admin []
  [admin-page])

(defmethod active-page :needs-activation []
  [needs-activation-page])

(defmethod active-page :check []
  [check-page])

(defmethod active-page :admin-companies []
  [admin-companies-page])

(defmethod active-page :admin-vendors []
  [admin-vendors-page])

(defmethod active-page :admin-reminders []
  [admin-reminders-page])

(defmethod active-page :admin-excel-import []
  [admin-excel-import-page])

(defmethod active-page :admin-users []
  [admin-users-page])

(defmethod active-page :unpaid-invoices []
  [unpaid-invoices-page])

(defmethod active-page :paid-invoices []
  [paid-invoices-page])

(defmethod active-page :invoices []
  [(with-meta
     (fn []
       [:div
        [:h1.title "All invoices"]])
     {:component-did-mount (fn []
                             (go
                               (re-frame/dispatch [::events/received-invoices (:body (<! (http/get "/api/invoices")))])))})])

(defmethod active-page :import-invoices []
  [import-invoices-page])


(defmethod active-page :new-invoice [] new-invoice-page)
