const WebServer = require('./controller/web-server');
const fs = require('fs');

WebServer.port = 3000;
WebServer.host = '0.0.0.0';
WebServer.app = { use: ()=>{}, get: ()=>{}, post: ()=>{}, put: ()=>{}, listen: ()=>{} };

// Register plugins in the same order as mc-bot.js
const plugins = [
    require('./controller/chat-web'),
    require('./controller/activity-web'),
    require('./controller/log-web'),
    require('./controller/invite'),
    require('./controller/settings/web'),
    require('./controller/ai/web'),
    require('./controller/storage/web'),
];

for (const p of plugins) {
    WebServer.queuePlugin(p);
}

const html = WebServer.getIndexHTML();
fs.writeFileSync('/tmp/index-v4.html', html);

// Extract and save JS for syntax check
const scriptMatch = html.match(/<script>([\s\S]*?)<\/script>/);
if (scriptMatch) {
    fs.writeFileSync('/tmp/rendered-js-v4.js', scriptMatch[1]);
}

console.log('HTML lines:', html.split('\n').length);
console.log('JS bytes:', scriptMatch ? scriptMatch[1].length : 0);
