             [clojure.java.io              :as io]
             [cheshire.core                :refer :all]
             [ring.util.response           :as resp]
+            [hiccup.def                   :refer [defhtml]]
             [hsm.actions                  :as actions]
             [hsm.pipe.event               :as event-pipe]
             [hsm.views                    :refer [layout panel panelx]]

              (when-not org?
                [:div.col-lg-6
                (panel [:a {:href (format "/user2/%s/starred" (:login user))} (str "Starred " c-star) ]
                  [:ul (for [star (:starred user-extras)] [:li [:a {:href (str "/p/" star)} star]])])])
              [:div.col-lg-6
              (panelx "User Repos" ["no-pad"]
                [:table.table (for [repo user-repos]
                  [:tbody
                  [:tr
                    [:td {:rowspan 2} [:span (:watchers repo)]]
                    [:td
                      [:a {:href (str "/p/" (:full_name repo))}
                      (:full_name repo)
                      [:span.label (:stars repo)]
                      [:span.label (:forks repo)]
                      ]]]
                  [:tr
                      [:td
                      [:p.gray (:description repo)]]]])]
                )]]))))))

(defn sync-user2

  (let [id (id-of request)
        user (actions/load-user db id)]
    (json-resp user)))

(defhtml user-part
  [id user admin? c-star c-follow c-followers]
  (panel (:login user)
    [:img.img-responsive.img-rounded {:src (:image user)}]
    [:h3 [:span (:login user)]
      [:a.pad10 {:href (str "https://github.com/" (:login user))} [:i.fa.fa-github]]]
    [:h5 [:span (:name user)]]
    [:p [:a {:href (:blog user)}(:blog user)]]
    [:p (:company user)]
    [:p (:location user)]
    [:p (:type user)]
    [:a {:href (str "mailto://" (:email user))} (:email user)]
    [:p (format "%s %s %s" c-star c-follow c-followers)]
    (when admin?
      [:a.btn.btn-danger.btn-sm {:href (format "/user2/%s?force-sync=1" id)} "Synchronize"])
    ))

(defhtml render-repos
  [repos]
  [:table.table (for [repo repos]
    [:tbody
      [:tr
        [:td {:rowspan 2} [:span (:watchers repo)]]
        [:td
          [:a {:href (str "/p/" (:full_name repo))}
          (:full_name repo)
          [:span.label (:stars repo)]
          [:span.label (:forks repo)]
          ]]]
      [:tr
          [:td
          [:p.gray (:description repo)]]]])])

(defn get-user2
  [[db event-chan] request] 
