             [salava.badge.ui.verify :refer [check-badge]]
             [salava.core.ui.tag :as tag]))
 
-
+(declare show-settings-dialog)
+(declare badge-content)
+
+(defn init-badge-connection [state badge-id]
+  (ajax/GET
+   (path-for (str "/obpv1/social/connected/" badge-id))
+   {:handler (fn [data]
+               (swap! state assoc :receive-notifications data)
+                )}))
+
+(defn init-data [state id tab-no]
+  (ajax/GET
+    (path-for (str "/obpv1/badge/info/" id))
+    {:handler (fn [data]
+               (do (reset! state (assoc data :id id
+                                :show-link-or-embed-code nil
+                                :initializing false
+                                :content-language (init-content-language (:content data))
+                                :tab-no tab-no
+                                :permission "success"))
+                 (init-badge-connection state (:badge_id data))
+                 (cond
+                   (== 2 (:tab-no @state))(show-settings-dialog id state init-data "settings")
+                   (== 3 (:tab-no @state))(show-settings-dialog id state init-data "share")
+                   )))}
+    (fn [] (swap! state assoc :permission "error"))))
+
+(defn show-settings-dialog [badge-id state init-data context]
+  (ajax/GET
+    (path-for (str "/obpv1/badge/settings/" badge-id) true)
+    {:handler (fn [data]
+                (swap! state assoc :badge-settings data (assoc data :new-tag ""))
+                (if (= context "settings")
+                  (swap! state assoc :tab [se/settings-tab-content data state init-data true]
+                                     :tab-no 2)
+                  (swap! state assoc :tab [se/share-tab-content data state init-data]
+                                     :tab-no 3)
+                  ))}))
 
 (defn congratulate [state]
   (ajax/POST

        state (atom {:initializing true
                     :permission "initial"})
        user (session/get :user)]
    (init-data state id)

    (fn []
      (cond

     (if (or verified_by_obf issued_by_obf)
       (bh/issued-by-obf obf_url verified_by_obf issued_by_obf)
       [:div.col-md-3])
     (if owner? [modal-navi state])]))


(defn content [state]
  (let [{:keys [owner? tab]} @state]
    [:div
     (when-not owner? [follow-verified-bar @state nil nil])
     [modal-top-bar state]
     (if tab tab [badge-content state])]))


(defn handler [params]
