const fs = require('fs');

const file = 'dist/assets/index-D9sWWWv_.js';
const content = fs.readFileSync(file, 'utf8');

const tSim = `if((D.host==="103.12.99.12"||D.host==="112.45.10.22"||D.host==="192.168.100.1")&&D.pass==="********"){b?M(B=>{const z=B.filter(X=>X.id!==b);return z.filter(X=>X.code===p&&X.routerId===N).length===0&&O(X=>X.map(de=>de.code===p?{...de,status:"active"}:de)),z}):(M(B=>B.filter(z=>z.code!==p)),O(B=>B.map(z=>z.code===p?{...z,status:"active"}:z))),alert(\`Koneksi user \${p} disimulasikan putus.\`);return}`;
const rSim = `if((D.host==="103.12.99.12"||D.host==="112.45.10.22"||D.host==="192.168.100.1")&&D.pass==="********"){b?M(B=>B.filter(X=>X.id!==b)):M(B=>B.filter(z=>z.code!==p)),alert(\`Koneksi user \${p} disimulasikan putus.\`);return}`;

const tReal = `if(z.success){b?M(X=>{const de=X.filter(Oe=>Oe.id!==b);return de.filter(Oe=>Oe.code===p&&Oe.routerId===N).length===0&&O(Oe=>Oe.map(Ue=>Ue.code===p?{...Ue,status:"active"}:Ue)),de}):(M(X=>X.filter(de=>de.code!==p)),O(X=>{let de=X.map(Ce=>Ce.code===p?{...Ce,status:"active"}:Ce);return de=de.filter(Ce=>!(Ce.agentId==="SYSTEM"&&Ce.code===p)),de}));const se={id:\`log-\${Date.now()}\`,timestamp:new Date().toLocaleTimeString(),source:"RouterOS",type:"success",message:\`Koneksi user hotspot \${p} berhasil diputuskan (kicked) di MikroTik.\`}`;
const rReal = `if(z.success){b?M(X=>X.filter(Oe=>Oe.id!==b)):M(X=>X.filter(de=>de.code!==p));const se={id:\`log-\${Date.now()}\`,timestamp:new Date().toLocaleTimeString(),source:"RouterOS",type:"success",message:\`Koneksi user hotspot \${p} berhasil diputuskan (kicked) di MikroTik.\`}`;

let modified = content;
if (content.includes(tSim)) {
  modified = modified.replace(tSim, rSim);
  console.log("Matched and replaced tSim");
} else {
  console.log("Could not find tSim exactly");
}

if (content.includes(tReal)) {
  modified = modified.replace(tReal, rReal);
  console.log("Matched and replaced tReal");
} else {
  console.log("Could not find tReal exactly");
}

if (modified !== content) {
  fs.writeFileSync(file, modified, 'utf8');
  console.log("Successfully wrote changes to JS file!");
} else {
  console.log("No changes made.");
}
