 (ns moomoo-frontend.uploads
   (:require [clojure.set :as set :refer [difference]]))
 
+; paused? refers to when user manually pauses an upload
+; stopped? refers to the upload being stopped because
+; of the upload limit
 (def blank-upload {:stopped? true
                    :paused?  false
                    :id       nil

       (not (:paused? upload))))

(defn active-uploads [uploads-order uploads]
  (remove #(not (active? (uploads %1))) uploads-order))

(defn inactive-uploads [uploads-order uploads]
  (remove #(active? (uploads %1)) uploads-order))

(defn get-action [old-state new-state upload-id]

                                       (set old-uploads-order))
        removed-upload-ids (set/difference (set old-uploads-order)
                                           (set uploads-order))
        update-vals (fn [m keys f] (reduce #(update % %2 f)
                                           m
                                           keys))]
    (cond
      (< (count active-uploads) upload-slots)
      (assoc new-state 
             :uploads
             (update-vals uploads
                          (take (- upload-slots
                                   (count active-uploads)) 
                                unpaused-inactive-uploads)
                          start))
      
      (> (count active-uploads) upload-slots)
      (assoc new-state
             :uploads
             (update-vals uploads
                          (drop upload-slots
                                active-uploads)
                          stop))

      :else new-state)))

