 
 (rum/defc form < rum/reactive
                  init-state-mixin
-                 refresh-state-mixin [_]
-  (let [{:keys [filter data]} (state/react cursor)
+                 refresh-state-mixin
+                 {:did-mount  (fn [state] (auto-scroll!) state)
+                  :did-update (fn [state] (auto-scroll!) state)} [{:keys [service]}]
+  (let [{:keys [filter data autoscroll timestamp]} (state/react cursor)
         filtered-items (filter-items data
                                      (:predicate filter))]
-    (print filtered-items)
     [:div
      [:div.form-panel
+      [:div.form-panel-left
+       (comp/panel-info icon/services
+                        (:serviceName service))]]
+
+     [:div.log-panel
       [:div.form-panel-left
        (comp/panel-text-field
          {:hintText "Search in log"
           :onChange (fn [_ v]
-                      (state/update-value [:filter :serviceName] v cursor))})
+                      (state/update-value [:filter :predicate] v cursor))})
        [:span.form-panel-space]
        (comp/panel-checkbox
-         {:checked (:unhealthy filter)
+         {:checked timestamp
           :label   "Show timestamp"
           :onCheck (fn [_ v]
-                     (state/update-value [:filter :unhealthy] v cursor))})]
+                     (state/update-value [:timestamp] v cursor))})]
       [:div.form-panel-right
-       (comp/mui
-         (comp/raised-button
-           {:href    (routes/path-for-frontend :service-create-image)
-            :label   "New service"
-            :primary true}))]]
-     [:div.log
-      (for [item filtered-items]
-        [:span
-         [:span.log-timestamp (:timestamp item)]
-         [:span.log-body (str " " (:line item))]
-         [:br]])]]))
+       (comp/panel-checkbox
+         {:checked autoscroll
+          :label   "Auto-scroll logs"
+          :onCheck (fn [_ v]
+                     (state/update-value [:autoscroll] v cursor))})]]
+     (if (empty? filtered-items)
+       (comp/form-icon-value icon/info "There are no logs available for the service.")
+       [:div.log#service-log
+        (for [item filtered-items]
+          [:span
+           (when timestamp
+             [:span.log-timestamp (:timestamp item)])
+           [:span.log-info (str (:taskName item) "." (subs (:task item) 0 12) "@" (:taskNode item))]
+           [:span.log-body (str " " (:line item))]
+           [:br]])])]))


(def cursor [:page :service :log])

(defn- filter-items
  [items predicate]
  (filter #(string/includes? (:line %) predicate) items))

(defn- data-handler
  [service-id]
  (handler/get
    (routes/path-for-backend :service-logs {:id service-id})
    {:on-success (fn [response]
                   (state/update-value [:data] response cursor))}))

(defn- init-state
  [logs]
  (state/set-value {:filter {:predicate ""}
                    :data   logs} cursor))

(def refresh-state-mixin
  (mixin/refresh

(ns swarmpit.component.service.log
  (:require [material.icon :as icon]
            [material.component :as comp]
            [swarmpit.component.state :as state]
            [swarmpit.component.mixin :as mixin]
            [swarmpit.component.handler :as handler]
