import{spinner as f}from"@clack/prompts";import o from"picocolors";var s={debug:0,info:1,warn:2,error:3,success:1};function c(t){if(t.quiet)return"error";if(t.verbose)return"debug";let e=process.env.NEBUTRA_LOG_LEVEL;return e&&s[e]!==void 0?e:t.level??"info"}function a(t){return process.env.NEBUTRA_LOG_FORMAT==="json"?"json":t.format??"plain"}function L(t,e,r){let i=new Date().toISOString().split("T")[1].split(".")[0],n=r?`[${r}]`:"";switch(t){case"error":return`${o.red(`\u2716 ${n}`)} ${e}`.trim();case"warn":return`${o.yellow(`\u26A0 ${n}`)} ${e}`.trim();case"success":return`${o.green(`\u2713 ${n}`)} ${e}`.trim();case"debug":return`${o.dim(`[debug ${i}] ${n}`)} ${e}`.trim();default:return`${o.blue(`\u2139 ${n}`)} ${e}`.trim()}}function u(t,e,r,i){let n={timestamp:new Date().toISOString(),level:t,scope:r,message:e,...i&&{details:i}};return JSON.stringify(n)}function p(){let t=f();return{start(e){t.start(o.cyan(e))},stop(e,r){e?r===0?t.stop(o.green(`\u2713 ${e}`)):t.stop(o.red(`\u2716 ${e}`)):t.stop("")},message(e){t.message(o.cyan(e))}}}var g=class t{config;effectiveLevel;format;constructor(e={}){this.config=e,this.effectiveLevel=c(e),this.format=a(e)}shouldLog(e){return s[e]>=s[this.effectiveLevel]}log(e,r,i){if(!this.shouldLog(e))return;let n=this.format==="json"?u(e,r,this.config.scope,i):L(e,r,this.config.scope);(e==="error"||e==="warn"?process.stderr:process.stdout).write(n+`
`)}debug(e,r){this.log("debug",e,r)}info(e,r){this.log("info",e,r)}warn(e,r){this.log("warn",e,r)}error(e,r){this.log("error",e,r)}success(e,r){this.log("success",e,r)}step(e,r,i){let n=o.cyan(`[${e}/${r}]`);this.log("info",`${n} ${i}`)}spinner(){return p()}scope(e){return new t({...this.config,scope:e})}setConfig(e){this.config={...this.config,...e},this.effectiveLevel=c(this.config),this.format=a(this.config)}getLevel(){return this.effectiveLevel}};function l(t){return new g(t)}var h=l({level:process.env.NEBUTRA_LOG_LEVEL??"info",verbose:process.argv.includes("--verbose"),quiet:process.argv.includes("--quiet")});export{l as a,h as b};
