(setq org-deadline-warning-days 7)
(setq org-agenda-skip-additional-timestamps-same-entry t)
(setq org-agenda-span 'fortnight)
(setq org-agenda-tags-column 'auto)
(setq org-agenda-skip-scheduled-if-deadline-is-shown t)

(setq org-agenda-files (list
			(concat org-directory "/inbox.org")
			(concat org-directory "/gtd.org")
			(concat org-directory "/org-gtd-tasks.org")
			)
      )

(use-package org-super-agenda)

(setq org-todo-keywords
        '(
          (sequence "TODO(t)" "NEXT(n)" "WAIT(w@/!)" "|" "DONE(d!)" "CNCL(c@)")
          )
        )

(setq org-todo-keyword-faces
        '(
          ("TODO" :foreground "red" :weight bold)
          ("NEXT" :foreground "red" :weight bold)
          ("WAIT" :foreground "yellow" :weight bold)
          ("DONE" :foreground "green" :weight bold)
          ("CNCL" :foreground "blue" :weight bold)
          )
        )

(setq org-enforce-todo-dependencies t)
(setq org-tags-exclude-from-inheritance '("crypt" "!private"))

(defun org-summary-todo (n-done n-not-done)
  "Switch entry to 'DONE' when all subentries are done, to 'TODO' otherwise.
Uses N-DONE and N-NOT-DONE"
  (let (org-log-done org-log-states)   ; turn off logging
    (org-todo (if (= n-not-done 0) "DONE" "TODO")
              )
      )
  )

  ;; (add-hook 'org-after-todo-statistics-hook #'org-summary-todo)

(use-package f)
(use-package dash)
(use-package s)
(use-package org-edna
  :config
  (setq org-edna-use-inheritance t)
  (org-edna-mode))

(use-package org-gtd
  :straight (org-gtd :type git :host github :repo "Trevoke/org-gtd.el")
  :demand t
  :init (setq org-gtd-update-ack "4.0.0")
  :config
  (setq org-gtd-keyword-mapping
        '((todo . "TODO")
          (next . "NEXT")
          (wait . "WAIT")
          (done . "DONE")
          (canceled . "CNCL")))
  (setq org-gtd-custom-node-paths
        (list (list "Actionable" (expand-file-name "~/memex/gtd.org") "Actions")
              (list "Legacy" (expand-file-name "~/memex/org-gtd-tasks.org") "Actions")
              (list "Projects" (expand-file-name "~/memex/gtd.org") "Projects")
              (list "Incubate" (expand-file-name "~/memex/gtd.org") "Incubate")))
  (org-gtd-mode)
  )

(global-set-key (kbd "C-c d c") #'org-gtd-capture)
(global-set-key (kbd "C-c d e") #'org-gtd-engage)
(global-set-key (kbd "C-c d p") #'org-gtd-process-inbox)
(with-eval-after-load 'org-gtd
  (define-key org-gtd-clarify-map (kbd "C-c c") #'org-gtd-organize))

(setq org-gtd-directory org-directory)
(setq org-gtd-organize-hooks '(org-gtd-set-area-of-focus))
(setq org-gtd-areas-of-focus '(
				 "Atoms"
				 "Bits"
				 "Cells"
				 "Flags"
				 "Business"
				 "Wealth"
				 "Learning"
				 "Skills"
				 "Privacy"
				 "Archive"
				 "Library"
				 "Writing"
				 "Health"
				 "Home"
				 "Family"
				 "Social"
				 "Egypt"
				 )
  )
(setq org-gtd-clarify-show-horizons 'right)

(setq org-log-into-drawer "LOGBOOK")

(setq org-clock-into-drawer t)

(setq org-habit-graph-column 80)
(setq org-habit-show-habits-only-for-today nil)

(setq org-refile-targets '((nil :maxlevel . 9)
                           (org-agenda-files :maxlevel . 9)
                           )
      )

(setq org-outline-path-complete-in-steps nil)

(setq org-refile-allow-creating-parent-nodes 'confirm)
