(ns miim.graphics.pixi
  (:require ["pixi.js" :as PIXI]
            [emptyhead.lib.io.print]
            [emptyhead.thought.crud :as thought]
            [emptyhead.thought.eval :as eval]
            [emptyhead.idea.protocol :as prtc]
            [emptyhead.thought.define :as def]))

(def/define!
  [:miim :graphics :make-screen]
  (fn [thought parent]
    (let [[parent args] (thought/pop-stack parent)
          app (PIXI/Application.)]
      (println args)
      (-> (.init app (clj->js args))
          (.then (fn [] (.appendChild js/document.body (.-canvas app)))))
      [parent app])))

(def populate
   (thought/register-thought!
    [:emptyhead :core :pure]
    :data {:height 256 :width 256 :background "29028F"}))

(def combined
  (let [operations [populate (thought/register-thought! [:miim :graphics :make-screen])]
        pure (eval/execute! (thought/register-thought! [:emptyhead :core :pure] :data operations))
        meme (eval/execute! (thought/make-thought [:emptyhead :core :sequence])
                            pure
                            )]
    (-> meme thought/pop-stack last)))
