 (defn calendar-hiccup
   "Hiccup tempate for the calendar"
   [calendar-state]
-  (let [d (:active-date calendar-state)
-        events (:events calendar-state)]
     [:div.callie-view
      prev-next-today-btns 
-     [:h2 {:class "month-year"} (month-year-span d)]
+     [:h2 {:class "month-year"} (month-year-span calendar-state)]
      [:table.table.table-bordered
       [:thead weekday-row]
-      [:tbody (calendar-body d events)]]]))
+      [:tbody (calendar-body calendar-state)]]])
 
 
 (defn inject-cal! [calendar-state] 

   (for [x WEEKDAY-NAMES] 
     [:th x])])

(defn day-classes [d]
  (cond-> []
    (is-today? d) (conj "today")
    (is-active-month? d) (conj "active-month")
    (not (is-active-month? d)) (conj "not-active-month")))

(defn event-div [ev]
  [:div {:class ["event"]}
   [:a [:span.time (.format event-time-formatter (:start ev))]
       [:span.title (:title ev)]]])

(defn day-cell [d events]
  [:td 
   {:class (string/join " " (day-classes d))} 
   [:span {:class "daynumber"} (.getDate d)]
   (for [ev (days-events-filter d events)]
     (event-div ev))])

(defn calendar-body 
  "6 weeks of days (The body of the calendar.)"
  [d events]
  (let [sd (start-day d)
        all-days (take 6 (partition 7 (iterate next-day sd)))]
    (for [week all-days]
      [:tr 
       (for [day week] (day-cell day events))])))

(def prev-next-today-btns 
  (list 

  [d events]
  (filter #(is-event-on-date? % d) events))

(defn month-year-span [calendar-state]
  (let [active-date (:active-date calendar-state)]
    [:span {:id "cal-month-year"} (.format month-week-formatter active-date)]))

(defn is-today? [d]
  (.equals d today))

(defn is-active-month? [d calendar-state]
  (= (.getMonth (:active-date calendar-state))
     (.getMonth d)))

(def weekday-row 
