"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});exports.logQueue=void 0;const log_update_1=__importDefault(require("log-update"));class LogQueueManager{constructor(){this.queue=[];this.processing=!1;this.liveModeActive=!1;this.liveTaskCount=0;this.pendingPrints=[];this.lastLiveContent=""}static getInstance(){LogQueueManager.instance||(LogQueueManager.instance=new LogQueueManager);return LogQueueManager.instance}liveStart(){this.liveTaskCount++;this.liveModeActive=!0}liveUpdate(e){this.queue.push({type:"live-update",content:e});this.processQueue()}liveClear(){this.queue.push({type:"live-clear"});this.processQueue()}liveDone(e){this.queue.push({type:"live-done",finalOutput:e});this.processQueue()}print(e){this.queue.push({type:"print",content:e});this.processQueue()}printAtomic(e){this.queue.push({type:"print-atomic",lines:e});this.processQueue()}isLiveModeActive(){return this.liveModeActive}getLiveTaskCount(){return this.liveTaskCount}processQueue(){if(!this.processing){this.processing=!0;for(;this.queue.length>0;){const e=this.queue.shift();switch(e.type){case"live-update":if(this.pendingPrints.length>0&&this.liveModeActive){log_update_1.default.clear();for(const e of this.pendingPrints)console.log(e);this.pendingPrints=[]}this.liveModeActive=!0;this.lastLiveContent=e.content;(0,log_update_1.default)(e.content);break;case"live-clear":log_update_1.default.clear();this.lastLiveContent="";break;case"live-done":this.liveTaskCount=Math.max(0,this.liveTaskCount-1);if(this.liveTaskCount>0){if(e.finalOutput){log_update_1.default.clear();console.log(e.finalOutput)}}else{if(e.finalOutput){log_update_1.default.clear();console.log(e.finalOutput)}else log_update_1.default.done();this.liveModeActive=!1;this.lastLiveContent="";for(const e of this.pendingPrints)console.log(e);this.pendingPrints=[]}break;case"print":this.liveModeActive?this.pendingPrints.push(e.content):console.log(e.content);break;case"print-atomic":if(this.liveModeActive){const t=this.lastLiveContent;log_update_1.default.clear();for(const e of this.pendingPrints)console.log(e);this.pendingPrints=[];console.log(e.lines.join("\n"));this.liveTaskCount>0&&t&&(0,log_update_1.default)(t)}else console.log(e.lines.join("\n"))}}this.processing=!1}}flush(){if(this.liveModeActive){log_update_1.default.done();this.liveModeActive=!1;this.liveTaskCount=0}for(const e of this.pendingPrints)console.log(e);this.pendingPrints=[]}}exports.logQueue=LogQueueManager.getInstance();exports.default=exports.logQueue;