(ns views.organizations
  (:require
    [datascript :as d]
    [secretary.core :as secretary :refer-macros [defroute]]

    [app]
    [resources]))

(def breadcrumbs (list "Organizations"))

(def template
  (div :class "ui page grid"
    (div :class "sixteen wide column"
      (div :class "ui segment"
        (div :class "ui vertical segment"
          (h1 :class "ui header"
            "Organizations"
            (a :class "ui right floated small button"
               :href "#/organizations/add"
              "Add Organization")))
        (div :class "ui vertical segment"
          (div :class "ui items"
            (loop-tpl :bindings [[name] ; TODO: Use datascript entity instead
                                 (cell= (d/q '[:find ?n
                                               :in $
                                               :where [?e :Name ?n]]
                                             resources/organizations-db))]
              (div :class "item"
                (div :class "content"
                  (a :class "header"
                    (text "~{name}"))
                  (div :class "extra"
                    (a :class "ui right floated small icon button"
                       :href (str "#/events?organization="
                                  #_(:OrganizationId @organization)) ; TODO: fix
                      "View events")))))))))))

(defroute "/organizations" []
  (reset! app/breadcrumbs breadcrumbs)
  template)

(ns views.organizations
  (:require
    [datascript :as d]
    [secretary.core :as secretary :refer-macros [defroute]]

    [app]
    [resources]))

(def breadcrumbs (list "Organizations"))

(def template
  (div :class "ui page grid"
    (div :class "sixteen wide column"
      (div :class "ui segment"
        (div :class "ui vertical segment"
          (h1 :class "ui header"
            "Organizations"
            (a :class "ui right floated small button"
               :href "#/organizations/add"
              "Add Organization")))
        (div :class "ui vertical segment"
          (div :class "ui items"
            (loop-tpl :bindings [[name] ; TODO: get datascript entities instead
                                 (cell= (d/q '[:find ?n
                                               :in $
                                               :where [?e :Name ?n]]
                                             resources/organizations-db))]
              (div :class "item"
                (div :class "content"
                  (a :class "header"
                    (text "~{name}"))
                  (div :class "extra"
                    (a :class "ui right floated small icon button"
                       :href (str "#/events?organization="
                                  #_(:OrganizationId @organization)) ; TODO: fix
                      "View events")))))))))))

(defroute "/organizations" []
  (reset! app/breadcrumbs breadcrumbs)
  template)

Add organization add form, tweaks to improve user experience.
Add organization add form, tweaks to improve user experience.
