1import{e as u}from"./env-zTj1AJea.js";import{u as U,F as M}from"./useFeatureFlag-BNuLgwFu.js";import{u as w,bw as p,F as T,bx as L,by as D,bz as V,D as K,x as X}from"./useGTM-6CiILgP4.js";import{m as A}from"./makeLangUrl-BfLIF9Nj.js";import{c as q,d as Q}from"./project-CEnLqcNQ.js";import"./brandProvider-0hDUM1C1.js";import{importShared as h}from"./__federation_fn_import-CEP4bGph.js";import{a as Z,G as k}from"./popupConfig-BpKA2D3Q.js";import{p as v,f as G,R as tt,g as P,a as et}from"./index3-Cnxw2M5F.js";import"./brandLogo-BW1Sybyw.js";import{u as nt}from"./useBreakpoint-Dt9SbD2v.js";import{analytics as st}from"./__federation_expose_Analytics-0aN8zFeH.js";import{j as g}from"./jsx-runtime-BjG_zV1W.js";import{a as I,M as it}from"./MainModal-BfdUB1KW.js";const B=u.VITE_APP_STAND==="prod"&&q,ot=u.VITE_APP_STAND==="prod"&&Q,Ne=B||ot,Fe=()=>{const{user:t}=w(),e=U(M.MF_NOTIFICATIONS,String(t?.id??""),{defaultValue:!1});return u.VITE_APP_STAND==="prod"?B&&!!e:e??!1},rt="/inapp",at=1e3,ct=3e4,lt=8,O=500,pt=100,x="[inapp]",ut="client shutdown",dt="frame too large";class ht{constructor(e,n,s){this.socket=new WebSocket(e,[n]),this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{s.onOpen()},this.socket.onmessage=i=>{s.onFrame(i.data)},this.socket.onclose=i=>{this.detach(),s.onClose(i.code,i.reason)}}get isOpen(){return this.socket.readyState===WebSocket.OPEN}send(e){this.isOpen&&this.socket.send(e)}close(){this.detach(),this.socket.close(1e3,ut)}detach(){this.socket.onopen=null,this.socket.onmessage=null,this.socket.onclose=null}}class _t{constructor(){this.invalidEnvelopes=0,this.unknownTypes=0}get isVerbose(){return!1}log(e,n){if(this.isVerbose){if(n){console.info(`${x} ${e}`,n);return}console.info(`${x} ${e}`)}}reportFatalFrame(e){this.log("connection closed",{reason:e})}reportInvalidUrl(e,n){this.log("invalid url",{url:e,error:n})}reportStopped(e){this.log("connection stopped",{attempts:e})}reportInvalidEnvelope(){this.invalidEnvelopes+=1,this.log("invalid envelope",{total:this.invalidEnvelopes})}reportUnknownType(e,n){this.unknownTypes+=1,this.log("unknown type",{scope:e,type:n,total:this.unknownTypes})}reset(){this.invalidEnvelopes=0,this.unknownTypes=0}}const o=new _t,C=t=>t.type==="user_context"?"context":"visibility",N=t=>t.type==="user_context"?`user_context:${t.state}`:t.type,gt=()=>typeof document>"u"||document.visibilityState==="visible";class ft{constructor(e){this.send=e,this.isVisible=gt(),this.context=null,this.lastSentAt=new Map,this.lastSentState=new Map,this.pending=new Map}get userContext(){return this.context}setVisible(e){this.isVisible=e,this.schedule(e?{type:"active_tab"}:{type:"inactive_tab"})}setContext(e){this.context=e,this.schedule({type:"user_context",state:e})}reassert(){this.lastSentAt.clear(),this.lastSentState.clear(),this.clearPending(),this.isVisible&&this.dispatch({type:"active_tab"}),this.context&&this.dispatch({type:"user_context",state:this.context})}dispose(){this.clearPending(),this.lastSentAt.clear(),this.lastSentState.clear()}schedule(e){if(this.lastSentState.get(C(e))===N(e)){this.clearPending(e.type);return}const n=Date.now()-(this.lastSentAt.get(e.type)??-1/0);if(n>=O){this.clearPending(e.type),this.dispatch(e);return}const s=this.pending.get(e.type);s&&clearTimeout(s.timer);const i=O-n+pt,r=setTimeout(()=>{const a=this.pending.get(e.type);this.pending.delete(e.type),a&&this.dispatch(a.event)},i);this.pending.set(e.type,{event:e,timer:r})}dispatch(e){this.lastSentAt.set(e.type,Date.now()),this.lastSentState.set(C(e),N(e)),this.send(e)}clearPending(e){if(e){const n=this.pending.get(e);n&&(clearTimeout(n.timer),this.pending.delete(e));return}this.pending.forEach(n=>clearTimeout(n.timer)),this.pending.clear()}}class yt{constructor(e=at,n=ct,s=lt){this.baseDelay=e,this.maxDelay=n,this.maxFailedAttempts=s,this.failedAttempts=0}get attempts(){return this.failedAttempts}get isExhausted(){return this.failedAttempts>=this.maxFailedAttempts}nextDelay(){if(this.isExhausted)return null;const e=Math.min(this.maxDelay,this.baseDelay*2**this.failedAttempts);return this.failedAttempts+=1,Math.round(e*(.5+Math.random()*.5))}reset(){this.failedAttempts=0}}class bt{constructor(){this.listeners=new Set}get size(){return this.listeners.size}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}
1publish(e){this.listeners.forEach(n=>n(e))}clear(){this.listeners.clear()}}const f=new bt,H=t=>f.subscribe(t),F=t=>{o.log("notification",{id:t.inbox_notification_id,scenario:t.trigger_scenario,category:t.category,priority:t.priority}),f.publish({kind:"notification",payload:t})},mt={toast:F,popup:F},St={active_tab_revoked:t=>{o.log("active tab revoked"),p.getState().setIsActiveTab(!1),f.publish({kind:"control",payload:t})}},Tt={read_sync:t=>{o.log("read sync",{ids:t.inbox_notification_ids.length,all:t.all}),f.publish({kind:"read_sync",payload:t})}},At={inbox_updated:t=>{o.log("inbox updated"),f.publish({kind:"inbox_updated",payload:t})}},b=(t,e,n)=>{const s=t[n.type];if(!s){o.reportUnknownType(e,n.type);return}s(n)},It=t=>{switch(p.getState().setLastMessageAt(Date.now()),t.kind){case"notification":b(mt,"notification",t.payload);break;case"control":b(St,"control",t.payload);break;case"read_sync":b(Tt,"read_sync",t.payload);break;case"inbox_updated":b(At,"inbox_updated",t.payload);break}},kt=new TextDecoder,y=t=>typeof t=="object"&&t!==null,S=t=>typeof t=="string"&&t.length>0,Et=t=>typeof t=="string",wt=t=>Array.isArray(t)&&t.every(e=>typeof e=="string"),Pt=t=>{const e=typeof t=="string"?t:kt.decode(t);return JSON.parse(e)},Ot=t=>y(t)&&S(t.type)&&S(t.inbox_notification_id)&&S(t.title_key)&&Et(t.body_key),xt=t=>y(t)&&t.type==="active_tab_revoked",Ct=t=>y(t)&&t.type==="read_sync"&&wt(t.inbox_notification_ids)&&typeof t.all=="boolean",Nt=t=>y(t)&&t.type==="inbox_updated",Ft=t=>{let e;try{e=Pt(t)}catch{return o.reportInvalidEnvelope(),null}if(!y(e)||!S(e.type))return o.reportInvalidEnvelope(),null;switch(e.type){case"toast":case"popup":return Ot(e)?{kind:"notification",payload:e}:(o.reportInvalidEnvelope(),null);case"read_sync":return Ct(e)?{kind:"read_sync",payload:e}:(o.reportInvalidEnvelope(),null);case"inbox_updated":return Nt(e)?{kind:"inbox_updated",payload:e}:(o.reportInvalidEnvelope(),null);case"active_tab_revoked":return xt(e)?{kind:"control",payload:e}:(o.reportInvalidEnvelope(),null);default:return null}};class Rt{constructor(e){this.config=e,this.socket=null,this.isConnecting=!1,this.isStopped=!1,this.generation=0,this.reconnectTimer=null,this.policy=new yt,this.onsite=new ft(n=>this.send(n))}get status(){return p.getState().status}get isStoppedByPolicy(){return this.isStopped}connect(){if(this.isStopped&&(this.isStopped=!1,this.policy.reset()),this.socket||this.isConnecting)return;const e=this.config.resolveUrl(),n=this.config.getToken();if(!e||!n){o.log("connect skipped",{hasUrl:!!e,hasToken:!!n});return}this.clearReconnectTimer(),this.isConnecting=!0,this.setStatus("connecting");const s=this.generation+=1;o.log("connecting",{url:e,attempt:this.policy.attempts});try{this.socket=new ht(e,n,{onOpen:()=>this.handleOpen(s),onFrame:i=>this.handleFrame(s,i),onClose:(i,r)=>this.handleClose(s,i,r)})}catch(i){this.isConnecting=!1,this.socket=null,o.reportInvalidUrl(e,i),this.stop()}}disconnect(){this.isStopped=!1,this.policy.reset(),this.clearReconnectTimer(),this.onsite.dispose(),this.closeSocket(),this.setStatus("idle"),p.getState().setIsActiveTab(!1)}reconnectWithFreshToken(){this.disconnect(),this.connect()}setVisible(e){this.onsite.setVisible(e),e&&(p.getState().setIsActiveTab(!0),this.isStopped&&this.connect())}setContext(e){this.onsite.setContext(e)}send(e){this.socket?.isOpen&&(o.log("send",e),this.socket.send(JSON.stringify(e)))}handleOpen(e){e===this.generation&&(this.isConnecting=!1,this.policy.reset(),this.setStatus("open"),o.log("open"),this.onsite.reassert())}handleFrame(e,n){if(e!==this.generation)return;const s=Ft(n);s&&It(s)}handleClose(e,n,s){if(e===this.generation){if(this.isConnecting=!1,this.socket=null,this.setStatus("closed"),o.log("closed",{code:n,reason:s}),s===dt){o.reportFatalFrame(s),this.stop();return}this.scheduleReconnect()}}scheduleReconnect(){const e=this.policy.nextDelay();if(e===null){o.reportStopped(this.policy.attempts),this.stop();return}o.log("reconnect scheduled",{attempt:this.policy.attempts,delay:e}),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},e)}stop(){this.isStopped=!0,this.clearReconnectTimer(),this.setStatus("stopped"),o.log("stopped",{attempts:this.policy.attempts})}closeSocket(){this.socket&&(this.generation+=1,this.socket.close(),this.socket=null,this.isConnecting=!1)}clearReconnectTimer(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}setStatus(e){p.getState().setStatus(e)}}const Ut=()=>{const{host:t}=window.location;return console.log(t,"check host wss"),t.includes("techdivinecas.co")&&t.includes("stage")?"wss://ws.stage.techdivinecas.co":t.match(/localhost/g)||t.includes("192.")||t.includes("dev.")?u.VITE_APP_SOCKET_HOST:t.match(/stage/g)?`wss://ws.${t}/`:t.match(/\b(dev)\b/g)||!t.startsWith("dev")&&!t.startsWith("192.")?`wss://ws.${t}/`:`wss://ws.${t}/`},Mt=()=>null,Lt=t=>`${t.replace(/\/+$/,"")}${rt}`,Dt=()=>{const t=Mt();if(t)return t;
1if(u.VITE_APP_INAPP_WS_URL)return u.VITE_APP_INAPP_WS_URL;const e=Ut();return e?Lt(e):null},c=new Rt({resolveUrl:Dt,getToken:v}),Vt=(t,e)=>{if(!t||!e||!v()){c.disconnect();return}c.connect()},{matchPath:R}=await h("react-router-dom"),vt="/game/:game",E=(t,e)=>!!R({path:e},t)||!!R({path:`/:lang${e}`},t),W=t=>E(t,T.config.casino.game)||E(t,vt),Gt=t=>E(t,T.config.fortuneWheel.root),Bt=new Set([k.popup.deposit,k.popup.withdraw]),Ht=t=>{const e=new URLSearchParams(t).get(Z.POPUP);return e!==null&&Bt.has(e)},Wt=(t,e="")=>Ht(e)?"in_cashier":Gt(t)?"in_fortune_wheel":W(t)?"in_game":"lobby",{useEffect:d,useRef:$t}=await h("react"),{useLocation:jt}=await h("react-router-dom"),Re=()=>{const{pathname:t,search:e}=jt(),{user:n,isAuthenticated:s}=w(),i=U(M.INAPP_NOTIFICATIONS,String(n?.id??""),{defaultValue:!1}),r=$t(null);d(()=>{Vt(!!i,s)},[i,s]),d(()=>{if(!s||!n){r.current=null;return}r.current!==null&&r.current!==n.id&&c.reconnectWithFreshToken(),r.current=n.id},[n,s]),d(()=>{c.setContext(Wt(t,e))},[t,e]),d(()=>{const a=l=>{if(l.key===G){if(!l.newValue||!i||!s){c.disconnect();return}c.reconnectWithFreshToken()}};return window.addEventListener("storage",a),()=>{window.removeEventListener("storage",a)}},[i,s]),d(()=>{const a=()=>{c.setVisible(document.visibilityState==="visible")},l=()=>{c.setVisible(!0)};return document.addEventListener("visibilitychange",a),window.addEventListener("focus",l),()=>{document.removeEventListener("visibilitychange",a),window.removeEventListener("focus",l)}},[]),d(()=>()=>c.disconnect(),[])},Yt={"one-button":"popup-one-button","two-buttons":"popup-two-buttons"},zt=t=>{const e=t.image_url||t.variables?.image_url;if(!e)return null;if(L(e))return e;const n=D();return n?V(n,e):null},Jt=t=>({label:t.button_label||t.variables?.popup_button_label||"",deeplink:t.button_link||t.variables?.popup_deeplink||null}),Kt=t=>{const e=t.secondary_button_label||t.variables?.popup_secondary_button_label;if(!e)return null;const n=t.secondary_button_link||t.variables?.popup_secondary_deeplink||null;return{label:e,type:n?"link":"close",deeplink:n}},Xt=t=>t.variables?.popup_template_id||Yt[t.variant],qt=t=>({mode:t.timer_mode,endsAt:t.timer_end_at||t.variables?.popup_timer_end_at||null}),Qt=t=>{const e=t.variables??{},n=Jt(t);return{id:t.inbox_notification_id,definitionId:t.inbox_notification_id,triggerScenario:t.trigger_scenario,category:t.category,priority:t.priority,occurredAt:t.occurred_at??new Date().toISOString(),expiresAt:null,readStatus:"unread",link:n.deeplink,popup:{type:"popup",contentId:t.inbox_notification_id,title:t.title_key,body:t.body_key,raw:t.raw,variables:e,typedVariables:t.typed_variables,templateId:Xt(t),variant:t.variant,imageUrl:zt(t),primaryAction:n,secondaryAction:Kt(t),timer:qt(t)}}},Zt={Transactional:{iconType:"info",color:"blue"},Promo:{iconType:"success",color:"green"},System:{iconType:"warning",color:"yellow"}},te=["success","info","warning","error","neutral"],ee=["green","blue","yellow","red","grey"],ne=t=>te.includes(t),se=t=>ee.includes(t),ie=(t,e)=>{const n=Zt[e],s=ne(t.toast_icon_type)?t.toast_icon_type:n.iconType,i=se(t.toast_color)?t.toast_color:n.color;return{iconType:s,color:i}},oe=t=>{const e=t.icon_url;if(!e)return null;if(L(e))return e;const n=D();return n?V(n,e):null},re=t=>{const e=t.toast_deeplink||null,n=t.toast_button_label||null;return t.toast_action_type==="cta"&&!!e&&!!n?{type:"cta",label:n,deeplink:e}:{type:"close",label:null,deeplink:null}},ae=t=>{const e=t.variables??{},n=ie(e,t.category);return{id:t.inbox_notification_id,definitionId:t.inbox_notification_id,triggerScenario:t.trigger_scenario,category:t.category,priority:t.priority,occurredAt:t.occurred_at??new Date().toISOString(),expiresAt:null,readStatus:"unread",link:t.link??null,toast:{type:"toast",contentId:t.inbox_notification_id,title:t.title_key,body:t.body_key,raw:t.raw,variables:e,typedVariables:t.typed_variables,iconType:n.iconType,color:n.color,subtitle:e.toast_subtitle||null,iconUrl:oe(e),action:re(e)}}},{Icon:$}=await h("@ui-kit-casino/icons"),ce={small:I.SMALL,big:I.BIG,huge:I.HUGE},le=({size:t="big",...e})=>g.jsx(it,{...e,size:ce[t],closeIcon:g.jsx($,{name:"CloseCircle24",size:24})}),pe=t=>g.jsx(tt,{...t}),ue=({isOpened:t,handleOnClose:e,...n})=>g.jsx(K,{...n,onClose:e,height:"auto",closeIcon:g.jsx($,{name:"CloseCircle24",size:24}),closeOnOutsideClick:!0}),{useMemo:m}=await h("react"),{useLocation:de,useNavigate:he}=await h("react-router-dom"),_e=t=>H(e=>{if(e.kind==="notification"){if(e.payload.type==="popup"){t(Qt(e.payload));return}t(ae(e.payload))}}),ge=t=>{const e=H(i=>{i.kind==="inbox_updated"&&t()});let n=p.getState().status;const s=p.subscribe(i=>{i.status==="open"&&n!=="open"&&n!=="idle"&&t(),n=i.status});return()=>{e(),s()}},fe="12px",Ue=()=>{const{user:t,isAuthenticated:e}=w(),{isDesktop:n}=nt(),{openPopup:s}=X(),i=he(),{pathname:r}=de(),a=W(r),l=m(()=>P(et)||null,[]),j=m(()=>P(G)||null,[e,t?.id]),Y=m(()=>({onNavigateToInbox:()=>i(A(T.routes.profile.notification())),onOpenNotification:()=>i(A(T.routes.profile.notification())),onFollowLink:_=>{if(_.startsWith("/")){i(A(_));return}window.open(_,"_blank","noopener,noreferrer")},onOpenDeposit:()=>s(k.popup.deposit)}),[i,s]),z=m(()=>({subscribe:_e,onInboxShouldResync:ge}),[]);return!e||!t?null:{token:j,fliptToken:u.VITE_APP_FLIPT_TOKEN||null,appVersion:u.VITE_APP_VERSION_APP,projectName:"glory",user:{id:t.id,name:t.name,login:t.login,language:l,currencyCode:t.currencyCode},language:l,isDesktop:n,analyticsEvents:{trackEvent:(_,J)=>st.track(_,J),getCampainId:()=>new URLSearchParams(window.location.search).get("campaign_id")??void 0,getTimeStamp:()=>new Date().toISOString()},navigation:Y,ui:{MainModal:le,BottomSheet:ue,Input:pe},notifications:z,toastTopOffset:a?fe:void 0}};export{B as I,Fe as a,Ne as b,Re as c,W as i,Ut as s,Ue as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.