(ns auto-ap.ssr.components.timeline
  (:require [auto-ap.ssr.hiccup-helper :as hh]))

(defn timeline-step [{:keys [active? visited? last?]} & children]
  (if active?
    [:li {:class "flex items-center text-primary-600 font-medium dark:text-primary-500"}
     [:span {:class "flex items-center justify-center w-5 h-5 mr-2 text-xs border-2 border-primary-600 rounded-full shrink-0 dark:border-primary-500"}]
     children
     (when-not last?
       [:svg {:class "w-3 h-3 ml-2 sm:ml-4", :aria-hidden "true", :xmlns "http://www.w3.org/2000/svg", :fill "none", :viewbox "0 0 12 10"}
        [:path {:stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "2", :d "m7 9 4-4-4-4M1 9l4-4-4-4"}]])]
    [:li {:class (cond-> "flex items-center"
                   (not visited?) (hh/add-class "text-gray-400"))}
     [:span {:class "flex items-center justify-center w-5 h-5 mr-2 text-xs border border-gray-500 rounded-full shrink-0 dark:border-gray-400"}
      (when visited?
        [:svg {:class "w-3 h-3 text-primary-600 dark:text-primary-500", :aria-hidden "true", :xmlns "http://www.w3.org/2000/svg", :fill "none", :viewbox "0 0 16 12"}
         [:path {:stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "2", :d "M1 5.917 5.724 10.5 15 1.5"}]])]
     children
     (when-not last?
       [:svg {:class "w-3 h-3 ml-2 sm:ml-4", :aria-hidden "true", :xmlns "http://www.w3.org/2000/svg", :fill "none", :viewbox "0 0 12 10"}
        [:path {:stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "2", :d "m7 9 4-4-4-4M1 9l4-4-4-4"}]])]))

(defn timeline [params & children]
  [:ol {:class "flex items-center w-full space-x-2 text-xs text-center text-gray-500 bg-white dark:text-gray-400 sm:text-base dark:bg-gray-800 sm:space-x-4 px-2"}
   children
   #_[:li {:class "flex items-center"}
      [:span {:class "flex items-center justify-center w-5 h-5 mr-2 text-xs border border-gray-500 rounded-full shrink-0 dark:border-gray-400"}]]])

(defn vertical-timeline-step [{:keys [active? visited? last?]} & children]
  (if active?
    [:li {:class "flex items-center text-primary-600 font-medium dark:text-primary-500"}
     [:span {:class "flex items-center justify-center w-5 h-5 mr-2 text-xs border-2 border-primary-600 rounded-full shrink-0 dark:border-primary-500"}]
     children ]
    [:li {:class (cond-> "flex items-center"
                   (not visited?) (hh/add-class "text-gray-400"))}
     [:span {:class "flex items-center justify-center w-5 h-5 mr-2 text-xs border border-gray-500 rounded-full shrink-0 dark:border-gray-400"}
      (when visited?
        [:svg {:class "w-3 h-3 text-primary-600 dark:text-primary-500", :aria-hidden "true", :xmlns "http://www.w3.org/2000/svg", :fill "none", :viewbox "0 0 16 12"}
         [:path {:stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "2", :d "M1 5.917 5.724 10.5 15 1.5"}]])]
     children ]))

(defn vertical-timeline [params & children]
  [:ol {:class (hh/add-class "flex flex-col items-start space-y-2 text-xs text-center text-gray-500 bg-gray-100 dark:text-gray-400 sm:text-base dark:bg-gray-800 sm:space-y-4 px-2"
                             (:class params))}
   children
   #_[:li {:class "flex items-center"}
      [:span {:class "flex items-center justify-center w-5 h-5 mr-2 text-xs border border-gray-500 rounded-full shrink-0 dark:border-gray-400"}]]])

