import{R as X,r as m,e as Z}from"./core.browser.esm-BT5kH-ZG.js";(function(){try{var o=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},n=new o.Error().stack;n&&(o._sentryDebugIds=o._sentryDebugIds||{},o._sentryDebugIds[n]="7f7316d9-4f97-4bcc-a639-54fe62fcbd3a",o._sentryDebugIdIdentifier="sentry-dbid-7f7316d9-4f97-4bcc-a639-54fe62fcbd3a")}catch{}})();(function(){try{var o=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},n=new o.Error().stack;n&&(o._sentryDebugIds=o._sentryDebugIds||{},o._sentryDebugIds[n]="bfb3692c-c154-4da3-b37a-10f19d643d93",o._sentryDebugIdIdentifier="sentry-dbid-bfb3692c-c154-4da3-b37a-10f19d643d93")}catch{}})();(function(){try{var o=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},n=new o.Error().stack;n&&(o._sentryDebugIds=o._sentryDebugIds||{},o._sentryDebugIds[n]="869a0d59-6d4d-466f-88dc-ef5f1ba73c98",o._sentryDebugIdIdentifier="sentry-dbid-869a0d59-6d4d-466f-88dc-ef5f1ba73c98")}catch{}})();(function(){try{var o=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},n=new o.Error().stack;n&&(o._sentryDebugIds=o._sentryDebugIds||{},o._sentryDebugIds[n]="e366351f-22f2-4e44-a9ab-d4881ee5d2dc",o._sentryDebugIdIdentifier="sentry-dbid-e366351f-22f2-4e44-a9ab-d4881ee5d2dc")}catch{}})();var U=function(o,n){return U=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])},U(o,n)},d=function(){return d=Object.assign||function(o){for(var n,t=1,r=arguments.length;t<r;t++)for(var e in n=arguments[t])Object.prototype.hasOwnProperty.call(n,e)&&(o[e]=n[e]);return o},d.apply(this,arguments)};function b(o,n,t,r){return new(t||(t=Promise))(function(e,i){function s(h){try{l(r.next(h))}catch(a){i(a)}}function c(h){try{l(r.throw(h))}catch(a){i(a)}}function l(h){var a;h.done?e(h.value):(a=h.value,a instanceof t?a:new t(function(y){y(a)})).then(s,c)}l((r=r.apply(o,[])).next())})}function g(o,n){var t,r,e,i,s={label:0,sent:function(){if(1&e[0])throw e[1];return e[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function c(l){return function(h){return function(a){if(t)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(t=1,r&&(e=2&a[0]?r.return:a[0]?r.throw||((e=r.return)&&e.call(r),0):r.next)&&!(e=e.call(r,a[1])).done)return e;switch(r=0,e&&(a=[2&a[0],e.value]),a[0]){case 0:case 1:e=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(e=s.trys,!((e=e.length>0&&e[e.length-1])||a[0]!==6&&a[0]!==2)){s=0;continue}if(a[0]===3&&(!e||a[1]>e[0]&&a[1]<e[3])){s.label=a[1];break}if(a[0]===6&&s.label<e[1]){s.label=e[1],e=a;break}if(e&&s.label<e[2]){s.label=e[2],s.ops.push(a);break}e[2]&&s.ops.pop(),s.trys.pop();continue}a=n.call(o,s)}catch(y){a=[6,y],r=0}finally{t=e=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([l,h])}}}var $={exports:{}};function P(){}P.prototype={on:function(o,n,t){var r=this.e||(this.e={});return(r[o]||(r[o]=[])).push({fn:n,ctx:t}),this},once:function(o,n,t){var r=this;function e(){r.off(o,e),n.apply(t,arguments)}return e._=n,this.on(o,e,t)},emit:function(o){for(var n=[].slice.call(arguments,1),t=((this.e||(this.e={}))[o]||[]).slice(),r=0,e=t.length;r<e;r++)t[r].fn.apply(t[r].ctx,n);return this},off:function(o,n){var t=this.e||(this.e={}),r=t[o],e=[];if(r&&n)for(var i=0,s=r.length;i<s;i++)r[i].fn!==n&&r[i].fn._!==n&&e.push(r[i]);return e.length?t[o]=e:delete t[o],this}},$.exports=P;var tt=$.exports.TinyEmitter=P,N=function(o){var n=o[1];return n!=null},et=function(){},rt=function(){function o(n){var t=n.onError,r=n.onSent,e=n.appName,i=n.metricsInterval,s=n.disableMetrics,c=s!==void 0&&s,l=n.url,h=n.clientKey,a=n.fetch,y=n.headerName,I=n.customHeaders,x=I===void 0?{}:I;this.onError=t,this.onSent=r||et,this.disabled=c,this.metricsInterval=1e3*i,this.appName=e,this.url=l instanceof URL?l:new URL(l),this.clientKey=h,this.bucket=this.createEmptyBucket(),this.fetch=a,this.headerName=y,this.customHeaders=x}return o.prototype.start=function(){var n=this;if(this.disabled)return!1;typeof this.metricsInterval=="number"&&this.metricsInterval>0&&setTimeout(function(){n.startTimer(),n.sendMetrics()},2e3)},o.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer)},o.prototype.createEmptyBucket=function(){return{start:new Date,stop:null,toggles:{}}},o.prototype.getHeaders=function(){var n,t=((n={})[this.headerName]=this.clientKey,n.Accept="application/json",n["Content-Type"]="application/json",n);return Object.entries(this.customHeaders).filter(N).forEach(function(r){var e=r[0],i=r[1];return t[e]=i}),t},o.prototype.sendMetrics=function(){return b(this,void 0,void 0,function(){var n,t,r;return g(this,function(e){switch(e.label){case 0:if(n="".concat(this.url,"/client/metrics"),t=this.getPayload(),this.bucketIsEmpty(t))return[2];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.fetch(n,{cache:"no-cache",method:"POST",headers:this.getHeaders(),body:JSON.stringify(t)})];case 2:return e.sent(),this.onSent(t),[3,4];case 3:return r=e.sent(),console.error("Unleash: unable to send feature metrics",r),this.onError(r),[3,4];case 4:return[2]}})})},o.prototype.count=function(n,t){return!(this.disabled||!this.bucket)&&(this.assertBucket(n),this.bucket.toggles[n][t?"yes":"no"]++,!0)},o.prototype.countVariant=function(n,t){return!(this.disabled||!this.bucket)&&(this.assertBucket(n),this.bucket.toggles[n].variants[t]?this.bucket.toggles[n].variants[t]+=1:this.bucket.toggles[n].variants[t]=1,!0)},o.prototype.assertBucket=function(n){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[n]||(this.bucket.toggles[n]={yes:0,no:0,variants:{}})},o.prototype.startTimer=function(){var n=this;this.timer=setInterval(function(){n.sendMetrics()},this.metricsInterval)},o.prototype.bucketIsEmpty=function(n){return Object.keys(n.bucket.toggles).length===0},o.prototype.getPayload=function(){var n=d(d({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:n,appName:this.appName,instanceId:"browser"}},o}(),nt=function(){function o(){this.store=new Map}return o.prototype.save=function(n,t){return b(this,void 0,void 0,function(){return g(this,function(r){return this.store.set(n,t),[2]})})},o.prototype.get=function(n){return b(this,void 0,void 0,function(){return g(this,function(t){return[2,this.store.get(n)]})})},o}(),ot=function(){function o(){this.prefix="unleash:repository"}return o.prototype.save=function(n,t){return b(this,void 0,void 0,function(){var r,e;return g(this,function(i){r=JSON.stringify(t),e="".concat(this.prefix,":").concat(n);try{window.localStorage.setItem(e,r)}catch(s){console.error(s)}return[2]})})},o.prototype.get=function(n){try{var t="".concat(this.prefix,":").concat(n),r=window.localStorage.getItem(t);return r?JSON.parse(r):void 0}catch(e){console.error(e)}},o}();let C;const it=new Uint8Array(16);function st(){if(!C&&(C=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!C))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return C(it)}const f=[];for(let o=0;o<256;++o)f.push((o+256).toString(16).slice(1));var z={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function at(o,n,t){if(z.randomUUID&&!n&&!o)return z.randomUUID();const r=(o=o||{}).random||(o.rng||st)();return r[6]=15&r[6]|64,r[8]=63&r[8]|128,function(e,i=0){return f[e[i+0]]+f[e[i+1]]+f[e[i+2]]+f[e[i+3]]+"-"+f[e[i+4]]+f[e[i+5]]+"-"+f[e[i+6]]+f[e[i+7]]+"-"+f[e[i+8]]+f[e[i+9]]+"-"+f[e[i+10]]+f[e[i+11]]+f[e[i+12]]+f[e[i+13]]+f[e[i+14]]+f[e[i+15]]}(r)}var ct=function(){function o(){}return o.prototype.generateEventId=function(){return at()},o.prototype.createImpressionEvent=function(n,t,r,e,i,s){var c=this.createBaseEvent(n,t,r,e,i);return s?d(d({},c),{variant:s}):c},o.prototype.createBaseEvent=function(n,t,r,e,i){return{eventType:e,eventId:this.generateEventId(),context:n,enabled:t,featureName:r,impressionData:i}},o}(),ut=["userId","sessionId","remoteAddress","currentTime"],J=function(o){return ut.includes(o)},v={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression",SENT:"sent",RECOVERED:"recovered"},lt="isEnabled",ht="getVariant",dt={name:"disabled",enabled:!1,feature_enabled:!1},A="repo",ft=function(){try{if(typeof window<"u"&&"fetch"in window)return fetch.bind(window);if("fetch"in globalThis)return fetch.bind(globalThis)}catch(o){console.error('Unleash failed to resolve "fetch"',o)}},pt=function(o){function n(t){var r=t.storageProvider,e=t.url,i=t.clientKey,s=t.disableRefresh,c=s!==void 0&&s,l=t.refreshInterval,h=l===void 0?30:l,a=t.metricsInterval,y=a===void 0?30:a,I=t.disableMetrics,x=I!==void 0&&I,S=t.appName,p=t.environment,w=p===void 0?"default":p,E=t.context,T=t.fetch,R=T===void 0?ft():T,D=t.createAbortController,H=D===void 0?function(){try{if(typeof window<"u"&&"AbortController"in window)return function(){return new window.AbortController};if("fetch"in globalThis)return function(){return new globalThis.AbortController}}catch(O){console.error('Unleash failed to resolve "AbortController" factory',O)}}():D,k=t.bootstrap,M=t.bootstrapOverride,G=M===void 0||M,K=t.headerName,V=K===void 0?"Authorization":K,q=t.customHeaders,B=q===void 0?{}:q,Y=t.impressionDataAll,Q=Y!==void 0&&Y,F=t.usePOSTrequests,W=F!==void 0&&F,u=o.call(this)||this;if(u.toggles=[],u.etag="",u.readyEventEmitted=!1,u.usePOSTrequests=!1,u.started=!1,!e)throw new Error("url is required");if(!i)throw new Error("clientKey is required");if(!S)throw new Error("appName is required.");return u.eventsHandler=new ct,u.impressionDataAll=Q,u.toggles=k&&k.length>0?k:[],u.url=e instanceof URL?e:new URL(e),u.clientKey=i,u.headerName=V,u.customHeaders=B,u.storage=r||(typeof window<"u"?new ot:new nt),u.refreshInterval=c?0:1e3*h,u.context=d({appName:S,environment:w},E),u.usePOSTrequests=W,u.sdkState="initializing",u.ready=new Promise(function(O){u.init().then(O).catch(function(L){console.error(L),u.sdkState="error",u.emit(v.ERROR,L),O()})}),R||console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'),H||console.error('Unleash: You must either provide your own "AbortController" implementation or run in an environment where "AbortController" is available.'),u.fetch=R,u.createAbortController=H,u.bootstrap=k&&k.length>0?k:void 0,u.bootstrapOverride=G,u.metrics=new rt({onError:u.emit.bind(u,v.ERROR),onSent:u.emit.bind(u,v.SENT),appName:S,metricsInterval:y,disableMetrics:x,url:u.url,clientKey:i,fetch:R,headerName:V,customHeaders:B}),u}return function(t,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function e(){this.constructor=t}U(t,r),t.prototype=r===null?Object.create(r):(e.prototype=r.prototype,new e)}(n,o),n.prototype.getAllToggles=function(){return function(t,r,e){for(var i,s=0,c=r.length;s<c;s++)!i&&s in r||(i||(i=Array.prototype.slice.call(r,0,s)),i[s]=r[s]);return t.concat(i||Array.prototype.slice.call(r))}([],this.toggles)},n.prototype.isEnabled=function(t){var r,e=this.toggles.find(function(c){return c.name===t}),i=!!e&&e.enabled;if(this.metrics.count(t,i),(e==null?void 0:e.impressionData)||this.impressionDataAll){var s=this.eventsHandler.createImpressionEvent(this.context,i,t,lt,(r=e==null?void 0:e.impressionData)!==null&&r!==void 0?r:void 0);this.emit(v.IMPRESSION,s)}return i},n.prototype.getVariant=function(t){var r,e=this.toggles.find(function(l){return l.name===t}),i=(e==null?void 0:e.enabled)||!1,s=e?e.variant:dt;if(s.name&&this.metrics.countVariant(t,s.name),this.metrics.count(t,i),(e==null?void 0:e.impressionData)||this.impressionDataAll){var c=this.eventsHandler.createImpressionEvent(this.context,i,t,ht,(r=e==null?void 0:e.impressionData)!==null&&r!==void 0?r:void 0,s.name);this.emit(v.IMPRESSION,c)}return d(d({},s),{feature_enabled:i})},n.prototype.updateToggles=function(){return b(this,void 0,void 0,function(){var t=this;return g(this,function(r){switch(r.label){case 0:return this.timerRef||this.readyEventEmitted?[4,this.fetchToggles()]:[3,2];case 1:return r.sent(),[3,4];case 2:return this.started?[4,new Promise(function(e){var i=function(){t.fetchToggles().then(function(){t.off(v.READY,i),e()})};t.once(v.READY,i)})]:[3,4];case 3:r.sent(),r.label=4;case 4:return[2]}})})},n.prototype.updateContext=function(t){return b(this,void 0,void 0,function(){var r;return g(this,function(e){switch(e.label){case 0:return(t.appName||t.environment)&&console.warn("appName and environment are static. They can't be updated with updateContext."),r={environment:this.context.environment,appName:this.context.appName,sessionId:this.context.sessionId},this.context=d(d({},r),t),[4,this.updateToggles()];case 1:return e.sent(),[2]}})})},n.prototype.getContext=function(){return d({},this.context)},n.prototype.setContextField=function(t,r){var e,i;if(J(t))this.context=d(d({},this.context),((e={})[t]=r,e));else{var s=d(d({},this.context.properties),((i={})[t]=r,i));this.context=d(d({},this.context),{properties:s})}this.updateToggles()},n.prototype.removeContextField=function(t){var r;J(t)?this.context=d(d({},this.context),((r={})[t]=void 0,r)):typeof this.context.properties=="object"&&delete this.context.properties[t],this.updateToggles()},n.prototype.init=function(){return b(this,void 0,void 0,function(){var t,r;return g(this,function(e){switch(e.label){case 0:return[4,this.resolveSessionId()];case 1:return t=e.sent(),this.context=d({sessionId:t},this.context),r=this,[4,this.storage.get(A)];case 2:return r.toggles=e.sent()||[],!this.bootstrap||!this.bootstrapOverride&&this.toggles.length!==0?[3,4]:[4,this.storage.save(A,this.bootstrap)];case 3:e.sent(),this.toggles=this.bootstrap,this.emit(v.READY),e.label=4;case 4:return this.sdkState="healthy",this.emit(v.INIT),[2]}})})},n.prototype.start=function(){return b(this,void 0,void 0,function(){var t,r=this;return g(this,function(e){switch(e.label){case 0:return this.started=!0,this.timerRef?(console.error("Unleash SDK has already started, if you want to restart the SDK you should call client.stop() before starting again."),[2]):[4,this.ready];case 1:return e.sent(),this.metrics.start(),t=this.refreshInterval,[4,this.fetchToggles()];case 2:return e.sent(),t>0&&(this.timerRef=setInterval(function(){return r.fetchToggles()},t)),[2]}})})},n.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},n.prototype.resolveSessionId=function(){return b(this,void 0,void 0,function(){var t;return g(this,function(r){switch(r.label){case 0:return this.context.sessionId?[2,this.context.sessionId]:[4,this.storage.get("sessionId")];case 1:return(t=r.sent())?[3,3]:(t=Math.floor(1e9*Math.random()),[4,this.storage.save("sessionId",t)]);case 2:r.sent(),r.label=3;case 3:return[2,t]}})})},n.prototype.getHeaders=function(){var t,r=this.usePOSTrequests,e=((t={})[this.headerName]=this.clientKey,t.Accept="application/json",t);return r&&(e["Content-Type"]="application/json"),this.etag&&(e["If-None-Match"]=this.etag),Object.entries(this.customHeaders).filter(N).forEach(function(i){var s=i[0],c=i[1];return e[s]=c}),e},n.prototype.storeToggles=function(t){return b(this,void 0,void 0,function(){return g(this,function(r){switch(r.label){case 0:return this.toggles=t,this.emit(v.UPDATE),[4,this.storage.save(A,t)];case 1:return r.sent(),[2]}})})},n.prototype.fetchToggles=function(){return b(this,void 0,void 0,function(){var t,r,e,i,s,c,l,h;return g(this,function(a){switch(a.label){case 0:if(!this.fetch)return[3,9];this.abortController&&this.abortController.abort(),this.abortController=this.createAbortController&&this.createAbortController(),t=this.abortController?this.abortController.signal:void 0,a.label=1;case 1:return a.trys.push([1,7,8,9]),r=this.usePOSTrequests,e=r?this.url:function(y,I){var x=new URL(y.toString());return Object.entries(I).filter(N).forEach(function(S){var p=S[0],w=S[1];p==="properties"&&w?Object.entries(w).filter(N).forEach(function(E){var T=E[0],R=E[1];return x.searchParams.append("properties[".concat(T,"]"),R)}):x.searchParams.append(p,w)}),x}(this.url,this.context),i=r?"POST":"GET",s=r?JSON.stringify({context:this.context}):void 0,[4,this.fetch(e.toString(),{method:i,cache:"no-cache",headers:this.getHeaders(),body:s,signal:t})];case 2:return c=a.sent(),this.sdkState==="error"&&c.status<400&&(this.sdkState="healthy",this.emit(v.RECOVERED)),c.ok&&c.status!==304?(this.etag=c.headers.get("ETag")||"",[4,c.json()]):[3,5];case 3:return l=a.sent(),[4,this.storeToggles(l.toggles)];case 4:return a.sent(),this.sdkState!=="healthy"&&(this.sdkState="healthy"),this.bootstrap||this.readyEventEmitted||(this.emit(v.READY),this.readyEventEmitted=!0),[3,6];case 5:c.ok||c.status===304||(console.error("Unleash: Fetching feature toggles did not have an ok response"),this.sdkState="error",this.emit(v.ERROR,{type:"HttpError",code:c.status})),a.label=6;case 6:return[3,9];case 7:return h=a.sent(),console.error("Unleash: unable to fetch feature toggles",h),this.sdkState="error",this.emit(v.ERROR,h),[3,9];case 8:return this.abortController=null,[7];case 9:return[2]}})})},n}(tt);const j=X.createContext(null),vt={bootstrap:[],disableRefresh:!0,disableMetrics:!0,url:"http://localhost",appName:"offline",clientKey:"not-used"},yt="startTransition",_=Z[yt]||(o=>o()),gt=({config:o,children:n,unleashClient:t,startClient:r=!0})=>{const e=o||vt,i=m.useRef(t||new pt(e)),[s,c]=m.useState(!!(t?o!=null&&o.bootstrap&&(o==null?void 0:o.bootstrapOverride)!==!1:e.bootstrap&&e.bootstrapOverride!==!1)),[l,h]=m.useState(null);m.useEffect(()=>{!e&&!t&&console.error(`You must provide either a config or an unleash client to the flag provider.
        If you are initializing the client in useEffect, you can avoid this warning
        by checking if the client exists before rendering.`);const p=R=>{_(()=>{h(D=>D||R)})},w=R=>{_(()=>{h(null)})};let E;const T=()=>{E=setTimeout(()=>{_(()=>{c(!0)})},0)};return i.current.on("ready",T),i.current.on("error",p),i.current.on("recovered",w),r&&(i.current.stop(),i.current.start()),function(){i.current&&(i.current.off("error",p),i.current.off("ready",T),i.current.off("recovered",w),i.current.stop()),E&&clearTimeout(E)}},[]);const a=async p=>{await i.current.updateContext(p)},y=p=>i.current.isEnabled(p),I=p=>i.current.getVariant(p),x=(p,w,E)=>i.current.on(p,w,E),S=m.useMemo(()=>({on:x,updateContext:a,isEnabled:y,getVariant:I,client:i.current,flagsReady:s,flagsError:l,setFlagsReady:c,setFlagsError:h}),[s,l]);return m.createElement(j.Provider,{value:S},n)},mt=o=>{const{isEnabled:n,client:t}=m.useContext(j),[r,e]=m.useState(!!n(o)),i=m.useRef();return i.current=r,m.useEffect(()=>{if(!t)return;const s=()=>{const l=n(o);l!==i.current&&(i.current=l,e(!!l))},c=()=>{const l=n(o);i.current=l,e(l)};return t.on("update",s),t.on("ready",c),()=>{t.off("update",s),t.off("ready",c)}},[t]),r},wt=()=>{const{updateContext:o}=m.useContext(j);return o};export{gt as I,wt as L,mt as O};
