(ns lineup.views
  (:require
   [lineup.components.edit :refer [edit]]
   [lineup.components.schedule :refer [schedule]]
   [lineup.events :as events]
   [lineup.subs :as subs]
   [re-com.core :as re-com]
   [re-frame.core :as re-frame]))

(defn- top-bar [mode]
  [re-com/h-box
   :class "top-bar"
   :justify :between
   :align :center
   :children
   [[re-com/title
     :label "Schedule"
     :level :level2]
    [re-com/hyperlink
     :label (if (= mode :edit) "done" "edit")
     :on-click #(re-frame/dispatch [::events/toggle-mode (if (= mode :edit) :normal :edit)])]]])

(defn main-panel []
  (let [mode (re-frame/subscribe [::subs/mode])]
    [re-com/v-box
     :gap "10px"
     :height "100%"
     :children
     [[top-bar @mode]
      (if (= @mode :edit)
        [edit]
        [schedule])]]))

