                               nil))
 
         remove-activity!
-        (fn [schedule]
+        (fn [schedule _]
           (schedules-endpoint :delete schedule nil))]
     (fn [event-id]
       (let



(def api-url "https://elevent.solutions:44300")


;; REST

      [:div.ui.dimmer {:class (when (empty? @events) :active)}
       [:div.ui.loader]]]]))

(defn event-details-attendee [event leave-event]
  (when-let [attendee-id (first (d/q '[:find [?attendee-id ...]
                                       :in $ ?event-id ?user-id
                                       :where
                                       [?attendee-id :EventId ?event-id]
                                       [?attendee-id :UserId ?user-id]]
                                     @attendees-db
                                     (:EventId event)
                                     (:UserId (:user @session))))]
    (let [scheduled-activities
          (d/q '[:find ?schedule-id ?activity-id
                 :in $activities $schedules ?event-id ?user-id
                 :where
                 [$activities ?activity-id :EventId ?event-id]
                 [$schedules  ?schedule-id :UserId     ?user-id]
                 [$schedules  ?schedule-id :ActivityId ?activity-id]]
               @activities-db
               @schedules-db
               (:EventId event)
               (get-in @session [:user :UserId]))]
      [:div.sixteen.wide.column
       [:div.ui.segment
        [:div.ui.vertical.segment
         [:h1.ui.dividing.header
          (:Name event)]
         [event-details-component event]
         [action-button {:class "right floated small"}
          [:div
           [:i.red.remove.icon]
           "Leave event"]
          (leave-event attendee-id)]]
        [:div.ui.vertical.segment
         [:h2 "QR-Code"]
         [qr-code
          {:text (event-attendee-route (into {} (d/entity @attendees-db
                                                          attendee-id)))}]]
        [:div.ui.vertical.segment
         [:h2 "Your Schedule"]
         [schedule-component scheduled-activities
          (list "Details" [:i.right.chevron.icon])
          (fn [_ activity-id]
            (js/location.replace (event-activity-route {:EventId (:EventId event)
                                                        :ActivityId activity-id})))
          [:a.ui.small.right.floated.labeled.icon.button
           {:href (event-schedule-route event)}
           [:i.edit.icon]
           "Edit"]]]]])))

(defn event-details-owner [event activities attendees leave-event]
  (let [submit-image
        (fn [e]
          (.preventDefault e)
          (let [form-data
                (doto
                  (js/FormData.)
                  (.append "Logo"
                           (-> (js/jQuery "#file")
                               (aget 0)
                               (aget "files")
                               (aget 0))))]
            (POST (str api-url-http "/logos")
                  {:keywords?       true
                   :timeout         8000
                   :headers
                   (if (:token @session)
                     {:Authentication
                      (str "Bearer " (:token @session))}
                     {})
                   :params form-data
                   :handler #(prn "success!")
                   :error-handler #(prn "failed...")})))]
    [:div.sixteen.wide.column
     [:div.ui.segment
      [:div.ui.vertical.segment
       [:h1.ui.dividing.header
        (:Name event)]
       [:div.ui.right.floated.small.labeled.icon.button
        [:i.edit.icon]
        "Edit"]
       [event-details-component event]]
      (when-let [attendee-id (first (d/q '[:find [?attendee-id ...]
                                           :in $ ?event-id ?user-id
                                           :where
                                           [?attendee-id :EventId ?event-id]
                                           [?attendee-id :UserId ?user-id]]
                                         @attendees-db
                                         (:EventId event)
                                         (:UserId (:user @session))))]
        [:div.ui.vertical.segment
         [:h2 "QR-Code"]
         [qr-code
          {:text (event-attendee-route (into {} (d/entity @attendees-db
                                                          attendee-id)))}]])
      [:div.ui.vertical.segment
       [:h2 "Event Logo"]
       [:form.ui.form
        [:div.two.fields
         [:div.field
          [:label "Choose image"]
          [:input#file {:type "file"}]]
         [:div.field]]
        [:button.ui.primary.button
         {:type :submit
          :on-click submit-image}
         "Submit"]]]
      [:div.ui.vertical.segment
       [:h2.ui.header
        "Activities"]
       [activity-table-component (:EventId event)]]
      [:div.ui.vertical.segment
       [:h2.ui.header
        "Attendees"
        [:a.ui.right.floated.small.button
         {:href (event-attendees-route event)}
         "View"]]
       [:table.ui.table
        [:thead
         [:tr
          [:th "Name"]
          [:th]]]
        [:tbody
         (for [attendee attendees]
           ^{:key (:AttendeeId attendee)}
           [:tr
            [:td (str (:FirstName attendee) " " (:LastName attendee))]
            [:td [:a.ui.right.floated.small.labeled.button
                  {:href (event-attendee-route {:EventId (:EventId event)
                                                :AttendeeId (:AttendeeId attendee)})
                   :class (when (:CheckinTime attendee) :green)}
                  (if (:CheckinTime attendee)
                    "Checked in"
                    "Check in")]]])]
        [:tfoot
         [:tr
          [:th {:colSpan "4"}
           [:div.ui.right.floated.small.labeled.icon.button
            [:i.edit.icon]
            "Edit"]]]]]]]]))

(defn event-page [event-id]
  (let [event (into {} (d/entity @events-db event-id))

