"use strict";(globalThis.rspackChunk_clerk_clerk_js=globalThis.rspackChunk_clerk_clerk_js||[]).push([[321],{9296(e,t,i){i.d(t,{getDebugLogger:()=>a}),i(5576);class r{logLevel;transport;constructor(e,t){this.transport=e,this.logLevel=t??"debug"}debug(e,t,i){this.log("debug",e,t,i)}error(e,t,i){this.log("error",e,t,i)}info(e,t,i){this.log("info",e,t,i)}warn(e,t,i){this.log("warn",e,t,i)}log(e,t,i,r){if(!this.shouldLogLevel(e))return;let s={timestamp:Date.now(),level:e,message:t,context:i,source:r};this.transport.send(s).catch(e=>{console.error("Failed to send log entry:",e)})}shouldLogLevel(e){let t=["error","warn","info","debug"],i=t.indexOf(this.logLevel);return t.indexOf(e)<=i}}class s{transports;constructor(e){this.transports=e}async send(e){let t=this.transports.map(t=>t.send(e).catch(e=>{console.error("Failed to send to transport:",e)}));await Promise.allSettled(t)}}class o{send(e){let t=new Date(e.timestamp).toISOString(),i=e.level.toUpperCase(),r=e.source?`[${e.source}]`:"",s=e.context?` ${JSON.stringify(e.context)}`:"",o=`[Clerk Debug] ${t} ${i}${r}: ${e.message}${s}`;switch(e.level){case"error":console.error(o);break;case"warn":console.warn(o);break;case"info":console.info(o);break;case"debug":console.debug(o);break;default:console.log(o)}return Promise.resolve()}}class n{collector;constructor(e){this.collector=e}async send(e){this.collector&&await Promise.resolve(this.collector.recordLog({context:e.context,level:e.level,message:e.message,organizationId:e.organizationId,sessionId:e.sessionId,source:e.source,timestamp:e.timestamp,userId:e.userId}))}}class l{static instance;initialized=!1;logger=null;initializationPromise=null;static getInstance(){return l.instance||(l.instance=new l),l.instance}async initialize(e={}){return this.initialized?this.logger:(this.initializationPromise||(this.initializationPromise=this.performInitialization(e)),this.initializationPromise)}async performInitialization(e){try{if(e.logLevel&&"string"!=typeof e.logLevel)throw Error("logLevel must be a string");let{logLevel:t,telemetryCollector:i}=e,l=[{transport:new o},...i?[{transport:new n(i)}]:[]].map(e=>e.transport),a=new s(l),c=new r(a,t??"info");return this.logger=c,this.initialized=!0,this.logger}catch(e){return console.error("Failed to initialize debug module:",e),this.initializationPromise=null,null}}getLogger(){return this.logger}isInitialized(){return this.initialized}reset(){this.initialized=!1,this.logger=null,this.initializationPromise=null}}async function a(e={}){return l.getInstance().initialize(e)}}}]);