   (:require-macros [sablono.core :refer (html)])
   (:import [goog.ui IdGenerator]))
 
-; (defn description-form [{:keys [issue issue-id]} owner]
-;   (reify
-;     om/IDisplayName (display-name [_] "Description form")
-;     om/IInitState (init-state [_] {:issue-description nil
-;                                    :describing? false})
-;     om/IRenderState
-;     (render-state [_ {:keys [issue-description]}]
-;       (let [{:keys [issue-db cust cast!]} (om/get-shared owner)]
-;         (html
-;           [:div.original-comment
-;           (if (:issue/description issue)
-
-;             [:div.issue-comment
-;              [:p.make (:issue/description issue)]
-;              [:p.issue-foot.make
-;               [:span (common/icon :user) " "]
-;               [:a {:role "button"}
-;                (:issue/author issue)]
-;               [:span " on "]
-;               [:a {:role "button"}
-;                (datetime/month-day (:issue/created-at issue))]
-;               [:span " — "]
-;               [:a {:role "button"
-;                    :on-click #(do
-;                                 (if (om/get-state owner :replying?)
-;                                   (om/set-state! owner :replying? false)
-;                                   (om/set-state! owner :replying? true)))}
-;                (if (om/get-state owner :describing?) "Cancel" "Reply")]]]
-
-;             [:div.content.make
-;              [:form.adaptive {:on-submit #(do (utils/stop-event %)
-;                                             (when issue-description
-;                                               (d/transact! issue-db [{:db/id (:db/id issue)
-;                                                                       :issue/description issue-description}]))
-;                                             (om/set-state! owner :issue-description nil)
-;                                             (om/set-state! owner :replying? false))}
-;               [:textarea {:value (or issue-description (:issue/description issue ""))
-;                           :required "true"
-;                           :onChange #(om/set-state! owner :issue-description (.. % -target -value))}]
-;               [:label {:data-label "label here"
-;                        :data-placeholder "How can we improve Precursor?"}]
-;               [:input {:type "submit"
-;                        :value "Submit idea."}]]])
-
-;           (om/build comment-form {:issue-id issue-id})
-
-;           ])))))
-
 (defn issue-form [_ owner]
   (reify
     om/IDisplayName (display-name [_] "Issue form")

         [:div.issue-card.content.make
          [:div.issue-info
           [:a.issue-title {:href (urls/issue-url issue)
                            :target "_top"
                            :role "button"}
            ; (or title (:issue/title issue ""))
            (:issue/title issue)
            ]
           ; (issue-foot issue)

           [:p.issue-foot
            [:a {:role "button"}
             (str comment-count " comment" (when (not= 1 comment-count) "s"))]
            [:span " for "]
            [:a {:role "button"}
             ; "feature"
             ; "integration"
             "bugfix"]
            [:span " in "]
            [:a {:role "button"}
             ; "review"
             ; "production"
             "development."]]]
          (om/build vote-box {:issue issue})])))))

; (defn issue-summary [{:keys [issue-id]} owner]
;   (reify
;     om/IInitState
;     (init-state [_] {:listener-key (.getNextUniqueId (.getInstance IdGenerator))})
;     om/IDidMount
;     (did-mount [_]
;       (fdb/add-entity-listener (om/get-shared owner :issue-db)
;                                issue-id
;                                (om/get-state owner :listener-key)
;                                (fn [tx-report]
;                                  (om/refresh! owner))))
;     om/IWillUnmount
;     (will-unmount [_]
;       (fdb/remove-entity-listener (om/get-shared owner :issue-db)
;                                   issue-id
;                                   (om/get-state owner :listener-key)))
;     om/IRender
;     (render [_]
;       (let [{:keys [cast! issue-db]} (om/get-shared owner)
;             issue (ds/touch+ (d/entity @issue-db issue-id))
;             comment-count (count (:issue/comments issue))]
;         (html
;           [:div.issue-summary
;            [:div.issue-info
;             [:a.issue-title {:on-click #(cast! :issue-expanded {:issue-id issue-id})
;                              :role "button"}
;              ; (or title (:issue/title issue ""))
;              (:issue/comments issue)
;              ]
;             ; (issue-foot issue)

;             [:p.issue-foot
;              [:a {:role "button"}
;               (str comment-count " comment" (when (< 1 comment-count) "s"))]
;              [:span " for "]
;              [:a {:role "button"}
;               ; "feature"
;               ; "integration"
;               "bugfix"]
;              [:span " in "]
;              [:a {:role "button"}
;               ; "review"
;               ; "production"
;               "development."]]]
;            (om/build vote-box {:issue issue})])))))

(defn issue* [{:keys [issue-id]} owner]
  (reify

      (let [issue-db (om/get-shared owner :issue-db)
            cust (om/get-shared owner :cust)]
        (html
         [:div.content.make
          [:form.adaptive {:on-submit #(do (utils/stop-event %)
                                         (when (seq comment-body)
                                           (d/transact! issue-db [{:db/id issue-id
                                                                   :issue/comments (merge {:db/id -1
                                                                                           :comment/created-at (datetime/server-date)
                                                                                           :comment/body comment-body
                                                                                           :comment/author (:cust/email cust)
                                                                                           :frontend/issue-id (utils/squuid)}
                                                                                          (when parent-id
                                                                                            {:comment/parent parent-id}))}])
                                           (om/set-state! owner :comment-body ""))
                                         (close-callback))}

           [:textarea {:required true
                       :value comment-body
