(defisland ()
  (let ((input (signal ""))
        (output (signal "(ready)"))
        (history (signal (list)))
        (modules-loaded (signal
          (str "freeze: " (type-of freeze-registry)))))
    (let ((eval-input
            (fn (e)
              (let ((src (deref input)))
                (when (not (empty? src))
                  (let ((result (cek-try
                                  (fn () (str (cek-eval (first (sx-parse src)))))
                                  (fn (err) (str "Error: " err)))))
                    (reset! output result)
                    (swap! history (fn (h) (append h (list (dict :src src :result result)))))
                    (reset! input "")))))))
      (div (~tw :tokens "border border-stone-200 rounded-lg overflow-hidden")
        (div (~tw :tokens "bg-stone-800 text-stone-100 p-4 font-mono text-sm min-h-[120px] max-h-[300px] overflow-y-auto")
          (for-each
            (fn (entry)
              (div
                (div (~tw :tokens "text-emerald-400") (str "sx> " (get entry "src")))
                (div (~tw :tokens "text-stone-300 mb-2") (get entry "result"))))
            (deref history))
          (div (~tw :tokens "text-amber-400") (str "=> " (deref output)))
          (div (~tw :tokens "text-stone-600 text-xs mt-2") (deref modules-loaded)))
        (div (~tw :tokens "flex border-t border-stone-200")
          (span (~tw :tokens "bg-stone-100 px-3 py-2 text-stone-500 font-mono text-sm") "sx>")
          (input :type "text"
            :value (deref input)
            :on-input (fn (e) (reset! input (element-value (host-get e "target"))))
            :on-keydown (fn (e) (when (= (host-get e "key") "Enter") (eval-input e)))
            (~tw :tokens "flex-1 px-3 py-2 font-mono text-sm outline-none")
            :placeholder "Type an expression... (try: (+ 1 2) or (map inc (list 1 2 3)))"
            :autofocus "true")
          (button :on-click eval-input
            (~tw :tokens "px-4 py-2 bg-violet-600 text-white font-mono text-sm hover:bg-violet-700")
            "Eval"))))))
