(ns wanijo.public.view
  (:require [hiccup.page :refer [html5 include-js include-css]]
            [hiccup.core :refer [h]]
            [wanijo.infrastructure.routing :refer [path]]))

(defn layout [content]
  (html5
   [:head
    [:meta {:charset "utf-8"}]
    [:meta {:name "viewport"
            :content "width=device-width,initial-scale=1,shrink-to-fit=no"}]
    [:title "Moxie!"]
    (include-css "/css/bootstrap.min.css"
                 "/css/public.css")
    (include-js "/js/bootstrap.min.js")]
   [:body
    [:nav.navbar.navbar-expand-lg.sticky-top
     [:a.navbar-brand {:href (path :public-index)}
      [:img.navbar__logo {:src "/img/trio-logo.svg"
                          :alt "logo"}]]
     [:button.navbar-toggler {:type "button"
                              :data-toggle "collapse"
                              :data-target "#navbar-content"}
      [:span.navbar-toggler-icon]]
     [:div#navbar-content.collapse.navbar-collapse.text-right
      [:div#navbar-nav.ml-auto
       [:a {:href (path :auth-login)}
        "Login"]]]]
    [:div.container-fluid.super-container
     [:menu.global-nav
      [:ol.global-nav__card-nav
       [:li.global-nav__card-nav-item
        [:a.global-nav__link {:href (path :public-coc-roles {:coc "dev"})}
         "Development"]]
       [:li.global-nav__card-nav-item
        [:a.global-nav__link {:href (path :public-coc-roles {:coc "prk"})}
         "Projekte"]]
       [:li.global-nav__card-nav-item
        [:a.global-nav__link {:href (path :public-coc-roles {:coc "req"})}
         "Req. Eng."]]]]
     (into [:div.content] content)]]))

(defn index []
  (layout
   [[:main.main
     [:h1 "Schön, dass du da bist!"]
     [:h2 "Willkommen auf der TRIO-Wissensplattform"]
     [:p "Hier findest du das gesammelte Wissen unserer Kollegen."]
     [:p "Schau dich um. Vermisst du etwas? Dann sprich mit deinem CoC!"]
     [:p "Du möchtest dich weiterentwickeln?"
      "Dann gestalte selbst deinen Weg bei der TRIO und sprich"
      "deinen Vorgesetzten an"]]]))

(defn show-coc [coc roles-with-levels]
  (layout
   [[:main.main
     [:h1 "CoC " (h (:name coc))]
     [:div.table-responsive
      [:table.table
       [:thead
        [:tr
         [:th "Rolle"]
         [:th "Erfahrungsstufe"]]]
       [:tbody
        (for [row roles-with-levels
              :let [{:keys [role levels]} row
                    level (first levels)]]
          (list
           [:tr
            [:td {:rowspan (max 1 (count levels))}
             (h (:name role))]
            [:td
             [:a {:href (path :public-role-modules
                              {:coc (:key coc)
                               :level (:uuid level)})}
              (h (:name level))]]]
           (for [level (rest levels)]
             [:tr
              [:td [:a {:href (path :public-role-modules
                                    {:coc (:key coc)
                                     :level (:uuid level)})}
                    (h (:name level))]]])))]]]]
    [:nav
     [:ol.breadcrumb
      [:li.breadcrumb-item
       [:a {:href (path :public-index)} "Start"]]
      [:li.breadcrumb-item.active (h (:name coc))]]]]))

(defn show-modules [coc level modules-with-comps]
  (layout
   [[:main.main
     [:h1 "Erfahrungsstufe " (h (:name level))]
     [:div.table-responsive
      [:table.table
       [:thead
        [:tr
         [:th "Modul"]
         [:th "Komponente"]]]
       [:tbody
        (for [row modules-with-comps
              :let [{:keys [module comps]} row
                    compo (first comps)]]
          (list
           [:tr
            [:td {:rowspan (max 1 (count comps))}
             (h (:name module))]
            [:td (h (:name compo))]]
           (for [compo (rest comps)]
             [:tr
              [:td (h (:name compo))]])))]]]]
    [:nav
     [:ol.breadcrumb
      [:li.breadcrumb-item
       [:a {:href (path :public-index)} "Start"]]
      [:li.breadcrumb-item
       [:a {:href (path :public-coc-roles
                        {:coc (:key coc)})}
        (h (:name coc))]]
      [:li.breadcrumb-item.active (h (:name level))]]]]))
