             [taoensso.timbre :as log])
   (:require-macros
    [status-im.utils.views :as views :refer [defview letsubs]]))
-
-(def connectivity-bar-height 36)
-(def neg-connectivity-bar-height (- connectivity-bar-height))
 
 ;; ui-connectivity-status delays
 (def standard-delay 1000)


(defn manage-visibility
  "status-hidden is a per-view state, while to-hide? is a global state common to
  all connectivity views (we have at least one view in home and one in chat)"
  [connected? animate? anim-opacity anim-y status-hidden]

  (if connected?
    (if animate?
      (when (and @to-hide? (not @status-hidden))
        (animation/start
         (animation/parallel
          [(animation/timing anim-opacity
                             {:toValue         0
                              :delay           800
                              :duration        150
                              :easing          (.-ease ^js animation/easing)
                              :useNativeDriver true})
           (animation/timing anim-y
                             {:toValue         (if platform/desktop? 0 neg-connectivity-bar-height)
                              :delay           800
                              :duration        150
                              :easing          (.-ease ^js animation/easing)
                              :useNativeDriver true})])
          ;; second param of start() - a callback that fires when animation stops
         #(do (reset! to-hide? false) (reset! status-hidden true))))
      (do
        (animation/set-value anim-opacity 0)
        (animation/set-value anim-y (if platform/desktop? 0 neg-connectivity-bar-height))
        (reset! to-hide? false)
        (reset! status-hidden true)))
    ;; else
    (if animate?
      (when (and (not @to-hide?) @status-hidden)
        (animation/start
         (animation/parallel
          [(animation/timing anim-opacity
                             {:toValue         1
                              :duration        150
                              :easing          (.-ease ^js animation/easing)
                              :useNativeDriver true})
           (animation/timing anim-y
                             {:toValue         (if platform/desktop? connectivity-bar-height 0)
                              :duration        150
                              :easing          (.-ease ^js animation/easing)
                              :useNativeDriver true})])
          ;; second param of start() - a callback that fires when animation stops
         #(do (reset! to-hide? true) (reset! status-hidden false))))
      (do
        (animation/set-value anim-opacity 1)
        (animation/set-value anim-y (if platform/desktop? connectivity-bar-height 0))
        (reset! to-hide? true)
        (reset! status-hidden false)))))

(defn connectivity-status
  [{:keys [connected?]} status-hidden]
  (let [anim-translate-y (animation/create-value neg-connectivity-bar-height)
        anim-opacity     (animation/create-value 0)]
    (reagent/create-class
     {:component-did-mount
      (fn []
        (manage-visibility connected? false
                           anim-opacity anim-translate-y status-hidden))
      :should-component-update
      ;; ignore :loading-indicator?
      (fn [_ [_ old_p] [_ new_p]]

      :component-did-update
      (fn [comp]
        (manage-visibility (:connected? (reagent/props comp)) true
                           anim-opacity anim-translate-y status-hidden height))
      :reagent-render
      (fn [{:keys [message on-press-event connected? connecting?] :as opts}]
        (when-not @status-hidden
          [react/animated-view {:style               (styles/text-wrapper
                                                      (assoc opts
                                                             :height @height
                                                             :background-color (if connected?
                                                                                 colors/green
                                                                                 colors/gray)
