    [uxbox.main.data.workspace :as dw]
    [uxbox.main.refs :as refs]
    [uxbox.main.store :as st]
-   [uxbox.main.ui.components.defer :refer [deferred]]
+   [uxbox.main.ui.components.defer :refer [throttle deferred]]
    [uxbox.main.ui.hooks :as hooks]
    [uxbox.main.ui.keyboard :as kbd]
    [uxbox.main.ui.shapes.icon :as icon]
+   [uxbox.util.object :as obj]
    [uxbox.util.dom :as dom]
    [uxbox.util.timers :as ts]
    [uxbox.util.i18n :as i18n :refer [t]]

  [props]
  [:> layer-item props])

(def ^:private layers-objects
  (letfn [(strip-data [obj]
            (select-keys obj [:id :name :blocked :hidden :shapes :type]))
          (selector [{:keys [objects] :as data}]
            (persistent!
             (reduce-kv (fn [res id obj]
                          (assoc! res id (strip-data obj)))
                        (transient {})
                        objects)))]
  (l/derived selector refs/workspace-data =)))

(mf/defc layers-tree
  {::mf/wrap [mf/memo]}
  []
  (let [selected (mf/deref refs/selected-shapes)
        objects (mf/deref layers-objects)
        root (get objects uuid/zero)]
    ;; [:& perf/profiler {:label "layers-tree" :enabled false}
    [:ul.element-list
     (for [[index id] (reverse (d/enumerate (:shapes root)))]
       (let [obj (get objects id)]

      [:span (:name page)]
      #_[:div.tool-window-close {:on-click on-click} i/close]]
     [:div.tool-window-content
      [:& layers-tree-wrapper {:key (:id page)
                               :objects (:objects data)}]]]))
