import{i as f,ae as g,af as h,g as n,e as m,p as b,f as P,s as w,au as y,aJ as A,u as C}from"./index-CIAVq8iD-1776148658686.js";const v=C(),H=e=>{e.message&&e.message.includes("parse access")&&v.push({path:"/not_app",query:{message:e.message}})},r=async()=>{try{console.debug("👤 Fetching user info after connection...");const e=await y();e&&e.status&&e.body?(console.debug("✅ User info cached successfully"),A(e.body,null)):console.warn("⚠️ Failed to get team entry or invalid response")}catch(e){console.warn("⚠️ Failed to fetch user info after connection:",e)}},I=async(e,c=H)=>{console.group("🔗 APP Connection Process"),console.debug("🚀 Starting APP connection...");try{if(!f())return console.debug("🌐 Browser environment detected"),await w({authorization:"",reqLang:navigator.language&&navigator.language.toLowerCase().startsWith("ar")?"ar":navigator.language&&navigator.language.toLowerCase().startsWith("tr")?"tr":navigator.language&&navigator.language.toLowerCase().startsWith("bn")?"bn":"en",appVersion:"1.0.0",buildVersion:"1",appChannel:"Web",reqImei:"H5-STATIC",sysOrigin:"LIKEI",sysOriginChild:"LIKEI"}),console.groupEnd(),await r(),e&&e(),{success:!0,environment:"browser"};if(g())return console.debug("✅ APP already connected and valid"),h()&&console.debug("🔧 Using cached HTTP headers"),console.groupEnd(),await r(),e&&e(),{success:!0,environment:"app",fromCache:!0};if(n.isConnecting())return console.debug("⏳ Connection already in progress, waiting..."),await n.getConnectionPromise(),console.debug("✅ Connected via existing process"),console.groupEnd(),await r(),e&&e(),{success:!0,environment:"app",fromCache:!0};console.debug("📱 Establishing new APP connection...");const o=await new Promise((t,l)=>{const a=new Promise((d,i)=>{m(async p=>{try{const s=b(p);if(s.success){const u=P(s.data);console.debug("🔧 Setting HTTP headers..."),await w(u),n.setConnected(u),console.debug("🎉 APP connection established successfully"),d({success:!0,environment:"app",fromCache:!1})}else console.error("❌ Failed to parse access origin:",s.error),n.reset(),i(new Error(s.error))}catch(s){console.error("❌ Connection process failed:",s),n.reset(),i(s)}})});n.setConnecting(a),a.then(t).catch(l)});return console.debug("✅ Connection completed successfully"),console.groupEnd(),await r(),e&&e(),o}catch(o){return console.error("❌ Connection failed:",o),console.groupEnd(),c&&c(o),{success:!1,error:o.message}}};export{I as c};
