(ns auto-ap.ssr.login-dropdown
  (:require
   [auto-ap.client-routes :as client-routes]
   [auto-ap.ssr.components.navbar-dropdown :refer [navbar-dropdown]]
   [bidi.bidi :as bidi]
   [hiccup2.core :as hiccup]
   [auto-ap.ssr-routes :as ssr-routes]))

(defn dropdown [{:keys [identity]}]
  (if identity
    (navbar-dropdown
      "login-dropdown"
      [:span [:span.icon [:i.fa.fa-user] ]
       [:span (:user/name identity)]]
      [:div
       [:a {:class "navbar-item"
            :href  (bidi/path-for client-routes/routes :reports)} "My company"]
       #_[:a.dropdown-item {:on-click (dispatch-event-with-propagation [:vendor-dialog/started {}])} "New Vendor"] ;; double colorn
       #_[:a.dropdown-item {:on-click (dispatch-event-with-propagation [:vendor-dialog/edit {}])} "Edit Vendor"]
       (when (= "admin" (:user/role identity))
         [:a {:class "navbar-item" :href (bidi/path-for client-routes/routes :admin)} "Administration"])
       [:hr {:class "navbar-divider"}]
       [:a.navbar-item {"_" (hiccup/raw "on click call localStorage.removeItem(\"jwt\")")
                        :href (bidi/path-for ssr-routes/only-routes :logout)}
        "Logout"]])
    [:a.navbar-item {:href (bidi/path-for client-routes/routes :login  )} "Login"]))
