;;; spells.el -*- lexical-binding: t; -*-

(defun read-lines (filePath)
  "Return a list of lines of a file at filePath"
  (with-temp-buffer
    (insert-file-contents filePath)
    (split-string (buffer-string) "\n" t)))

;; Functions for my diary system
(defun today ()
  "Returns today's date in YYYY-MM-DD format"
  (interactive)
  (format-time-string "%Y-%m-%d"))

(defun time ()
  "Insert a line with the current time"
  (interactive)
  (insert (concat "Entry Time: " (format-time-string "%H:%M:%S") "\n")))

(defun open-diary ()
  "Open the diary file for today's date."
  (interactive)
  (find-file (concat "~/wrt/diary/" (today) ".md"))
  (unless (file-exists-p (concat "~/wrt/diary/" (today) ".md"))
    (insert (today)))
  (end-of-buffer))

(defun response-gatherer (prompt)
  "Read prompts from file 'prompt' and present them to the user in the minibuffer"
  (interactive)
  (open-diary)
  (evil-insert-newline-below)
  (insert (concat "## " prompt "\n"))
  (time)
  (mapcar
   (lambda (x) (insert
                (message (concat x " %s\n") (read-string (concat x " ")))))
     (read-lines
      (concat "~/wrt/journal/selfMonitoringPrompts/" prompt))))

(defun sleep-journal ()
  "Fill out sleep journal in today's diary entry"
  (interactive)
  (response-gatherer "sleepJournal"))
