<commit_before>(ns statuses.views.main
  (:require [clj-time.local :refer [format-local-time]]
            [hiccup.core :refer [html]]
            [hiccup.element :refer [link-to]]
            [hiccup.form :refer [form-to hidden-field text-field]]
            [statuses.configuration :refer [config]]
            [statuses.routes :refer [avatar-path update-path
                                     updates-path]]
            [statuses.views.common :as common :refer [icon]]
            [statuses.views.layout :as layout]))

(defn- button
  ([class label] (button class label nil))
  ([class label icon-name]
  [:button {:type "submit" :class (str "btn btn-" class)} (html (icon icon-name) [:span.btn-label label])]))

(defn format-time [time]
  [:time {:datetime (format-local-time time :date-time)} (format-local-time time :rfc822)])

(defn delete-form [id]
  (form-to {:class "delete-form" :onsubmit "return confirm('Delete status?')"} [:delete (update-path id)]
    (button "delete" "Delete" "remove")))

(defn entry-form []
  (form-to {:class "entry-form"} [:post (updates-path)]
    [:div.input.input-group
     (text-field {:class "form-control" :autofocus "autofocus"} "entry-text")
     [:span.input-group-btn
      (button "default" "Send")]]
    [:div {"style" "clear: both"}]))

(defn reply-form [id author]
  (layout/simple
    (form-to {:class (str "reply-form form" id)} [:post (updates-path)]
      [:div.input-group (text-field {:class "form-control" :autofocus "autofocus" :value (str "@" author " ")} "reply-text")
       [:span.input-group-btn (button "default" "Reply")]]
      (hidden-field "reply-to" id)
      [:div {"style" "clear: both"}])))


(defn update [is-current {:keys [id text author time in-reply-to conversation can-delete?]}]
  (list
    [:div.avatar
     (link-to (str (config :profile-url-prefix) author) [:img {:src (avatar-path author) :alt author}])]
    [:div.meta
     [:span.author (link-to (str (updates-path) "?author=" author) author)]
     (if in-reply-to
       [:span.reply (link-to (update-path in-reply-to) in-reply-to)])
     [:span.actions (button "reply" "Reply" "reply")
      (if can-delete?
        [:span.delete (delete-form id)])]
     [:span.time [:a.permalink {:href (update-path id)} (format-time time)]]
     ]
    [:div.post-content (common/linkify text)]
  )
)

(defn list-page [items next username current-item-id]
  (layout/default
    (if current-item-id (str "Status " current-item-id) "timeline")
    username
    (list
      (when-not current-item-id (entry-form))
      [:ul.updates (map (fn [item]
                          (if (= current-item-id (:id item))
                            [:li.post.current (update true item)]<commit_msg>refactored main view to use new profile-path function (now consistent with the usage of avatar-path)<commit_after>(ns statuses.views.main
  (:require [clj-time.local :refer [format-local-time]]
            [hiccup.core :refer [html]]
            [hiccup.element :refer [link-to]]
            [hiccup.form :refer [form-to hidden-field text-field]]
            [statuses.configuration :refer [config]]
            [statuses.routes :refer [avatar-path update-path
                                     updates-path profile-path]]
            [statuses.views.common :as common :refer [icon]]
            [statuses.views.layout :as layout]))

(defn- button
  ([class label] (button class label nil))
  ([class label icon-name]
  [:button {:type "submit" :class (str "btn btn-" class)} (html (icon icon-name) [:span.btn-label label])]))

(defn format-time [time]
  [:time {:datetime (format-local-time time :date-time)} (format-local-time time :rfc822)])

(defn delete-form [id]
  (form-to {:class "delete-form" :onsubmit "return confirm('Delete status?')"} [:delete (update-path id)]
    (button "delete" "Delete" "remove")))

(defn entry-form []
  (form-to {:class "entry-form"} [:post (updates-path)]
    [:div.input.input-group
     (text-field {:class "form-control" :autofocus "autofocus"} "entry-text")
     [:span.input-group-btn
      (button "default" "Send")]]
    [:div {"style" "clear: both"}]))

(defn reply-form [id author]
  (layout/simple
    (form-to {:class (str "reply-form form" id)} [:post (updates-path)]
      [:div.input-group (text-field {:class "form-control" :autofocus "autofocus" :value (str "@" author " ")} "reply-text")
       [:span.input-group-btn (button "default" "Reply")]]
      (hidden-field "reply-to" id)
      [:div {"style" "clear: both"}])))


(defn update [is-current {:keys [id text author time in-reply-to conversation can-delete?]}]
  (list
    [:div.avatar
     (link-to (profile-path author) [:img {:src (avatar-path author) :alt author}])]
    [:div.meta
     [:span.author (link-to (str (updates-path) "?author=" author) author)]
     (if in-reply-to
       [:span.reply (link-to (update-path in-reply-to) in-reply-to)])
     [:span.actions (button "reply" "Reply" "reply")
      (if can-delete?
        [:span.delete (delete-form id)])]
     [:span.time [:a.permalink {:href (update-path id)} (format-time time)]]
     ]
    [:div.post-content (common/linkify text)]
  )
)

(defn list-page [items next username current-item-id]
  (layout/default
    (if current-item-id (str "Status " current-item-id) "timeline")
    username
    (list
      (when-not current-item-id (entry-form))
      [:ul.updates (map (fn [item]
                          (if (= current-item-id (:id item))
                            [:li.post.current (update true item)]
{'fraction_non_alphanumeric': 0.1772082878953108, 'fraction_numerical': 0.0010905125408942203, 'mean_word_length': 2.869901547116737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2332727', 'n_tokens_mistral': 1902, 'n_tokens_neox': 1841, 'n_words': 472}