(ns auto-ap.views.main
  (:require
   [re-frame.core :as re-frame]
   [bidi.bidi :as bidi]
   [auto-ap.routes :as routes]
   [auto-ap.subs :as subs]
   [auto-ap.events :as events]
   [auto-ap.views.utils :refer [active-when active-when= login-url dispatch-event]]
   [auto-ap.views.components.layouts :refer [side-bar-layout]]
   [auto-ap.views.pages.unpaid-invoices :refer [unpaid-invoices-page]]
   [auto-ap.views.pages.import-invoices :refer [import-invoices-page]]
   [auto-ap.views.pages.paid-invoices :refer [paid-invoices-page]]
   [auto-ap.views.pages.needs-activation :refer [needs-activation-page]]
   [auto-ap.views.pages.transactions :refer [transactions-page]]
   [auto-ap.views.pages.login :refer [login-page]]
   [auto-ap.views.pages.checks :refer [checks-page]]
   [auto-ap.views.pages.admin :refer [admin-page]]
   [auto-ap.views.pages.home :refer [home-page]]
   [auto-ap.views.pages.admin.clients :refer [admin-clients-page]]
   [auto-ap.views.pages.admin.vendors :refer [admin-vendors-page]]
   [auto-ap.views.pages.admin.excel-import :refer [admin-excel-import-page]]
   [auto-ap.views.pages.admin.users :refer [admin-users-page]]
   [auto-ap.views.pages.admin.yodlee :refer [admin-yodlee-page]]
   [auto-ap.entities.clients :as clients]
   [auto-ap.views.components.vendor-dialog :refer [vendor-dialog]]))

(defmulti page (fn [active-page] active-page))
(defmethod page :unpaid-invoices [_]
  (unpaid-invoices-page {:status "unpaid"}))

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


(defmethod page :paid-invoices [_]
  (unpaid-invoices-page {:status "paid"}))

(defmethod page :voided-invoices [_]
  (unpaid-invoices-page {:status "voided"}))


(defmethod page :checks [_]
  (checks-page))

(defmethod page :transactions [_]
  (transactions-page))

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

(defmethod page :admin-clients [_]
  (admin-clients-page))

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

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

(defmethod page :admin-yodlee [_]
  (admin-yodlee-page))

(defmethod page :index [_]
  (home-page)
  )

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

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


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

(defn active-page []
  (let [ap (re-frame/subscribe [::subs/active-page])]
    [:div
     ^{:key @ap} [page @ap]]))
