 
 (def view "add-projects")
 
+(defn vcs-github? [item] (contains? #{"github" nil} (:vcs_type item)))
+(defn vcs-bitbucket? [item] (= "bitbucket" (:vcs_type item)))
+
 (defn missing-scopes-notice [current-scopes missing-scopes]
   [:div
    [:div.alert.alert-error

     [:div.orgname login]
     (cond
       ;; TODO remove the nil check after a migration adds vcs-type to all entities
       (contains? #{"github" nil} vcs-type)
       [:a.visit-org {:href (str (gh-utils/http-endpoint) "/" login)
                      :target "_blank"}
        [:i.octicon.octicon-mark-github]]

       (= "bitbucket" vcs-type)
       [:a.visit-org
        [:i.fa.fa-bitbucket]])]))


   "."])

(defn organization-listing [data owner]
  (reify
    om/IDisplayName (display-name [_] "Organization Listing")
    om/IDidMount
    (did-mount [_]
      (utils/tooltip "#collaborators-tooltip-hack" {:placement "right"}))
    om/IRender
    (render [_]
      (let [{:keys [user settings repos]} data]
        (html
         [:div
          [:div.overview
           [:span.big-number "1"]
           [:div.instruction "Choose a GitHub account that you are a member of or have access to."]]
          [:div.organizations
           [:h4 "Your accounts"]
           [:ul.organizations
            (map (fn [org] (organization org settings owner))
                 ;; here we display you, then all of your organizations, then all of the owners of
                 ;; repos that aren't organizations and aren't you. We do it this way because the
                 ;; organizations route is much faster than the repos route. We show them
                 ;; in this order (rather than e.g. putting the whole thing into a set)
                 ;; so that new ones don't jump up in the middle as they're loaded.
                 (filter vcs-github?
                  (concat [user]
                          (:organizations user)
                          (let [org-names (->> user :organizations (cons user) (map :login) set)
                                in-orgs? (comp org-names :login)]
                            (->> repos (map :owner) (remove in-orgs?) (set))))))]
           (when (:repos-loading user)
             [:div.orgs-loading
              [:div.loading-spinner common/spinner]])
           (missing-org-info owner)]])))))

(defn select-vcs-type [vcs-type item]
  (case vcs-type
    "bitbucket" (vcs-bitbucket? item)
    "github"    (vcs-github?    item)))

(defn organization-listing-with-bitbucket [data owner]
  (reify
    om/IDisplayName (display-name [_] "Organization Listing")
    om/IDidMount
