"use strict";(globalThis.rspackChunk_clerk_clerk_js=globalThis.rspackChunk_clerk_clerk_js||[]).push([[321],{9296(e,t,i){i.d(t,{getDebugLogger:()=>c});var o=i(7213);i(5254),i(3560),i(6395),i(2949),i(7891),i(5467);class s{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,o){if(!this.shouldLogLevel(e))return;let s={timestamp:Date.now(),level:e,message:t,context:i,source:o};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}constructor(e,t){(0,o._)(this,"logLevel",void 0),(0,o._)(this,"transport",void 0),this.transport=e,this.logLevel=null!=t?t:"debug"}}i(1045);class r{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)}constructor(e){(0,o._)(this,"transports",void 0),this.transports=e}}class n{send(e){let t=new Date(e.timestamp).toISOString(),i=e.level.toUpperCase(),o=e.source?"[".concat(e.source,"]"):"",s=e.context?" ".concat(JSON.stringify(e.context)):"",r="[Clerk Debug] ".concat(t," ").concat(i).concat(o,": ").concat(e.message).concat(s);switch(e.level){case"error":console.error(r);break;case"warn":console.warn(r);break;case"info":console.info(r);break;case"debug":console.debug(r);break;default:console.log(r)}return Promise.resolve()}}class l{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}))}constructor(e){(0,o._)(this,"collector",void 0),this.collector=e}}class a{static getInstance(){return a.instance||(a.instance=new a),a.instance}async initialize(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};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,o=[{transport:new n},...i?[{transport:new l(i)}]:[]].map(e=>e.transport),a=new r(o),c=new s(a,null!=t?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}constructor(){(0,o._)(this,"initialized",!1),(0,o._)(this,"logger",null),(0,o._)(this,"initializationPromise",null)}}async function c(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return a.getInstance().initialize(e)}(0,o._)(a,"instance",void 0)}}]);