-(ns frontend.visualization.build)
+(ns frontend.visualization.build
+  (:require [frontend.models.feature :as feature]))
 
 (defn status->color [status]
-  (cond
-   (= status "success") "#292"
-   (= status "failed") "#c13737"
-   :else "rgb(128,128,128)"))
+  (let [is-v2? (feature/enabled? :ui-v2)
+        is-success? (= status "success")
+        is-failed? (= status "failed")]
+    (cond
+      (and is-v2? is-success?) "#42c88a"
+      (and is-v2? is-failed?) "#ed5c5c"
+      is-success? "#292"
+      is-failed? "#c13737"
+      ; grey for v2
+      is-v2? "#2c2f33"
+      :else "rgb(128,128,128)")))
 
 (defn millis->min-secs [millis]
   (let [total-secs (/ millis 1000.0)

                         "width" #(- (scale (js/Date. (aget % "end_time"))) (scale (js/Date. (aget % "start_time"))))
                         "height" bar-height
                         "fill" #(status->color (aget % "status"))}))
         ;; the start tick
         (-> group
             (.append "rect")
             (.attr #js {"x" #(scale (js/Date. (aget % "start_time")))
                         "y" #(* (+ bar-height bar-pad) (aget % "index"))
                         "width" 0.1
                         "height" (+ 1 bar-height)
                         "stroke" "black"
                         "stroke-width" 0.5})))))

    (-> svg (.selectAll "text") (.data (clj->js long-actions)) (.enter) (.append "text")
        (.text #(str (aget % "name") " (" (millis->min-secs (max-action-run-time-millis %)) ")"))

        d0 (js/Date. (:start_time build))
        d1 (js/Date. (:stop_time build))
        scale (-> js/d3 (.-time) (.scale))]
    (.attr svg "width" "100%")
    (-> scale (.domain #js [d0, d1]) (.range #js [0, (* 0.8 svg-width)]))
    (println "scale maps [" d0 ", " d1 "] -> [" (scale d0) ", " (scale d1) "]")

