 (ns frontend.components.doc-viewer
   (:require [clojure.set :as set]
             [clojure.string :as str]
+            [cljs-time.core :as time]
             [datascript :as d]
             [frontend.async :refer [put!]]
             [frontend.components.common :as common]

      (let [cast! (om/get-shared owner :cast!)
            touched-docs (get-in app [:cust :touched-docs])
            ;; Not showing created for now, since we haven't been storing that until recently
            created-docs (get-in app [:cust :created-docs])]
        (html
         [:div.menu-prompt {:class (str "menu-prompt-" "doc-viewer")}
          [:div.menu-header

  (:require-macros [frontend.utils :refer [html]])
  (:import [goog.ui IdGenerator]))

(def day-of-week
  {1 "Monday"
   2 "Tuesday"
   3 "Wednesday"
   4 "Thursday"
   5 "Friday"
   6 "Saturday"
   7 "Sunday"})

(defn date->bucket [date]
  (let [time (goog.date.DateTime. date)
        start-of-day (doto (goog.date.DateTime.)
                       (.setHours 0)
                       (.setMinutes 0)
                       (.setSeconds 0)
                       (.setMilliseconds 0))]
    (cond
     (time/after? time start-of-day) "today"
     (time/after? time (time/minus start-of-day (time/days 1))) "yesterday"
     (time/after? time (time/minus start-of-day (time/days 6))) (day-of-week (time/day-of-week time))
     (time/after? time (time/minus start-of-day (time/days 14))) "last week"
     :else "a while ago")))


(defn doc-viewer [app owner]
  (reify
    om/IRender
