const path = require("path");
const fs = require("fs");
require(path.join(__dirname, "../_build/default/browser/sx_browser.bc.js"));
require(path.join(__dirname, "sx-platform.js"));
const K = globalThis.SxKernel;
for (const n of ["signals","deps","page-helpers","router","adapter-html"])
  K.loadSource(fs.readFileSync(path.join(__dirname,`../../../web/${n}.sx`),"utf8"));

// Test signal basics
const tests = [
  '(signal 42)',
  '(let ((s (signal 42))) (deref s))',
  '(let ((s (signal 42))) (reset! s 100) (deref s))',
  '(let ((s (signal 10))) (swap! s (fn (v) (* v 2))) (deref s))',
  '(let ((s (signal 0))) (computed (fn () (+ (deref s) 1))))',
  '(let ((idx (signal 0))) (let ((c (computed (fn () (+ (deref idx) 10))))) (deref c)))',
];

for (const t of tests) {
  const r = K.eval(t);
  const s = JSON.stringify(r);
  console.log(`${t.substring(0,60)}`);
  console.log(`  => ${s && s.length > 100 ? s.substring(0,100) + '...' : s}`);
  console.log();
}
