 ;;; `inbox-column-page' (the latter to handle selection-updates when
 ;;; dragging). We bubble it from `inbox-column-page', adding its own
 ;;; `:id' and use that id to update the selection information.
-(ui/defcomponent inbox-column-page [page owner {:keys [page-click!]}]
+(ui/defcomponent inbox-column-page [page owner {:keys [page-click! store-idx!]}]
   (render [_]
     [:li.page {:draggable true
                :class [(when (:selected? page) "selected")]
                :on-drag-start (fn [e]
                                 (println "inbox-column-page")
-                                (doto e.dataTransfer
-                                  (.setData "application/x-pepa-page" (:id page))))
+                                (.setData e.dataTransfer "application/x-pepa-page" (:id page)))
+               :on-drag-enter (fn [e]
+                                (println "[inbox-column-page] drag-enter")
+                                (store-idx! (:idx page)))
                :on-click (fn [e]
                            (page-click!
                             (selection/event->click (:id page) e))

                            ;; Delegate to `inbox'
                            (handle-drop! (:id column)
                                          source-column
                                          page-ids)))}
     [:header (column-title column state)]
     [:ul.pages
      (om/build-all inbox-column-page (column-pages column state)
                    {:opts {:page-click! (fn [click] 
                                           (om/update-state! owner :selection
                                                             #(selection/click % click)))}
                     :fn (partial mark-page-selected (:selected selection))})]]))

(defn ^:private inbox-handle-drop! [state owner page-cache target source page-ids]
  (let [columns (om/get-state owner :columns)
        target (get columns target)
        source (get columns source)
        ;; Remove page-ids already in `target'
        target-pages (mapv :id (column-pages target state))
        pages (into []
                    (comp (remove (set target-pages))
                          (map page-cache)
                          (map om/value))
                    page-ids)]
    (if-not (seq pages)
      ;; TODO: Should we do that in the columns itself?
      (js/console.warn "Ignoring drop consisting only of duplicate pages:"
                       (pr-str page-ids))
      (go
        (if (<! (accept-drop! target state pages))
          (do
            (println "Target saved. Removing from source...")
            (<! (remove-pages! source state page-ids))

  (remove-pages! [_ state page-ids]))

(defprotocol ColumnDropTarget
  (accept-drop!  [_ state pages target-idx]))

(defrecord InboxColumnSource [id]
  ColumnSource
