             [discuss.communication.lib :as comlib]
             [discuss.config :as config]
             [discuss.references.lib :as rlib]
+            [discuss.texts.references :as textref]
             [discuss.translations :refer [translate] :rename {translate t}]
             [discuss.utils.bootstrap :as bs]
             [discuss.utils.common :as lib]

(defui ReferenceUsageForSingleArgumentView
  "Build single usage of a reference in an argument."
  static om/IQuery
  (query [this]
         `[:argument])
  Object
  (render [this]
          (let [{:keys [argument]} (om/props this)
                {:keys [author issue]} argument]
            (html [:div.bs-callout.bs-callout-info
                   [:div.pull-right

                     (vlib/fa-icon "fa-search"))]
                   [:a {:href "javascript:void(0)"
                        :onClick #(comlib/jump-to-argument (:slug issue) (:uid argument))}
                    [:strong (vlib/safe-html intro)]]
                   [:div (t :common :author) ": " (:nickname author)]
                   [:div (t :common :issue) ": " (:title issue)]]))))
(def reference-usage-for-single-argument (om/factory ReferenceUsageForSingleArgumentView {:keyfn :argument}))

(defui ReferenceUsagesForArgumentsView
  static om/IQuery
  (query [this] [:arguments])
  Object
  (render [this]
          (let [{:keys [arguments raw]} (om/props this)]
            (html [:div
                   (map
                    #(reference-usage-for-single-argument
                      {:argument %
                       :intro (textref/reference-usage-intro (get-in % [:author :nickname]) (:conclusions raw) (:premises raw))})
                    arguments)]))))
(def reference-usages-for-arguments (om/factory ReferenceUsagesForArgumentsView {:keyfn :arguments}))

