export class RecordingScriptWriter{constructor(t){this.steps=[],this.indentation=t}async appendStep(t){this.steps.push(t)}getScript(){const t=this.indentation,e=[];let n=0;function s(s){e.push(s?t.repeat(n)+s.trimRight():"")}s("const puppeteer = require('puppeteer');"),s(""),s("(async () => {"),n+=1,s("const browser = await puppeteer.launch();"),s("const page = await browser.newPage();"),s("");for(const r of this.steps){const t=r.toScript().filter((t=>null!==t)).map((t=>t.trim()));t.length>1&&(s("{"),n+=1);for(const e of t)"}"===e&&(n-=1),s(e),"{"===e&&(n+=1);t.length>1&&(n-=1,s("}"))}return s("await browser.close();"),n-=1,s("})();"),e.join("\n")+"\n"}}