                                                                                      "?client_id="
                                                                                      (:client-id client))))))
 
-(defn add-application-list [request enlive-m]
+(defn add-application-list [enlive-m request library-m]
   (let [authorised-clients (get-in request [:context :authorised-clients])]
     (if-not (empty? authorised-clients)
-      (html/at enlive-m [:.clj--app__list] (html/content (application-list-items authorised-clients)))
-      (html/at enlive-m [:.clj--app__list] (html/content empty-application-list-item)))))
+      (html/at enlive-m [:.clj--app__list] (html/content (application-list-items authorised-clients library-m)))
+      (html/at enlive-m [:.clj--app__list] (html/content (empty-application-list-item library-m))))))
 
 (defn set-sign-out-link [enlive-m]
   (html/at enlive-m

    (vh/remove-element enlive-m [:.clj--flash-message-container])))

(defn profile [request]
  (->> (vh/load-template "public/profile.html")
       (set-flash-message request)
       (diplay-email-unconfirmed-message request)
       (add-username request)
       (add-application-list request)
       set-sign-out-link
       set-change-password-link
       set-delete-account-link
       (hide-admin-span request)
       vh/remove-work-in-progress))

(ns stonecutter.view.profile
  (:require [net.cgrand.enlive-html :as html]
            [stonecutter.config :as config]
            [stonecutter.routes :as r]
            [stonecutter.view.view-helpers :as vh]))

(defn add-username [enlive-m request]
  (let [email (get-in request [:session :user-login])]
    (html/at enlive-m
             [:.clj--card-email] (html/content email))))

(def library-template (vh/load-template "public/library.html"))

(defn application-list-item [library-m] (first (html/select library-template [:.clj--authorised-app__list-item])))

(defn empty-application-list-item [library-m] (first (html/select library-template [:.clj--authorised-app__list-item--empty])))

(defn application-list-items [authorised-clients library-m]
  (html/at (application-list-item library-m)
           [:.clj--authorised-app__list-item]
           (html/clone-for [client authorised-clients]
                           [:.clj--client-name] (html/content (:name client))
