import {readFileSync} from 'node:fs';
import {renderComponent} from '../../packages/test/src/index';
import {getReactiveRuntime,getComponentControllerRuntime} from '../../packages/csr/src/index';
const source=readFileSync('packages/ui/components/Chart.wrn','utf8');
const types=['bar','line','area','pie','doughnut','radar','polarArea','scatter','bubble','mixed'];
const bundle=await Bun.build({entrypoints:['output/chartjs-verify/entry.ts'],target:'browser',minify:false});
if(!bundle.success) throw new Error(String(bundle.logs));
const js=await bundle.outputs[0].text();
let html='
';
for(const type of types){
const data=type==='scatter'||type==='bubble'?{datasets:[{label:'Coordinates',data:[{x:1,y:4,r:8},{x:3,y:8,r:16},{x:5,y:3,r:12}]}]}:{labels:['Mon','Tue','Wed','Thu','Fri'],datasets:[{label:'Sample',data:type==='bar'?[-20,38,29,52,45]:[24,38,29,52,45]},...(type==='mixed'?[{type:'line',label:'Target',data:[25,30,40,45,50]}]:[])]};
html+=await renderComponent(source,{title:type,description:'Sample data',type:type==='mixed'?'bar':type,data,showValues:false,options:{animation:false},height:260});
}
html+='';
const server=Bun.serve({port:4319,fetch(req){const path=new URL(req.url).pathname;return new Response(path==='/chart.js'?js:path==='/csr.js'?getReactiveRuntime()+'\n'+getComponentControllerRuntime():html,{headers:{'Content-Type':path.endsWith('.js')?'text/javascript':'text/html'}})}});
console.log('Chart verification listening on '+server.url);