@retion-miniapp/react-native 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Sr=Object.create;var bt=Object.defineProperty;var _r=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames;var Mr=Object.getPrototypeOf,xr=Object.prototype.hasOwnProperty;var Er=(e,t)=>{for(var n in t)bt(e,n,{get:t[n],enumerable:!0})},Pn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of vr(t))!xr.call(e,r)&&r!==n&&bt(e,r,{get:()=>t[r],enumerable:!(o=_r(t,r))||o.enumerable});return e};var le=(e,t,n)=>(n=e!=null?Sr(Mr(e)):{},Pn(t||!e||!e.__esModule?bt(n,"default",{value:e,enumerable:!0}):n,e)),Cr=e=>Pn(bt({},"__esModule",{value:!0}),e);var Pi={};Er(Pi,{CodeType:()=>te,DefaultMiniAppSplash:()=>_n,MINIAPP_PLATFORM_URL:()=>Je,MiniAppHost:()=>yr,MiniAppHostError:()=>g,ScannerEndReason:()=>We,ScannerEvent:()=>Et,ScannerLayout:()=>pe,ScannerMethod:()=>Ke,ToastType:()=>me,closeMiniApp:()=>Qe,configureMiniApp:()=>Tn,createMmkvStorage:()=>In,createReactNativeBiometrics:()=>jt,createRnfsFileSystem:()=>kn,ensureMiniApp:()=>ft,fetchMiniAppChangelog:()=>xn,getLocalMiniApp:()=>N,getMiniAppCatalog:()=>gr,getMiniAppCatalogEntry:()=>Ze,getMiniAppChangelogSeen:()=>vn,getMiniAppStatuses:()=>rr,getMiniAppUpdate:()=>An,getPendingChangelog:()=>br,installBundledMiniApp:()=>Bo,markMiniAppChangelogSeen:()=>Mn,onMiniAppEvent:()=>or,openMiniApp:()=>Xo,pauseMiniApp:()=>cr,pauseMiniAppDownloads:()=>pr,preloadMiniApp:()=>Qo,releaseSpeechFor:()=>Ce,restoreMiniApp:()=>ar,resumeMiniApp:()=>lr,resumeMiniAppDownloads:()=>ur,sendEventToWeb:()=>zo,syncMiniAppCatalog:()=>qt,uninstallMiniApp:()=>sr,updateMiniApp:()=>dr,uploadToUrl:()=>Kt,useMiniAppChangelog:()=>Ar,useMiniAppDownload:()=>Vt,useMiniAppDownloadsPaused:()=>nr});module.exports=Cr(Pi);var Je="https://retion-miniapp-platform.vercel.app",qe=null,Rn=new Set,Tn=e=>{qe=e,Rn.forEach(t=>t())},D=()=>{if(!qe)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return qe},On=e=>{Rn.add(e),qe&&e()},he=(...e)=>{qe!=null&&qe.debug&&console.log("[miniapp]",...e)};var kn=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:c,contentLength:l})=>r==null?void 0:r(c,l)});return{promise:a.then(({statusCode:c})=>({status:c})),cancel:()=>e.stopDownload(i)}}}),In=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var S=le(require("react")),I=require("react-native"),fr=le(require("react-native-webview"));var lt=require("react-native");var jt=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),At,Ht=()=>(At||(At=import("react-native-biometrics").then(({default:e})=>jt(new e({allowDeviceCredentials:!1}))).catch(e=>{throw At=void 0,new g("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),At);var Ee=require("react-native");var Ln=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new g("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new g("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new g("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Fn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new g("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(Ee.Platform.OS==="android"){let s=Ee.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,d=Ee.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,u=await Ee.PermissionsAndroid.check(s);if(!c())return;let y=u||await Ee.PermissionsAndroid.check(d);if(!c())return;if(!u&&!y){let p=await Ee.PermissionsAndroid.requestMultiple([s,d]);if(!c())return;if(p[s]!==Ee.PermissionsAndroid.RESULTS.GRANTED&&p[d]!==Ee.PermissionsAndroid.RESULTS.GRANTED)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var u;if(!c())return;let d=(u={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?u:"LOCATION_ERROR";i(new g(d,s.message))},e)}})().catch(l=>i(l))});var Gt=require("react-native");var Jt=20,Dn=20,$n=/^[a-z][a-z0-9_-]{0,31}$/,Pr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,Rr=["low","medium","high"],Ie=e=>!!e&&typeof e=="object"&&!Array.isArray(e),X=e=>new g("INVALID_PARAMS",e),st=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Nn=(e,t)=>{if(e===void 0)return{};if(!Ie(e)||Object.keys(e).length>Dn||Object.values(e).some(n=>typeof n!="string"))throw X(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Dn} key)`);return e},zn=e=>{var n,o,r,i;if(e!==void 0&&!Ie(e))throw X("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!$n.test(t.source)))throw X("source ph\u1EA3i l\xE0 t\xEAn ngu\u1ED3n, vd library | camera | document");if(t.accept!==void 0&&(!Array.isArray(t.accept)||t.accept.length>50||t.accept.some(a=>typeof a!="string"||!Pr.test(a))))throw X("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!st(t.max_count,1,Jt))throw X(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Jt}`);if(t.max_size!==void 0&&!st(t.max_size,1,Number.MAX_SAFE_INTEGER))throw X("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!st(t.concurrency,1,5))throw X("concurrency ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u20135");return{source:(n=t.source)!=null?n:"library",accept:((o=t.accept)!=null?o:[]).map(a=>a.toLowerCase()),max_count:(r=t.max_count)!=null?r:1,max_size:t.max_size,process:Tr(t.process),target:Or(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},Tr=e=>{if(e===void 0)return{};if(!Ie(e))throw X("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Ie(n))throw X("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!st(n[o],1,1e4))throw X(`process.image.${o} ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u201310000`);if(n.quality!==void 0&&(typeof n.quality!="number"||n.quality<=0||n.quality>1))throw X("process.image.quality ph\u1EA3i trong kho\u1EA3ng (0, 1]");t.image={max_width:n.max_width,max_height:n.max_height,quality:n.quality}}if(e.video!==void 0){let n=e.video;if(!Ie(n))throw X("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!st(n.max_duration,1,3600))throw X("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!Rr.includes(n.quality))throw X("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},Or=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Ie(e))throw X("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!$n.test(t))throw X("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Ie(e.params))throw X("upload.params ph\u1EA3i l\xE0 object");return{target:t,params:(o=e.params)!=null?o:{}}}if(typeof e.url!="string"||!/^https:\/\//i.test(e.url))throw X("upload.url ph\u1EA3i l\xE0 https");for(let a of["field_name","url_field"])if(e[a]!==void 0&&(typeof e[a]!="string"||!e[a]))throw X(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Nn(e.headers,"upload.headers"),form_data:Nn(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},Wn=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},kr=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Wn(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Ir=e=>{let t=e.length>0&&e.every(o=>o.startsWith("image/")),n=e.length>0&&e.every(o=>o.startsWith("video/"));return t?"image":n?"video":"mixed"},ot,Lr=()=>(ot!=null||(ot=import("react-native-image-picker").catch(e=>{throw ot=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),ot),Un=e=>async({accept:t,max_count:n,process:o})=>{var l,s,d,u,y,p,f,O,R;let r=await Lr(),i=Ir(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(u=(d=o.image)==null?void 0:d.quality)!=null?u:.8,videoQuality:(p=(y=o.video)==null?void 0:y.quality)!=null?p:"medium",durationLimit:(f=o.video)==null?void 0:f.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let C=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new g(C,(O=c.errorMessage)!=null?O:c.errorCode)}return((R=c.assets)!=null?R:[]).filter(C=>C.uri).map((C,M)=>{var q,W,oe;return{uri:C.uri,name:(q=C.fileName)!=null?q:`file_${M+1}`,mime_type:(W=C.type)!=null?W:"application/octet-stream",size:C.fileSize,width:C.width,height:C.height,duration:C.duration,processed:!((oe=C.type)!=null&&oe.startsWith("video/"))||Gt.Platform.OS==="ios"}})},Fr={"image/*":"images","video/*":"video","audio/*":"audio","text/plain":"plainText","text/csv":"csv","application/pdf":"pdf","application/json":"json","application/zip":"zip","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx"},Dr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},Nr=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var d;return(d=Fr[s])!=null?d:Dr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let d=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(p=>p.uri&&!p.error).map((p,f)=>{var O,R,C;return{uri:p.uri,name:(O=p.name)!=null?O:`file_${f+1}`,mime_type:(R=p.type)!=null?R:"application/octet-stream",size:(C=p.size)!=null?C:void 0}});if(Gt.Platform.OS!=="android"||!e.keepLocalCopy||!d.some(p=>p.uri.startsWith("content://")))return d;let u=await e.keepLocalCopy({files:d.map(p=>({uri:p.uri,fileName:p.name})),destination:"cachesDirectory"}),y=new Map(u.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var f;return{...p,uri:(f=y.get(p.uri))!=null?f:p.uri}})}catch(s){let d=s==null?void 0:s.code;if(d===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw d===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new g("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},rt,Ur=async e=>(rt!=null||(rt=import("@react-native-documents/picker").then(t=>Nr(t)).catch(t=>{throw rt=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await rt)(e)),jn={library:Un("library"),camera:Un("camera"),document:Ur},Vn={type:"image",label:"\u1EA2nh",accept:["image/*"]},Bn={type:"video",label:"Video",accept:["video/*"]},qn={library:[Vn,Bn],camera:[Vn,Bn],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},it,Hn=()=>(it!=null||(it=import("react-native-compressor").catch(()=>(it=void 0,null))),it),Jn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Vr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Br={low:640,medium:1280,high:1920},qr=async(e,{image:t})=>{var o;if(!t||!Vr.has(e.mime_type.toLowerCase()))return e;let n=await Hn();if(!n)return e;try{let r=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(o=t.quality)!=null?o:.8,output:"jpg"});return{...e,uri:r,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await Jn(n,r,e.size),processed:!0}}catch{return e}},$r=async(e,{video:t})=>{var o;let n=await Hn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Br[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Jn(n,r,e.size),processed:!0}}catch{return e}},zr={image:qr,video:$r},Wr=(e,t)=>t.split(".").reduce((n,o)=>Ie(n)?n[o]:void 0,e),Kt=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new g("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([u,y])=>l.append(u,y)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let d=u=>{o.removeEventListener("abort",s),u()};c.open("POST",a.url),Object.entries(a.headers).forEach(([u,y])=>c.setRequestHeader(u,y)),c.upload.onprogress=u=>n(u.loaded,u.total||e.size||0),c.onload=()=>d(()=>{let u=c.responseText;try{u=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new g("UPLOAD_FAILED",`HTTP ${c.status}`));return}let y=Wr(u,a.url_field);if(typeof y!="string"||!y){i(new g("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:y,response:u})}),c.onerror=()=>d(()=>i(new g("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>d(()=>i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),Gn=e=>{var o,r;let t={...jn};for(let[i,a]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))a?t[i]=a:delete t[i];let n={url:Kt};for(let[i,a]of Object.entries((r=e==null?void 0:e.targets)!=null?r:{}))i!=="url"&&a&&(n[i]=a);return{sources:t,targets:n}},Kn=e=>{let{sources:t,targets:n}=Gn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===jn[i]&&qn[i]).map(i=>[i,qn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Jt}},_t=new Map,Yn=(e,t)=>`${e}:${t}`,jr=0,Xn=(e,t)=>{var n;typeof t=="string"&&((n=_t.get(Yn(e,t)))==null||n.abort())},$e=e=>{for(let[t,n]of _t)t.startsWith(`${e}:`)&&n.abort()},St=()=>new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Hr=(e,t)=>{var n;return{name:e,code:typeof(t==null?void 0:t.code)=="string"?t.code:"UPLOAD_FAILED",message:String((n=t==null?void 0:t.message)!=null?n:t)}},Qn=async(e,t)=>{var l;let{sources:n,targets:o}=Gn(t.config),r=n[e.source];if(!r)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=Yn(t.instance_id,(l=t.task_id)!=null?l:`auto-${++jr}`);_t.set(c,a);try{return await Jr(e,t,r,i,a.signal)}finally{_t.delete(c)}},Jr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=u=>u()},l,s,d)=>{var E,m,T;let u={app_id:n!=null?n:"",instance_id:t,context:{...(E=o==null?void 0:o())!=null?E:{}}},y=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:u}))).slice(0,e.max_count);if(d.aborted)throw St();if(!y.length)throw new g("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],f=y.filter(x=>kr(x,e.accept)?!0:(p.push({name:x.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${x.mime_type||Wn(x.name)}`}),!1)),O=f.map(()=>0),R=f.map(x=>{var V;return(V=x.size)!=null?V:0}),C=0,M=0,q=(x=!1)=>{if(!a||!r)return;let V=Date.now();if(!x&&V-M<200)return;M=V;let Ae=R.reduce((L,re)=>L+re,0),Y=O.reduce((L,re)=>L+re,0);a("upload.progress",{task_id:r,loaded:Y,total:Ae,percent:Ae?Math.min(100,Math.round(Y/Ae*100)):0,done_count:C,count:f.length})},W=[],oe=0,Pe=async()=>{var x,V,Ae;for(;oe<f.length;){let Y=oe++,L=f[Y];try{if(d.aborted)throw St();let re=L.mime_type.startsWith("image/")?"image":L.mime_type.startsWith("video/")?"video":void 0,G=re&&!L.processed?(V=(x=i==null?void 0:i.processors)==null?void 0:x[re])!=null?V:zr[re]:void 0;if(G&&(L=await G(L,e.process),R[Y]=(Ae=L.size)!=null?Ae:R[Y],d.aborted))throw St();if(e.max_size&&L.size&&L.size>e.max_size)throw new g("FILE_TOO_LARGE",`File ${L.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let ee=(He,xe)=>{O[Y]=He,xe&&(R[Y]=xe),q()},ie=await s({file:L,target:e.target,onProgress:ee,signal:d,caller:u});if(typeof(ie==null?void 0:ie.url)!="string"||!ie.url)throw new g("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:ve,...Me}=ie;W[Y]={url:ve,name:L.name,mime_type:L.mime_type,size:L.size,width:L.width,height:L.height,duration:L.duration,...Object.keys(Me).length?{response:"response"in Me?Me.response:Me}:{}},O[Y]=R[Y]}catch(re){p.push(Hr(f[Y].name,re))}finally{C++,q(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,f.length)},Pe)),d.aborted)throw St();let ce=W.filter(x=>!!x);if(!ce.length){let x=p[0];throw new g((m=x==null?void 0:x.code)!=null?m:"UPLOAD_FAILED",(T=x==null?void 0:x.message)!=null?T:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:ce,failed:p}};var vt=require("react"),Le=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},H=(e,t,n=Object.is)=>{let o=(0,vt.useRef)(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return(0,vt.useSyncExternalStore)(e.subscribe,r)};var me={info:"info",success:"success",error:"error"},Gr=200,Zn={info:2e3,success:2e3,error:3e3},at=Le({message:"",type:me.info,tick:0}),eo=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Gr);return o?{message:o,type:Object.values(me).includes(n)?n:me.info}:null},to=(e,t=me.info)=>{at.setState(n=>({message:e,type:t,tick:n.tick+1}))};var ye=require("react-native");var ze=require("react-native");var fe,Ge=new Map,no=(e,t)=>{var o;let n=(o=Ge.get(e))!=null?o:new Set;n.add(t),Ge.set(e,n)},oo=(e,t)=>{let n=Ge.get(e);n&&(t?n.delete(t):n.clear(),n.size===0&&Ge.delete(e))},Xt=new Map,ro=(e,t)=>{Xt.set(e,t)},io=e=>Xt.get(e),so=()=>ze.Platform.OS==="android"&&!!(fe!=null&&fe.requesting_permission),Kr=1500,Mt=()=>new Promise(e=>{if(ze.Platform.OS!=="android"||ze.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Kr),o=ze.AppState.addEventListener("change",r=>{r==="active"&&t()})}),Yt=e=>{var t;if(fe===e&&(fe=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&ze.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},ao=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(fe)throw new g("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};fe=r;try{let d;try{d=await import("expo-speech-recognition")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let u=d.ExpoSpeechRecognitionModule;if(r.native=u,r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let y;try{y=await u.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await Mt(),r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.granted)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await u.getStateAsync()!=="inactive")throw new g("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(u.addListener("result",p=>{var f,O;fe!==r||r.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(O=(f=p.results[0])==null?void 0:f.transcript)!=null?O:""})}),u.addListener("error",p=>{fe===r&&!r.cancelled&&n("speech.error",{...p,code:p.error})}),u.addListener("end",()=>{fe===r&&(Yt(r),n("speech.end"))})),r.started=!0,u.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:d.AVAudioSessionCategory.playAndRecord,categoryOptions:[d.AVAudioSessionCategoryOptions.defaultToSpeaker,d.AVAudioSessionCategoryOptions.allowBluetooth],mode:d.AVAudioSessionMode.measurement}})}catch(d){throw Yt(r),d}},co=e=>{let t=fe;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Ce=e=>{Xt.delete(e);let t=Ge.get(e);Ge.delete(e),t==null||t.forEach(o=>{var r;try{(r=o.release)==null||r.call(o,e)}catch{}});let n=fe;if(!(!n||n.owner!==e||n.cancelled)&&(n.cancelled=!0,n.started))try{n.native.abort()}catch{Yt(n)}};var lo={qr:"qr",ean13:"ean-13",ean8:"ean-8",upcA:"upc-a",upcE:"upc-e",code128:"code-128",code39:"code-39",code93:"code-93",codabar:"codabar",itf:"itf",pdf417:"pdf-417",aztec:"aztec",dataMatrix:"data-matrix"},te={...lo,all:Object.values(lo)},Ke={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Et={result:"scanner.result",end:"scanner.end"},We={user:"user",web:"web",closed:"closed",error:"error"},pe={top:"top",full:"full"},Fe={once:"once",continuous:"continuous"},Yr=1500,po=6e4,z,Q=Le({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),go=()=>ye.Platform.OS==="android"&&!!(z!=null&&z.requesting_permission),Zt=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r,absolute:i}=e!=null?e:{},a={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(c=>te.all.includes(c)))throw new g("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");a.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>po)throw new g("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${po}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new g("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(pe).includes(r))throw new g("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new g("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},en=e=>z!==e?!1:(z=void 0,Q.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Xr=()=>ye.Alert.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{ye.Linking.openSettings().catch(()=>{})}}]),ho=async(e,t)=>{if(z)throw new g("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");z=e;let n=()=>{if(e.cancelled||!t())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=ye.Platform.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await Mt(),n(),c!=="granted")throw a&&Xr(),new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new g("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await tn();n(),Q.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,absolute:e.absolute,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw en(e),o}},xt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{xt=e==null?void 0:e.insets}).catch(()=>{});var Ct=()=>{var e;return xt!=null?xt:{top:ye.Platform.OS==="ios"?54:(e=ye.StatusBar.currentHeight)!=null?e:0,bottom:ye.Platform.OS==="ios"?34:48}},tn=async()=>{if(ye.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},mo=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:te.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Yr,hint:n.hint,layout:t===Fe.once?pe.full:(i=n.layout)!=null?i:pe.top,absolute:t!==Fe.once&&((a=n.layout)!=null?a:pe.top)===pe.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},fo=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=mo(e,Fe.once,t);a.onHit=o,a.resolve=r,a.reject=i,ho(a,n).catch(i)}),yo=(e,t,n,o=()=>!0,r)=>{let i=mo(e,Fe.continuous,t);return i.emit=n,i.onHit=r,ho(i,o)},Pt=(e,t,n)=>{var o,r;if(!Q.getState().active){e.cancelled=!0;return}if(en(e)){if(e.mode===Fe.once){(o=e.reject)==null||o.call(e,t===We.error?new g("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new g("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,Et.end,n?{reason:t,message:n}:{reason:t})}},wo=e=>{(z==null?void 0:z.owner)===e&&Pt(z,We.web)},De=e=>{(z==null?void 0:z.owner)===e&&Pt(z,We.closed)},nn=()=>{z&&Pt(z,We.user)},bo=e=>{z&&Pt(z,We.error,e)},on=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=z;if(!(!o||!Q.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(o.last_seen.set(c,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Fe.once){en(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}Q.setState(d=>({last_value:c,hit_tick:d.hit_tick+1,scan_count:d.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,Et.result,{value:c,type:l})}}},Qr={1:te.code128,2:te.code39,4:te.code93,8:te.codabar,16:te.dataMatrix,32:te.ean13,64:te.ean8,128:te.itf,256:te.qr,512:te.upcA,1024:te.upcE,2048:te.pdf417,4096:te.aztec},Zr=2500,uo=2e3,Qt=e=>{Q.setState({notice:e}),setTimeout(()=>{Q.getState().notice===e&&Q.setState({notice:null})},Zr)},Ao=async()=>{var t,n;let e=z;if(!(!e||Q.getState().is_picking)){e.requesting_permission=!0,Q.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:uo,maxHeight:uo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||z!==e)return;if(r.errorCode||!i){Qt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(z!==e)return;let l=c.map(({value:s,format:d})=>({value:s,code_type:Qr[d]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:d})=>({value:s,type:d!=null?d:"unknown"}));if(!l.length){Qt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}on(l,Date.now(),!0)}catch{z===e&&Qt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await Mt(),e.requesting_permission=!1,z===e&&Q.setState({is_picking:!1})}}};var Tt=1,g=class extends Error{constructor(n,o){super(o);this.code=n}},So=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Tt&&typeof t.method=="string"?t:null}catch{return null}},pt=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,_o=(e,t)=>pt({id:e,result:t}),vo=(e,t)=>pt({id:e,error:{code:t.code,message:t.message}}),Mo=(e,t)=>pt({event:e,data:t}),sn=e=>pt({event:"context",data:e});var xo=()=>`(function () {
1
+ "use strict";var qr=Object.create;var Pt=Object.defineProperty;var Br=Object.getOwnPropertyDescriptor;var $r=Object.getOwnPropertyNames;var zr=Object.getPrototypeOf,Wr=Object.prototype.hasOwnProperty;var Hr=(e,t)=>{for(var n in t)Pt(e,n,{get:t[n],enumerable:!0})},Kn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of $r(t))!Wr.call(e,r)&&r!==n&&Pt(e,r,{get:()=>t[r],enumerable:!(o=Br(t,r))||o.enumerable});return e};var he=(e,t,n)=>(n=e!=null?qr(zr(e)):{},Kn(t||!e||!e.__esModule?Pt(n,"default",{value:e,enumerable:!0}):n,e)),jr=e=>Kn(Pt({},"__esModule",{value:!0}),e);var Yi={};Hr(Yi,{CodeType:()=>ie,DefaultMiniAppChangelogPrompt:()=>Hn,DefaultMiniAppSplash:()=>Un,DefaultMiniAppUpdatePrompt:()=>jn,MINIAPP_CHANGELOG_KINDS:()=>$n,MINIAPP_PLATFORM_URL:()=>Qe,MiniAppChangelogGroups:()=>rn,MiniAppChangelogHistory:()=>Wn,MiniAppHost:()=>Fr,MiniAppHostError:()=>g,MiniAppUpdates:()=>Ur,ScannerEndReason:()=>Ke,ScannerEvent:()=>Dt,ScannerLayout:()=>fe,ScannerMethod:()=>et,ToastType:()=>be,closeMiniApp:()=>rt,configureMiniApp:()=>Xn,createMmkvStorage:()=>Zn,createReactNativeBiometrics:()=>ln,createRnfsFileSystem:()=>Qn,dismissMiniAppChangelog:()=>nn,ensureMiniApp:()=>vt,fetchMiniAppChangelog:()=>en,getLocalMiniApp:()=>$,getMiniAppCatalog:()=>kr,getMiniAppCatalogEntry:()=>st,getMiniAppChangelogSeen:()=>Zt,getMiniAppStatuses:()=>Mr,getMiniAppUpdate:()=>Nn,getPendingChangelog:()=>Bn,installBundledMiniApp:()=>sr,markMiniAppChangelogSeen:()=>at,mergeMiniAppChangelog:()=>zn,onMiniAppEvent:()=>Gt,openMiniApp:()=>yr,pauseMiniApp:()=>Er,pauseMiniAppDownloads:()=>Tr,preloadMiniApp:()=>wr,releaseSpeechFor:()=>Ie,restoreMiniApp:()=>Cr,resumeMiniApp:()=>Pr,resumeMiniAppDownloads:()=>Rr,sendEventToWeb:()=>lr,showMiniAppChangelog:()=>Qt,syncMiniAppCatalog:()=>Yt,uninstallMiniApp:()=>xr,updateMiniApp:()=>Xt,uploadToUrl:()=>gn,useMiniAppChangelog:()=>tn,useMiniAppChangelogRequest:()=>on,useMiniAppDownload:()=>it,useMiniAppDownloadsPaused:()=>Sr});module.exports=jr(Yi);var Qe="https://retion-miniapp-platform.vercel.app",je=null,Yn=new Set,Xn=e=>{je=e,Yn.forEach(t=>t())},F=()=>{if(!je)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return je},Tt=e=>{Yn.add(e),je&&e()},me=(...e)=>{je!=null&&je.debug&&console.log("[miniapp]",...e)};var Qn=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:c,contentLength:l})=>r==null?void 0:r(c,l)});return{promise:a.then(({statusCode:c})=>({status:c})),cancel:()=>e.stopDownload(i)}}}),Zn=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var v=he(require("react")),V=require("react-native"),Lr=he(require("react-native-webview"));var yt=require("react-native");var ln=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),Rt,pn=()=>(Rt||(Rt=import("react-native-biometrics").then(({default:e})=>ln(new e({allowDeviceCredentials:!1}))).catch(e=>{throw Rt=void 0,new g("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),Rt);var ke=require("react-native");var eo=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new g("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new g("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new g("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},to=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new g("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(ke.Platform.OS==="android"){let s=ke.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,d=ke.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,u=await ke.PermissionsAndroid.check(s);if(!c())return;let y=u||await ke.PermissionsAndroid.check(d);if(!c())return;if(!u&&!y){let p=await ke.PermissionsAndroid.requestMultiple([s,d]);if(!c())return;if(p[s]!==ke.PermissionsAndroid.RESULTS.GRANTED&&p[d]!==ke.PermissionsAndroid.RESULTS.GRANTED)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var u;if(!c())return;let d=(u={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?u:"LOCATION_ERROR";i(new g(d,s.message))},e)}})().catch(l=>i(l))});var dn=require("react-native");var un=20,no=20,co=/^[a-z][a-z0-9_-]{0,31}$/,Jr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,Gr=["low","medium","high"],qe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),te=e=>new g("INVALID_PARAMS",e),ht=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,oo=(e,t)=>{if(e===void 0)return{};if(!qe(e)||Object.keys(e).length>no||Object.values(e).some(n=>typeof n!="string"))throw te(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${no} key)`);return e},lo=e=>{var n,o,r,i;if(e!==void 0&&!qe(e))throw te("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!co.test(t.source)))throw te("source ph\u1EA3i l\xE0 t\xEAn ngu\u1ED3n, vd library | camera | document");if(t.accept!==void 0&&(!Array.isArray(t.accept)||t.accept.length>50||t.accept.some(a=>typeof a!="string"||!Jr.test(a))))throw te("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!ht(t.max_count,1,un))throw te(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${un}`);if(t.max_size!==void 0&&!ht(t.max_size,1,Number.MAX_SAFE_INTEGER))throw te("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!ht(t.concurrency,1,5))throw te("concurrency ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u20135");return{source:(n=t.source)!=null?n:"library",accept:((o=t.accept)!=null?o:[]).map(a=>a.toLowerCase()),max_count:(r=t.max_count)!=null?r:1,max_size:t.max_size,process:Kr(t.process),target:Yr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},Kr=e=>{if(e===void 0)return{};if(!qe(e))throw te("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!qe(n))throw te("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!ht(n[o],1,1e4))throw te(`process.image.${o} ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u201310000`);if(n.quality!==void 0&&(typeof n.quality!="number"||n.quality<=0||n.quality>1))throw te("process.image.quality ph\u1EA3i trong kho\u1EA3ng (0, 1]");t.image={max_width:n.max_width,max_height:n.max_height,quality:n.quality}}if(e.video!==void 0){let n=e.video;if(!qe(n))throw te("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!ht(n.max_duration,1,3600))throw te("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!Gr.includes(n.quality))throw te("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},Yr=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!qe(e))throw te("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!co.test(t))throw te("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!qe(e.params))throw te("upload.params ph\u1EA3i l\xE0 object");return{target:t,params:(o=e.params)!=null?o:{}}}if(typeof e.url!="string"||!/^https:\/\//i.test(e.url))throw te("upload.url ph\u1EA3i l\xE0 https");for(let a of["field_name","url_field"])if(e[a]!==void 0&&(typeof e[a]!="string"||!e[a]))throw te(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:oo(e.headers,"upload.headers"),form_data:oo(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},po=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},Xr=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=po(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Qr=e=>{let t=e.length>0&&e.every(o=>o.startsWith("image/")),n=e.length>0&&e.every(o=>o.startsWith("video/"));return t?"image":n?"video":"mixed"},ut,Zr=()=>(ut!=null||(ut=import("react-native-image-picker").catch(e=>{throw ut=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),ut),ro=e=>async({accept:t,max_count:n,process:o})=>{var l,s,d,u,y,p,h,L,k;let r=await Zr(),i=Qr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(u=(d=o.image)==null?void 0:d.quality)!=null?u:.8,videoQuality:(p=(y=o.video)==null?void 0:y.quality)!=null?p:"medium",durationLimit:(h=o.video)==null?void 0:h.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let T=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new g(T,(L=c.errorMessage)!=null?L:c.errorCode)}return((k=c.assets)!=null?k:[]).filter(T=>T.uri).map((T,_)=>{var B,G,ce;return{uri:T.uri,name:(B=T.fileName)!=null?B:`file_${_+1}`,mime_type:(G=T.type)!=null?G:"application/octet-stream",size:T.fileSize,width:T.width,height:T.height,duration:T.duration,processed:!((ce=T.type)!=null&&ce.startsWith("video/"))||dn.Platform.OS==="ios"}})},ei={"image/*":"images","video/*":"video","audio/*":"audio","text/plain":"plainText","text/csv":"csv","application/pdf":"pdf","application/json":"json","application/zip":"zip","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx"},ti={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},ni=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var d;return(d=ei[s])!=null?d:ti[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let d=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(p=>p.uri&&!p.error).map((p,h)=>{var L,k,T;return{uri:p.uri,name:(L=p.name)!=null?L:`file_${h+1}`,mime_type:(k=p.type)!=null?k:"application/octet-stream",size:(T=p.size)!=null?T:void 0}});if(dn.Platform.OS!=="android"||!e.keepLocalCopy||!d.some(p=>p.uri.startsWith("content://")))return d;let u=await e.keepLocalCopy({files:d.map(p=>({uri:p.uri,fileName:p.name})),destination:"cachesDirectory"}),y=new Map(u.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var h;return{...p,uri:(h=y.get(p.uri))!=null?h:p.uri}})}catch(s){let d=s==null?void 0:s.code;if(d===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw d===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new g("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},dt,oi=async e=>(dt!=null||(dt=import("@react-native-documents/picker").then(t=>ni(t)).catch(t=>{throw dt=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await dt)(e)),uo={library:ro("library"),camera:ro("camera"),document:oi},io={type:"image",label:"\u1EA2nh",accept:["image/*"]},so={type:"video",label:"Video",accept:["video/*"]},ao={library:[io,so],camera:[io,so],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},gt,go=()=>(gt!=null||(gt=import("react-native-compressor").catch(()=>(gt=void 0,null))),gt),ho=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},ri=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),ii={low:640,medium:1280,high:1920},si=async(e,{image:t})=>{var o;if(!t||!ri.has(e.mime_type.toLowerCase()))return e;let n=await go();if(!n)return e;try{let r=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(o=t.quality)!=null?o:.8,output:"jpg"});return{...e,uri:r,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await ho(n,r,e.size),processed:!0}}catch{return e}},ai=async(e,{video:t})=>{var o;let n=await go();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:ii[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await ho(n,r,e.size),processed:!0}}catch{return e}},ci={image:si,video:ai},li=(e,t)=>t.split(".").reduce((n,o)=>qe(n)?n[o]:void 0,e),gn=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new g("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([u,y])=>l.append(u,y)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let d=u=>{o.removeEventListener("abort",s),u()};c.open("POST",a.url),Object.entries(a.headers).forEach(([u,y])=>c.setRequestHeader(u,y)),c.upload.onprogress=u=>n(u.loaded,u.total||e.size||0),c.onload=()=>d(()=>{let u=c.responseText;try{u=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new g("UPLOAD_FAILED",`HTTP ${c.status}`));return}let y=li(u,a.url_field);if(typeof y!="string"||!y){i(new g("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:y,response:u})}),c.onerror=()=>d(()=>i(new g("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>d(()=>i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),mo=e=>{var o,r;let t={...uo};for(let[i,a]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))a?t[i]=a:delete t[i];let n={url:gn};for(let[i,a]of Object.entries((r=e==null?void 0:e.targets)!=null?r:{}))i!=="url"&&a&&(n[i]=a);return{sources:t,targets:n}},fo=e=>{let{sources:t,targets:n}=mo(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===uo[i]&&ao[i]).map(i=>[i,ao[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:un}},Ot=new Map,yo=(e,t)=>`${e}:${t}`,pi=0,wo=(e,t)=>{var n;typeof t=="string"&&((n=Ot.get(yo(e,t)))==null||n.abort())},Je=e=>{for(let[t,n]of Ot)t.startsWith(`${e}:`)&&n.abort()},kt=()=>new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),ui=(e,t)=>{var n;return{name:e,code:typeof(t==null?void 0:t.code)=="string"?t.code:"UPLOAD_FAILED",message:String((n=t==null?void 0:t.message)!=null?n:t)}},bo=async(e,t)=>{var l;let{sources:n,targets:o}=mo(t.config),r=n[e.source];if(!r)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=yo(t.instance_id,(l=t.task_id)!=null?l:`auto-${++pi}`);Ot.set(c,a);try{return await di(e,t,r,i,a.signal)}finally{Ot.delete(c)}},di=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=u=>u()},l,s,d)=>{var R,f,I;let u={app_id:n!=null?n:"",instance_id:t,context:{...(R=o==null?void 0:o())!=null?R:{}}},y=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:u}))).slice(0,e.max_count);if(d.aborted)throw kt();if(!y.length)throw new g("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],h=y.filter(P=>Xr(P,e.accept)?!0:(p.push({name:P.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${P.mime_type||po(P.name)}`}),!1)),L=h.map(()=>0),k=h.map(P=>{var z;return(z=P.size)!=null?z:0}),T=0,_=0,B=(P=!1)=>{if(!a||!r)return;let z=Date.now();if(!P&&z-_<200)return;_=z;let xe=k.reduce((U,le)=>U+le,0),ee=L.reduce((U,le)=>U+le,0);a("upload.progress",{task_id:r,loaded:ee,total:xe,percent:xe?Math.min(100,Math.round(ee/xe*100)):0,done_count:T,count:h.length})},G=[],ce=0,Le=async()=>{var P,z,xe;for(;ce<h.length;){let ee=ce++,U=h[ee];try{if(d.aborted)throw kt();let le=U.mime_type.startsWith("image/")?"image":U.mime_type.startsWith("video/")?"video":void 0,X=le&&!U.processed?(z=(P=i==null?void 0:i.processors)==null?void 0:P[le])!=null?z:ci[le]:void 0;if(X&&(U=await X(U,e.process),k[ee]=(xe=U.size)!=null?xe:k[ee],d.aborted))throw kt();if(e.max_size&&U.size&&U.size>e.max_size)throw new g("FILE_TOO_LARGE",`File ${U.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let re=(Xe,Re)=>{L[ee]=Xe,Re&&(k[ee]=Re),B()},pe=await s({file:U,target:e.target,onProgress:re,signal:d,caller:u});if(typeof(pe==null?void 0:pe.url)!="string"||!pe.url)throw new g("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:Pe,...Te}=pe;G[ee]={url:Pe,name:U.name,mime_type:U.mime_type,size:U.size,width:U.width,height:U.height,duration:U.duration,...Object.keys(Te).length?{response:"response"in Te?Te.response:Te}:{}},L[ee]=k[ee]}catch(le){p.push(ui(h[ee].name,le))}finally{T++,B(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,h.length)},Le)),d.aborted)throw kt();let ge=G.filter(P=>!!P);if(!ge.length){let P=p[0];throw new g((f=P==null?void 0:P.code)!=null?f:"UPLOAD_FAILED",(I=P==null?void 0:P.message)!=null?I:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:ge,failed:p}};var It=require("react"),Oe=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},j=(e,t,n=Object.is)=>{let o=(0,It.useRef)(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return(0,It.useSyncExternalStore)(e.subscribe,r)};var be={info:"info",success:"success",error:"error"},gi=200,Ao={info:2e3,success:2e3,error:3e3},mt=Oe({message:"",type:be.info,tick:0}),_o=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,gi);return o?{message:o,type:Object.values(be).includes(n)?n:be.info}:null},So=(e,t=be.info)=>{mt.setState(n=>({message:e,type:t,tick:n.tick+1}))};var _e=require("react-native");var Ge=require("react-native");var Ae,Ze=new Map,Mo=(e,t)=>{var o;let n=(o=Ze.get(e))!=null?o:new Set;n.add(t),Ze.set(e,n)},vo=(e,t)=>{let n=Ze.get(e);n&&(t?n.delete(t):n.clear(),n.size===0&&Ze.delete(e))},mn=new Map,xo=(e,t)=>{mn.set(e,t)},Co=e=>mn.get(e),Eo=()=>Ge.Platform.OS==="android"&&!!(Ae!=null&&Ae.requesting_permission),hi=1500,Lt=()=>new Promise(e=>{if(Ge.Platform.OS!=="android"||Ge.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,hi),o=Ge.AppState.addEventListener("change",r=>{r==="active"&&t()})}),hn=e=>{var t;if(Ae===e&&(Ae=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Ge.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Po=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(Ae)throw new g("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};Ae=r;try{let d;try{d=await import("expo-speech-recognition")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let u=d.ExpoSpeechRecognitionModule;if(r.native=u,r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let y;try{y=await u.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await Lt(),r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.granted)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await u.getStateAsync()!=="inactive")throw new g("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(u.addListener("result",p=>{var h,L;Ae!==r||r.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(L=(h=p.results[0])==null?void 0:h.transcript)!=null?L:""})}),u.addListener("error",p=>{Ae===r&&!r.cancelled&&n("speech.error",{...p,code:p.error})}),u.addListener("end",()=>{Ae===r&&(hn(r),n("speech.end"))})),r.started=!0,u.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:d.AVAudioSessionCategory.playAndRecord,categoryOptions:[d.AVAudioSessionCategoryOptions.defaultToSpeaker,d.AVAudioSessionCategoryOptions.allowBluetooth],mode:d.AVAudioSessionMode.measurement}})}catch(d){throw hn(r),d}},To=e=>{let t=Ae;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Ie=e=>{mn.delete(e);let t=Ze.get(e);Ze.delete(e),t==null||t.forEach(o=>{var r;try{(r=o.release)==null||r.call(o,e)}catch{}});let n=Ae;if(!(!n||n.owner!==e||n.cancelled)&&(n.cancelled=!0,n.started))try{n.native.abort()}catch{hn(n)}};var Ro={qr:"qr",ean13:"ean-13",ean8:"ean-8",upcA:"upc-a",upcE:"upc-e",code128:"code-128",code39:"code-39",code93:"code-93",codabar:"codabar",itf:"itf",pdf417:"pdf-417",aztec:"aztec",dataMatrix:"data-matrix"},ie={...Ro,all:Object.values(Ro)},et={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Dt={result:"scanner.result",end:"scanner.end"},Ke={user:"user",web:"web",closed:"closed",error:"error"},fe={top:"top",full:"full"},Be={once:"once",continuous:"continuous"},mi=1500,ko=6e4,J,ne=Oe({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),Io=()=>_e.Platform.OS==="android"&&!!(J!=null&&J.requesting_permission),yn=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r,absolute:i}=e!=null?e:{},a={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(c=>ie.all.includes(c)))throw new g("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");a.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>ko)throw new g("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${ko}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new g("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(fe).includes(r))throw new g("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new g("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},wn=e=>J!==e?!1:(J=void 0,ne.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),fi=()=>_e.Alert.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{_e.Linking.openSettings().catch(()=>{})}}]),Lo=async(e,t)=>{if(J)throw new g("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");J=e;let n=()=>{if(e.cancelled||!t())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=_e.Platform.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await Lt(),n(),c!=="granted")throw a&&fi(),new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new g("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await bn();n(),ne.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,absolute:e.absolute,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw wn(e),o}},Ft;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{Ft=e==null?void 0:e.insets}).catch(()=>{});var tt=()=>{var e;return Ft!=null?Ft:{top:_e.Platform.OS==="ios"?54:(e=_e.StatusBar.currentHeight)!=null?e:0,bottom:_e.Platform.OS==="ios"?34:48}},bn=async()=>{if(_e.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},Fo=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:ie.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:mi,hint:n.hint,layout:t===Be.once?fe.full:(i=n.layout)!=null?i:fe.top,absolute:t!==Be.once&&((a=n.layout)!=null?a:fe.top)===fe.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},Do=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=Fo(e,Be.once,t);a.onHit=o,a.resolve=r,a.reject=i,Lo(a,n).catch(i)}),No=(e,t,n,o=()=>!0,r)=>{let i=Fo(e,Be.continuous,t);return i.emit=n,i.onHit=r,Lo(i,o)},Nt=(e,t,n)=>{var o,r;if(!ne.getState().active){e.cancelled=!0;return}if(wn(e)){if(e.mode===Be.once){(o=e.reject)==null||o.call(e,t===Ke.error?new g("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new g("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,Dt.end,n?{reason:t,message:n}:{reason:t})}},Vo=e=>{(J==null?void 0:J.owner)===e&&Nt(J,Ke.web)},$e=e=>{(J==null?void 0:J.owner)===e&&Nt(J,Ke.closed)},An=()=>{J&&Nt(J,Ke.user)},Uo=e=>{J&&Nt(J,Ke.error,e)},_n=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=J;if(!(!o||!ne.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(o.last_seen.set(c,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Be.once){wn(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}ne.setState(d=>({last_value:c,hit_tick:d.hit_tick+1,scan_count:d.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,Dt.result,{value:c,type:l})}}},yi={1:ie.code128,2:ie.code39,4:ie.code93,8:ie.codabar,16:ie.dataMatrix,32:ie.ean13,64:ie.ean8,128:ie.itf,256:ie.qr,512:ie.upcA,1024:ie.upcE,2048:ie.pdf417,4096:ie.aztec},wi=2500,Oo=2e3,fn=e=>{ne.setState({notice:e}),setTimeout(()=>{ne.getState().notice===e&&ne.setState({notice:null})},wi)},qo=async()=>{var t,n;let e=J;if(!(!e||ne.getState().is_picking)){e.requesting_permission=!0,ne.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:Oo,maxHeight:Oo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||J!==e)return;if(r.errorCode||!i){fn("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(J!==e)return;let l=c.map(({value:s,format:d})=>({value:s,code_type:yi[d]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:d})=>({value:s,type:d!=null?d:"unknown"}));if(!l.length){fn("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}_n(l,Date.now(),!0)}catch{J===e&&fn("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await Lt(),e.requesting_permission=!1,J===e&&ne.setState({is_picking:!1})}}};var Ut=1,g=class extends Error{constructor(n,o){super(o);this.code=n}},Bo=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Ut&&typeof t.method=="string"?t:null}catch{return null}},wt=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,$o=(e,t)=>wt({id:e,result:t}),zo=(e,t)=>wt({id:e,error:{code:t.code,message:t.message}}),Wo=(e,t)=>wt({event:e,data:t}),Mn=e=>wt({event:"context",data:e});var Ho=()=>`(function () {
2
2
  var post = function (level, args) {
3
3
  try {
4
4
  var parts = [];
@@ -8,7 +8,7 @@
8
8
  else if (typeof a === 'object') { try { parts.push(JSON.stringify(a).slice(0, 800)); } catch (e) { parts.push(String(a)); } }
9
9
  else { parts.push(String(a)); }
10
10
  }
11
- window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${Tt}, method: 'log', level: level, text: parts.join(' ') }));
11
+ window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${Ut}, method: 'log', level: level, text: parts.join(' ') }));
12
12
  } catch (e) {}
13
13
  };
14
14
  ['log', 'info', 'warn', 'error'].forEach(function (level) {
@@ -19,7 +19,7 @@
19
19
  window.addEventListener('unhandledrejection', function (e) { post('error', ['[unhandledrejection]', e.reason]); });
20
20
  // Kh\xF4ng log query (c\xF3 th\u1EC3 ch\u1EE9a token) \u2014 ch\u1EC9 \u0111\u01B0\u1EDDng d\u1EABn + route.
21
21
  post('info', ['[page] ' + location.pathname + location.hash]);
22
- })(); true;`,Eo=()=>`(function () {
22
+ })(); true;`,jo=()=>`(function () {
23
23
  function atTop(el) {
24
24
  for (var n = el; n && n !== document.documentElement; n = n.parentElement) {
25
25
  if (n.scrollTop > 0) { return false; }
@@ -30,7 +30,7 @@
30
30
  function report(at_top) {
31
31
  if (at_top === last) { return; }
32
32
  last = at_top;
33
- window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${Tt}, method: 'touchAtTop', at_top: at_top }));
33
+ window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${Ut}, method: 'touchAtTop', at_top: at_top }));
34
34
  }
35
35
  document.addEventListener('touchstart', function (e) { report(atTop(e.target)); }, { capture: true, passive: true });
36
36
  // Cu\u1ED9n r\u1EDDi \u0111\u1EA7u trang \u2192 b\xE1o ngay, kh\xF4ng \u0111\u1EE3i l\u1EA7n ch\u1EA1m sau (tr\xE1nh host d\xF9ng gi\xE1 tr\u1ECB c\u0169 "\u0111ang \u1EDF \u0111\u1EA7u").
@@ -38,7 +38,7 @@
38
38
  var el = e.target === document ? document.documentElement : e.target;
39
39
  if (el && el.scrollTop > 0) { report(false); }
40
40
  }, { capture: true, passive: true });
41
- })(); true;`,Co=()=>`(function () {
41
+ })(); true;`,Jo=()=>`(function () {
42
42
  if (window.__retionSafeAreaFrozen) { return; }
43
43
  window.__retionSafeAreaFrozen = true;
44
44
  var max = {};
@@ -59,14 +59,14 @@
59
59
  },
60
60
  });
61
61
  };
62
- })(); true;`,Po=e=>pt({event:e}),Ro=(e,t)=>{let n=To(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
63
- ${sn(e)}`},To=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),Oo=(e,t={})=>{let n=To(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${Tt} };
62
+ })(); true;`,Go=e=>wt({event:e}),Ko=(e,t)=>{let n=Yo(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
63
+ ${Mn(e)}`},Yo=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),Xo=(e,t={})=>{let n=Yo(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${Ut} };
64
64
  window.__RETION_MINIAPP_CONTEXT__ = ${JSON.stringify(e)};
65
65
  ${n?`try { history.replaceState(history.state, '', location.pathname + '?' + ${JSON.stringify(n)} + location.hash); } catch (e) {}`:""}
66
- true;`},ko={partner:"partner_token",chatbox:"chatbox_token"},Io=(e,t)=>{let n={...e};for(let o of Object.values(ko))t.includes(o)||delete n[o];return n},rn=new Set,ct=async(e,t)=>{if(rn.has(e))throw new g("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);rn.add(e);try{return await t()}finally{rn.delete(e)}},an=e=>`(function () {
66
+ true;`},Qo={partner:"partner_token",chatbox:"chatbox_token"},Zo=(e,t)=>{let n={...e};for(let o of Object.values(Qo))t.includes(o)||delete n[o];return n},Sn=new Set,ft=async(e,t)=>{if(Sn.has(e))throw new g("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);Sn.add(e);try{return await t()}finally{Sn.delete(e)}},vn=e=>`(function () {
67
67
  window.__retionScannerHeight = ${Math.max(0,Math.round(e))};
68
68
  window.dispatchEvent(new Event('retionscannerheight'));
69
- })(); true;`,Lo=()=>`(function () {
69
+ })(); true;`,er=()=>`(function () {
70
70
  try {
71
71
  var AudioCtx = window.AudioContext || window.webkitAudioContext;
72
72
  if (!AudioCtx) { return; }
@@ -85,4 +85,5 @@
85
85
  // iOS c\xF3 th\u1EC3 \u0111\u1EC3 context \u1EDF suspended / interrupted (vd. khi camera m\u1EDF phi\xEAn quay): ch\u1EA1y l\u1EA1i xong m\u1EDBi ph\xE1t.
86
86
  if (ctx.state === 'running') { play(); } else { ctx.resume().then(play).catch(function () {}); }
87
87
  } catch (e) {}
88
- })(); true;`,ei=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Rt=(e,t)=>{if(typeof e!="string"||!e)throw new g("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},Fo=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:d,isActive:u,playBeep:y})=>{var C,M,q,W,oe,Pe,ce,E;let p=s==null?void 0:s.handlers,f={app_id:c,instance_id:l,close:a},O=()=>{var m;(m=s==null?void 0:s.haptic)==null||m.call(s,"impactLight"),y==null||y()},R=()=>new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let m=Ln(t);return ct(e,()=>Fn(m,u))}case"speech.start":{if(!d)throw R();let m={};if((t==null?void 0:t.lang)!==void 0){if(typeof t.lang!="string"||!/^[a-zA-Z]{2,8}(-[a-zA-Z0-9]{1,8})*$/.test(t.lang))throw new g("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");m.lang=t.lang}for(let V of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[V])!==void 0){if(typeof t[V]!="boolean")throw new g("INVALID_PARAMS",`${V} ph\u1EA3i l\xE0 boolean`);m[V]=t[V]}if((t==null?void 0:t.mode)!==void 0&&t.mode!=="s2t"&&t.mode!=="voice")throw new g("INVALID_PARAMS","mode ph\u1EA3i l\xE0 's2t' ho\u1EB7c 'voice'");let T=(t==null?void 0:t.mode)==="s2t"?"s2t":"voice",x=T==="voice"?(C=s==null?void 0:s.voice)!=null?C:s==null?void 0:s.speech:void 0;if(ro(l,x),x){no(l,x);try{return await x.start({owner:l,app_id:c,mode:T,options:m,emit:d,isActive:u!=null?u:(()=>!0)})}catch(V){throw oo(l,x),V}}return ao(l,m,d,u)}case"speech.stop":{let m=io(l);return m?m.stop(l):co(l)}case Ke.scan:return fo(l,Zt(t),u,O);case Ke.start:{if(!d)throw R();return yo(l,Zt(t),d,u,O)}case Ke.stop:return wo(l);case"uploadFiles":{let{task_id:m,...T}=t!=null?t:{};if(m!==void 0&&(typeof m!="string"||!m))throw new g("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return Qn(zn(T),{instance_id:l,app_id:c,getContext:r,task_id:m,config:s==null?void 0:s.upload,emit:d,exclusivePick:x=>ct("uploadFiles.pick",x)})}case"uploadFiles.cancel":Xn(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Kn(s==null?void 0:s.upload);case"getBiometricAvailability":return((M=s==null?void 0:s.biometrics)!=null?M:await Ht()).getAvailability();case"authenticateBiometric":{let m=Rt(t==null?void 0:t.reason,"reason").trim();if(!m||m.length>200)throw new g("INVALID_PARAMS","reason must contain 1\u2013200 characters");let T=t==null?void 0:t.cancelButtonText;if(T!==void 0&&(typeof T!="string"||!T.trim()||T.length>80))throw new g("INVALID_PARAMS","Invalid cancelButtonText");return ct(e,async()=>{var V;return((V=s==null?void 0:s.biometrics)!=null?V:await Ht()).authenticate({reason:m,cancelButtonText:T})})}case"requestPayment":{let m=p==null?void 0:p.requestPayment;if(!m)throw R();let T=t==null?void 0:t.amount;if(typeof T!="number"||!Number.isFinite(T)||T<=0)throw new g("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let x={...t,amount:T,currency:Rt(t==null?void 0:t.currency,"currency")};return ct(e,()=>m(x,f))}case"printImage":{let m=p==null?void 0:p.printImage;if(!m)throw R();let T=Rt(t==null?void 0:t.image,"image");await ct(e,()=>m({image:T},f));return}case"openScreen":if(!(p!=null&&p.openScreen))throw R();await p.openScreen({screen:Rt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},f);return;case"closeApp":a();return;case"openWebview":{let m=String((q=t==null?void 0:t.url)!=null?q:"");if(!/^https?:\/\//i.test(m))throw new g("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(m):lt.Linking.openURL(m));return}case"openLink":{let m=String((W=t==null?void 0:t.url)!=null?W:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(m)||/^(javascript|file|data|about|blob):/i.test(m))throw new g("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(m):lt.Linking.openURL(m))}catch(T){throw new g("NOT_SUPPORTED",String((Pe=(oe=T==null?void 0:T.message)!=null?oe:T)!=null?Pe:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let m=eo(t);if(!m||(u==null?void 0:u())===!1)return;s!=null&&s.showToast?s.showToast(m.message,{type:m.type}):to(m.message,m.type);return}case"haptic":{let m=ei.has(t==null?void 0:t.type)?t.type:"selection";(ce=s==null?void 0:s.haptic)==null||ce.call(s,m);return}case"getSystemInfo":return{platform:lt.Platform.OS==="ios"?"ios":"android",appVersion:(E=s==null?void 0:s.app_version)!=null?E:"",theme:i?"dark":"light"};case"getAccessToken":{let m=n().access_token;if(!m)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return m}case"getToken":{let m=t==null?void 0:t.type;if(m==="access"){let V=n().access_token;if(!V)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return V}if(m!=="partner"&&m!=="chatbox")throw new g("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(m)}`);let T=ko[m];if(!o().includes(T))throw new g("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${T} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let x=m==="partner"?n().partner_token:n().chatbox_token;if(!x)throw new g("HOST_ERROR",`Kh\xF4ng c\xF3 ${T}`);return x}case"getUserInfo":{let m=n().user;if(!m)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return m}case"getPageInfo":{let m=n().page;if(!m)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return m}case"sendMessage":case"insertText":throw new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new g("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var ln=e=>`bundle:${e}`,pn=()=>`${D().file_system.document_dir}/miniapps`,un=pn,dn=(e,t,n="index.html",o=!1,r=[])=>{let i=`${un()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},cn=e=>{var t;D().storage.setString(ln(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},ti=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,N=e=>{let t=D().storage.getString(ln(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return dn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Te=e=>D().file_system.exists(e.entry_uri.replace("file://","")),gn=async e=>{let t=N(e.app_id);return(t==null?void 0:t.version)===e.version&&await Te(t)},No=async(e,t)=>{let n=D().file_system,o=`${un()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Uo=async e=>{var t;await((t=dt[e])==null?void 0:t.catch(()=>{})),D().storage.setString(ln(e),""),await D().file_system.remove(`${un()}/${e}`).catch(()=>{})},Ye=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},dt={},Vo=(e,t)=>{var i;let o=((i=dt[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return dt[e]=r,r.then(()=>{dt[e]===r&&delete dt[e]}),o},hn=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let c=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(c)return c}return 0},Bo=({manifest:e,zip_path:t})=>Vo(e.app_id,async()=>{var i;let n=D().file_system,o=N(e.app_id);if(o&&hn(o.version,e.version)>=0&&await Te(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=dn(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),cn(e),he("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),No(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),mn=(e,{base_url:t,onProgress:n}={})=>{let o=D().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new Ye},l=async()=>{var u;c();let s=N(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return cn(e),N(e.app_id);c();let d=o.download({url:t?ti(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,p)=>{var O;let f=p>0?p:(O=e.size)!=null?O:0;f>0&&(n==null||n(Math.min(1,y/f)))}});r=d;try{let{status:y}=await d.promise;if(c(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else he("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let p=dn(e.app_id,e.version,e.entry,!!e.context_update,(u=e.permissions)!=null?u:[]);return await o.remove(p.dir).catch(()=>{}),await o.mkdir(p.dir),await o.unzip(a,p.dir),cn(e),No(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(y){throw i?new Ye:y}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:Vo(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},ut={},ni=__DEV__?0:60*1e3,Do={},qo=(e,t)=>{var o,r;let n=N(e);return n&&Date.now()-((o=Do[t])!=null?o:0)<ni?Promise.resolve(n):((r=ut[e])!=null||(ut[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),c=await mn(a,{base_url:t}).promise;return Do[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),N(e))).finally(()=>{ut[e]=void 0})),ut[e])};var Ot=new Map,$o=(e,t)=>(Ot.set(e,t),()=>{Ot.get(e)===t&&Ot.delete(e)}),zo=(e,t)=>{let n=Ot.get(e);return n?n(t):!1};var B=require("react"),w=require("react-native");var v=require("react/jsx-runtime"),gt="#22C55E",oi="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",ri=2,It=18,ii=1600,ht=14,si=2e3,Ho=.38,ai=40,Wo=2,ci=8,li=2e3,pi=250,Xe=2e3,ui=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:ht},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:ht},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:ht},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:ht}],jo=({color:e})=>(0,v.jsx)(v.Fragment,{children:ui.map((t,n)=>(0,v.jsx)(w.View,{style:[_.corner,t,{borderColor:e}]},n))}),kt=({style:e,children:t,...n})=>{let o=(0,B.useRef)(new w.Animated.Value(1)).current,r=i=>w.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,v.jsx)(w.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,v.jsx)(w.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},yn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var h,b;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:d}=e,u=c===pe.top,y=(0,B.useRef)(new w.Animated.Value(0)).current,p=r.useCameraDevice("back"),f=(0,B.useRef)(new w.Animated.Value(1)).current,[O,R]=(0,B.useState)(!1),[C,M]=(0,B.useState)(1),q=(0,B.useRef)(null),[W,oe]=(0,B.useState)(()=>{let{width:A,height:$}=w.Dimensions.get("window");return{width:A,height:u?$*Ho:$,window_y:0}}),Pe=H(Q,A=>A.last_value),ce=H(Q,A=>A.hit_tick),E=H(Q,A=>A.scan_count),m=H(Q,A=>A.notice),T=H(Q,A=>A.is_picking),x=(0,B.useRef)(null),V=Ct(),Ae=V.top,Y=(0,B.useRef)(new w.Animated.Value(0)).current,L=(0,B.useRef)(new w.Animated.Value(0)).current,re=(0,B.useRef)(new w.Animated.Value(0)).current,G=(0,B.useRef)(n);G.current=n,(0,B.useEffect)(()=>{if(!t)return;y.setValue(W.height);let A=w.Animated.timing(y,{toValue:0,duration:pi,easing:w.Easing.out(w.Easing.cubic),useNativeDriver:!1});return A.start(({finished:$})=>{var se;$&&((se=G.current)==null||se.call(G))}),()=>A.stop()},[t,y]);let ee=Math.round(W.width*(u?.8:.78)),ie=Math.round(u?W.height*.46:ee*.78),ve=Math.round((W.height-ie)/2),Me=Math.round((W.width-ee)/2),He=r.useCodeScanner({codeTypes:i,onCodeScanned:(0,B.useCallback)(A=>on(A),[])});(0,B.useEffect)(()=>{let A=w.BackHandler.addEventListener("hardwareBackPress",()=>(nn(),!0));return()=>A.remove()},[]);let xe=(0,B.useRef)(ce);(0,B.useEffect)(()=>{if(ce===xe.current)return;Y.setValue(1),re.setValue(1);let A=w.Animated.parallel([w.Animated.timing(Y,{toValue:0,duration:450,useNativeDriver:!0}),w.Animated.sequence([w.Animated.delay(si),w.Animated.timing(re,{toValue:0,duration:250,useNativeDriver:!0})])]);return A.start(),()=>A.stop()},[ce,Y,re]),(0,B.useEffect)(()=>{let A=se=>w.Animated.timing(L,{toValue:se,duration:ii,easing:w.Easing.inOut(w.Easing.quad),useNativeDriver:!0}),$=w.Animated.loop(w.Animated.sequence([A(1),A(0)]));return $.start(),()=>$.stop()},[L]);let Re=(0,B.useCallback)(()=>{w.Animated.timing(f,{toValue:0,duration:220,useNativeDriver:!0}).start()},[f]);(0,B.useEffect)(()=>{let A=setTimeout(Re,li);return()=>clearTimeout(A)},[Re]);let[et,$t]=(0,B.useState)(!1);(0,B.useEffect)(()=>{let A=requestAnimationFrame(()=>{A=requestAnimationFrame(()=>$t(!0))});return()=>cancelAnimationFrame(A)},[]);let Be=!!(p!=null&&p.hasTorch),tt=(h=p==null?void 0:p.neutralZoom)!=null?h:1,nt=p?Math.min(p.maxZoom/tt,ci):1,zt=tt*Math.min(C,nt),yt=A=>{var ae;let{touches:$}=A.nativeEvent;if($.length!==2){q.current=null;return}let se=Math.hypot($[0].pageX-$[1].pageX,$[0].pageY-$[1].pageY);(ae=q.current)!=null||(q.current={distance:se,level:C}),M(Math.max(1,Math.min(nt,q.current.level*(se/q.current.distance))))},wt=(0,v.jsx)(w.Text,{style:[_.hint,!!m&&_.hint_notice],numberOfLines:1,children:(b=m!=null?m:l)!=null?b:oi});return(0,v.jsx)(w.Animated.View,{ref:x,onTouchMove:yt,onTouchEnd:()=>{q.current=null},pointerEvents:t?"none":"auto",style:u?[_.top,d&&_.top_absolute,t&&{height:y}]:_.full,onLayout:({nativeEvent:{layout:A}})=>{var $;t||(o==null||o(A.height),($=x.current)==null||$.measureInWindow((se,ae)=>{oe({width:A.width,height:A.height,window_y:ae||0})}))},children:(0,v.jsxs)(w.View,{style:t?[_.content_closing,{height:W.height}]:_.content,children:[p&&et&&(0,v.jsx)(r.Camera,{style:w.StyleSheet.absoluteFill,device:p,isActive:!T,codeScanner:He,torch:O&&Be?"on":"off",zoom:zt,onPreviewStarted:Re,onError:A=>bo(A.message)}),(0,v.jsx)(w.Animated.View,{style:[_.preview_cover,{opacity:f}],pointerEvents:"none"}),W.height>0&&(0,v.jsxs)(w.View,{style:_.overlay,pointerEvents:"none",children:[(0,v.jsx)(w.View,{style:[_.dim_ring,{top:ve-Xe,left:Me-Xe,width:ee+Xe*2,height:ie+Xe*2}]}),(0,v.jsxs)(w.View,{style:{position:"absolute",top:ve,left:Me,width:ee,height:ie},children:[(0,v.jsx)(jo,{color:"#FFFFFF"}),(0,v.jsx)(w.Animated.View,{style:[w.StyleSheet.absoluteFill,{opacity:Y}],children:(0,v.jsx)(jo,{color:gt})}),(0,v.jsxs)(w.Animated.View,{style:[_.scan_line_wrap,{transform:[{translateY:L.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,ie-It)]})}]}],children:[(0,v.jsx)(w.View,{style:_.scan_glow_outer}),(0,v.jsx)(w.View,{style:_.scan_glow_inner}),(0,v.jsx)(w.View,{style:_.scan_line})]})]}),(0,v.jsx)(w.View,{style:[_.hint_slot,u?{top:0,height:ve-6,justifyContent:"flex-end"}:{top:ve+ie+20}],children:wt}),a===Fe.continuous&&!!Pe&&(0,v.jsx)(w.Animated.View,{style:[_.result_slot,{top:u?ve+ie-ai:ve+ie+52},{opacity:re}],children:(0,v.jsxs)(w.View,{style:_.result,children:[(0,v.jsx)(w.View,{style:_.check_badge,children:(0,v.jsx)(w.View,{style:_.check_mark})}),(0,v.jsx)(w.Text,{style:_.result_text,numberOfLines:1,children:Pe}),(0,v.jsxs)(w.Text,{style:_.result_count,children:["\xB7 ",E," m\xE3"]})]})})]}),W.height>0&&(0,v.jsx)(w.View,{style:[_.close_slot,u?_.close_slot_top:{top:Math.max(12,Ae-W.window_y+12)}],children:(0,v.jsxs)(kt,{style:[_.close_button,!!s&&_.glass_surface],onPress:nn,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&(0,v.jsx)(s,{style:_.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(w.View,{style:[_.close_bar,_.close_bar_a]}),(0,v.jsx)(w.View,{style:[_.close_bar,_.close_bar_b]})]})}),(0,v.jsx)(w.View,{style:[_.toolbar_wrap,!u&&{bottom:V.bottom+20}],pointerEvents:"box-none",children:(0,v.jsxs)(w.View,{style:[_.toolbar,!!s&&_.glass_surface],children:[s&&(0,v.jsx)(s,{style:_.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(kt,{style:_.tool,onPress:Ao,disabled:T,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,v.jsxs)(w.View,{style:_.image_icon,children:[(0,v.jsx)(w.View,{style:_.image_icon_dot}),(0,v.jsx)(w.View,{style:_.image_icon_hill})]})}),!!p&&nt>=Wo&&(0,v.jsx)(kt,{style:[_.tool,C>1&&_.tool_on],onPress:()=>M(A=>A>1?1:Wo),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,v.jsxs)(w.Text,{style:[_.zoom_text,C>1&&_.zoom_text_on],children:[Math.round(C*10)/10,"x"]})}),Be&&(0,v.jsx)(kt,{style:[_.tool,O&&_.tool_on],onPress:()=>R(A=>!A),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:O},children:(0,v.jsx)(w.Text,{style:[_.torch_icon,O&&_.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},di="rgba(0,0,0,0.5)",fn=50,_=w.StyleSheet.create({top:{height:`${Ho*100}%`,overflow:"hidden",backgroundColor:"#000000"},full:{position:"absolute",top:0,left:0,right:0,bottom:0},content:{flex:1,backgroundColor:"#000000"},top_absolute:{position:"absolute",top:0,left:0,right:0,zIndex:1},content_closing:{position:"absolute",left:0,right:0,bottom:0,backgroundColor:"#000000"},preview_cover:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,overflow:"hidden"},dim_ring:{position:"absolute",borderWidth:Xe,borderColor:di,borderRadius:Xe+ht},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:It,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:It,borderRadius:It/2,backgroundColor:gt,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:gt,opacity:.2},scan_line:{height:ri,borderRadius:1,backgroundColor:gt},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:fn,height:fn,borderRadius:fn/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:gt},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});var we=require("react"),P=require("react-native");var J=require("react/jsx-runtime"),wn={[me.info]:"#3B82F6",[me.success]:"#22C55E",[me.error]:"#EF4444"},Jo=-120,Lt=P.Platform.OS==="android",Go=({type:e})=>e===me.success?(0,J.jsx)(P.View,{style:ne.check_mark}):e===me.error?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(P.View,{style:[ne.cross_bar,ne.cross_a]}),(0,J.jsx)(P.View,{style:[ne.cross_bar,ne.cross_b]})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(P.View,{style:ne.info_dot}),(0,J.jsx)(P.View,{style:ne.info_bar})]}),Ko=()=>{let e=H(at,y=>y.message),t=H(at,y=>y.type),n=H(at,y=>y.tick),o=(0,we.useRef)(new P.Animated.Value(Jo)).current,r=(0,we.useRef)(new P.Animated.Value(0)).current,i=(0,we.useRef)(new P.Animated.Value(.92)).current,a=(0,we.useRef)(new P.Animated.Value(0)).current,[c,l]=(0,we.useState)(),[s,d]=(0,we.useState)(!1);(0,we.useEffect)(()=>{let y=!0;return tn().then(p=>{y&&p&&l(()=>p)}),()=>{y=!1}},[]);let u=(0,we.useRef)(n);return(0,we.useEffect)(()=>{if(n===u.current)return;P.AccessibilityInfo.announceForAccessibility(e),d(!0),a.setValue(0),i.setValue(.92);let y=P.Animated.sequence([P.Animated.parallel([P.Animated.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),P.Animated.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),P.Animated.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),P.Animated.sequence([P.Animated.delay(90),P.Animated.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),P.Animated.delay(Zn[t]),P.Animated.parallel([P.Animated.timing(o,{toValue:Jo,duration:240,useNativeDriver:!0}),P.Animated.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return y.start(({finished:p})=>{p&&d(!1)}),()=>y.stop()},[n]),s?(0,J.jsx)(P.View,{style:[ne.layer,{top:Ct().top+(Lt?12:8)}],pointerEvents:"none",children:(0,J.jsxs)(P.Animated.View,{style:[ne.toast,Lt&&ne.toast_android,!!c&&ne.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&(0,J.jsx)(c,{style:ne.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Lt?(0,J.jsx)(P.Animated.View,{style:[ne.badge_halo,{backgroundColor:`${wn[t]}33`,transform:[{scale:a}]}],children:(0,J.jsx)(P.View,{style:[ne.badge,{backgroundColor:wn[t]}],children:(0,J.jsx)(Go,{type:t})})}):(0,J.jsx)(P.Animated.View,{style:[ne.badge,{backgroundColor:wn[t],transform:[{scale:a}]}],children:(0,J.jsx)(Go,{type:t})}),(0,J.jsx)(P.Text,{style:[ne.message,Lt&&ne.message_android],numberOfLines:2,children:e})]})}):null},ne=P.StyleSheet.create({layer:{position:"absolute",left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_android:{width:"100%",minHeight:60,gap:12,paddingLeft:10,paddingRight:16,paddingVertical:10,borderRadius:20,borderWidth:P.StyleSheet.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ue=Le({active_key:null,instances:{}}),Yo=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=D().keep_alive)==null?void 0:c.max_webviews;ue.setState(l=>{let s=t!=null?t:e.app_id,d={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},u=Object.keys(d);return a&&a>0&&u.length>a&&u.filter(y=>y!==s).sort((y,p)=>d[y].last_used_at-d[p].last_used_at).slice(0,u.length-a).forEach(y=>{delete d[y]}),i?{active_key:s,instances:d}:{instances:d}})},Xo=e=>Yo(e,!0),Qo=e=>Yo(e,!1),Qe=()=>ue.setState({active_key:null}),Ft=e=>{ue.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var Zo="catalog",gi="paused_apps",hi="removed_apps",mi=10*1e3,fi=2,yi=3e3,wi=()=>{var e;try{return JSON.parse((e=D().storage.getString(Zo))!=null?e:"{}")}catch{return{}}},U=Le({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),er=e=>{var t;return!!((t=D().manual_update)!=null&&t.includes(e))},Ut=new Set,tr=e=>{let t=new Set,n=()=>D().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=D().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},_e=tr(gi),Ve=tr(hi);On(()=>{_e.load(),Ve.load();let e=wi(),t={};Object.keys(e).filter(n=>!Ve.has(n)).forEach(n=>{let o=N(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:_e.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),U.setState({catalog:e,downloads:t})});var Vt=e=>H(U,t=>e?t.downloads[e]:void 0),nr=()=>H(U,e=>e.pause_reasons.length>0),Se=(...e)=>he("queue",...e),Z=[],Oe={},k=null,Dt=new Set,je={},bn=new Set,Ne=e=>{bn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},or=e=>(bn.add(e),()=>{bn.delete(e)}),rr=()=>U.getState().downloads,de=(e,t)=>{let n=!!N(e),o=U.getState().downloads[e],r=t.status==="downloading"&&n?"updating":t.status,i={...o!=null?o:{status:"queued",progress:0},...t,...r?{status:r}:{},has_local:n};U.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?Ne({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Ne({type:"progress",app_id:e,progress:i.progress,version:i.version})},Nt=(e,t)=>{var n;(n=je[e])==null||n.forEach(o=>o(t)),delete je[e]},bi=()=>U.getState().pause_reasons.length>0,Ue=e=>{var c;if(k)return;let t=e?Z.indexOf(e):bi()?-1:Z.findIndex(l=>!_e.has(l));if(t<0||t>=Z.length)return;let[n]=Z.splice(t,1),o=U.getState().catalog[n];if(!o){Nt(n,N(n)),Ue();return}let r=Date.now();Oe[n]=((c=Oe[n])!=null?c:0)+1,de(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=mn(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,de(n,{progress:s/100,version:o.version}))}});k={app_id:n,handle:a,forced:!!e},Se("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{Se("installed",n,o.version,`${Date.now()-r}ms`),de(n,{status:"installed",progress:1,version:o.version}),Nt(n,l)}).catch(l=>{var d;if(l instanceof Ye){if(Dt.has(n))return;Se("paused",n),Oe[n]-=1,Z.unshift(n),de(n,{status:_e.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((d=l==null?void 0:l.message)!=null?d:l);if(console.warn("[miniapp-queue] failed",n,s),Oe[n]<fi){de(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var u;Z.includes(n)||(k==null?void 0:k.app_id)===n||(Z.push(n),Ue((u=je[n])!=null&&u.length?n:void 0))},yi);return}de(n,{status:"failed",progress:0,version:o.version,error:s}),Nt(n,N(n))}).finally(()=>{k=null;let l=Z.find(s=>{var d;return(d=je[s])==null?void 0:d.length});Ue(l)})},Bt=(e,{front:t=!1}={})=>{if((k==null?void 0:k.app_id)===e)return;let n=Z.indexOf(e);if(n>=0){if(!t)return;Z.splice(n,1)}t?Z.unshift(e):Z.push(e)},Ai=async e=>{let{host_id:t,client_token:n}=D(),o=new AbortController,r=setTimeout(()=>o.abort(),mi);try{let i=`${Je}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},mt=null,qt=()=>(mt!=null||(mt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(D().channels.map(Ai)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(U.getState().catalog).filter(l=>!o[l]);D().storage.setString(Zo,JSON.stringify(o)),U.setState({catalog:o}),await Promise.all(r.map(l=>ir(l,{by_user:!1}))),r.forEach(l=>Ve.delete(l));let i=Object.keys(o).filter(l=>!Ve.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await gn(l)){de(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=N(l.app_id);if(er(l.app_id)&&!Ut.has(l.app_id)&&s&&await Te(s)){de(l.app_id,{status:"installed",progress:1,version:s.version}),c[l.app_id]={app_id:l.app_id,current_version:s.version,next_version:l.version};continue}a.push(l)}return U.setState({updates:c}),a.forEach(l=>{Oe[l.app_id]=0,de(l.app_id,{status:_e.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Bt(l.app_id)}),Se("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Ne({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Ne({type:"update_available",...l})),Ue(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),Ne({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{mt=null}})()),mt),ir=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ve.add(e),Dt.has(e))return;Dt.add(e),_e.delete(e);let n=Z.indexOf(e);n>=0&&Z.splice(n,1),(k==null?void 0:k.app_id)===e&&k.handle.cancel();let o=(c=(a=(r=U.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=N(e))==null?void 0:i.version)!=null?c:"";de(e,{status:"uninstalling",progress:0,version:o}),await Uo(e),Ft(e),U.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Oe[e],Dt.delete(e),Nt(e,null),Se("uninstalled",e,t?"(user)":"(not in list)"),Ne({type:"uninstalled",app_id:e})},sr=e=>ir(e,{by_user:!0}),ar=e=>{let t=Ze(e);return t?(Ve.delete(e),(k==null?void 0:k.app_id)===e||Z.includes(e)||(Oe[e]=0,de(e,{status:_e.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Bt(e),Ue(),Se("restore",e)),!0):!1},cr=e=>{if(_e.has(e))return;if(_e.add(e),Se("pause app",e),(k==null?void 0:k.app_id)===e&&!k.forced){k.handle.cancel();return}let t=U.getState().downloads[e];Z.includes(e)&&t&&de(e,{status:"paused",progress:0,version:t.version})},lr=e=>{if(!_e.delete(e))return;Se("resume app",e);let t=U.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!Z.includes(e)&&Ze(e)&&(Oe[e]=0,Bt(e)),Z.includes(e)&&t&&de(e,{status:"queued",progress:0,version:t.version}),Ue()},pr=e=>{let{pause_reasons:t}=U.getState();t.includes(e)||(U.setState({pause_reasons:[...t,e]}),Se("pause",e),t.length===0&&Ne({type:"pause_change",paused:!0,reasons:[e]}),k&&!k.forced&&k.handle.cancel())},ur=e=>{let{pause_reasons:t}=U.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);U.setState({pause_reasons:n}),Se("resume",e),n.length===0&&Ne({type:"pause_change",paused:!1,reasons:n}),Ue()},An=e=>U.getState().updates[e],dr=async e=>{var n,o;let t=An(e);Ut.add(e);try{let r=await ft(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=Ze(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(U.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),Se("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Ut.delete(e)}},gr=()=>Object.values(U.getState().catalog).map(e=>({...e,installed:!!N(e.app_id),removed_by_user:Ve.has(e.app_id)})),Ze=e=>U.getState().catalog[e],ft=async e=>{let t=Ze(e);if(!t)return;if(_e.delete(e),Ve.delete(e),await gn(t))return N(e);let n=N(e);if(er(e)&&!Ut.has(e)&&n&&await Te(n))return n;let o=new Promise(r=>{var i;((i=je[e])!=null?i:je[e]=[]).push(r)});return(k==null?void 0:k.app_id)===e?k.forced=!0:(Oe[e]=0,Bt(e,{front:!0}),k&&!k.forced?k.handle.cancel():Ue(e)),o};var F=require("react/jsx-runtime"),Sn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),hr=0,Si=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},_i=S.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var yt,wt;let u=(0,S.useRef)(null),y=(0,S.useRef)(!1),p=H(ue,h=>h.instances[e]),f=p==null?void 0:p.app.app_id,O=p==null?void 0:p.app.manifest_url,R=p==null?void 0:p.context,C=p==null?void 0:p.url_params,M=H(Q,h=>{var b;return((b=h.active)==null?void 0:b.owner)===e?h.active:null}),[q,W]=(0,S.useState)(null),[oe,Pe]=(0,S.useState)(M);M!==oe&&(Pe(M),M?W(null):(oe==null?void 0:oe.layout)===pe.top&&W(oe));let ce=(M==null?void 0:M.layout)===pe.top?M:q,[E,m]=(0,S.useState)(()=>f?N(f):null),[T,x]=(0,S.useState)(!1),[V,Ae]=(0,S.useState)(0),[Y,L]=(0,S.useState)(0),[re,G]=(0,S.useState)(!1),ee=(0,S.useRef)(null),ie=h=>{ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{ee.current=null,G(!0)},h)};(0,S.useEffect)(()=>()=>{ee.current&&clearTimeout(ee.current)},[]),(0,S.useEffect)(()=>{if(!f||!t&&E)return;let h=!0;return x(!1),(async()=>{let b=N(f),A=b?await Te(b):!1;if(!h||(m(A?ae=>!ae||ae.version!==b.version||ae.permissions.join(",")!==b.permissions.join(",")?b:ae:null),__DEV__&&Date.now()-hr>1e4&&(hr=Date.now(),await qt()),!h))return;let $=await ft(f),se=$!==void 0?$:O?await qo(f,O):N(f);if(h){if(!se){x(!0);return}m(ae=>ae!=null?ae:se)}})(),()=>{h=!1}},[t,f,O,V]),(0,S.useEffect)(()=>$o(e,h=>u.current?(u.current.postMessage(h),!0):!1),[e]);let ve=H(U,h=>{let b=f?h.downloads[f]:void 0;return(b==null?void 0:b.status)==="installed"?b.version:void 0});(0,S.useEffect)(()=>{if(t||!f||!E)return;let h=N(f);if(!h||h.version===E.version)return;let b=!0;return Te(h).then(A=>{!b||!A||(he(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",E.version,"\u2192",h.version),m(h))}),()=>{b=!1}},[t,f,ve,E==null?void 0:E.version]);let Me=H(U,h=>{var b;return f&&(b=h.apply_ticks[f])!=null?b:0});(0,S.useEffect)(()=>{if(!Me||!f)return;let h=N(f);if(!h||h.version===(E==null?void 0:E.version))return;let b=!0;return Te(h).then(A=>{!b||!A||(he(`webview:${e}`,"c\u1EADp nh\u1EADt",E==null?void 0:E.version,"\u2192",h.version),G(!1),m(h))}),()=>{b=!1}},[Me]),(0,S.useEffect)(()=>{var A;let h=(A=D().keep_alive)==null?void 0:A.idle_close_ms;if(t||!h||h<=0)return;let b=setTimeout(()=>{Ft(e)},h);return()=>clearTimeout(b)},[t,e]),(0,S.useEffect)(()=>{r>0&&(x(!1),G(!1),L(h=>h+1),Ae(h=>h+1))},[r]);let He=(0,S.useRef)(t);(0,S.useEffect)(()=>{var h;He.current!==t&&(He.current=t,y.current&&((h=u.current)==null||h.injectJavaScript(Po(t?"resumed":"paused"))))},[t]);let xe=`${(yt=E==null?void 0:E.version)!=null?yt:"none"}:${(wt=E==null?void 0:E.permissions.join(","))!=null?wt:""}:${Y}`,Re=(0,S.useMemo)(()=>JSON.stringify([R!=null?R:{},C!=null?C:{}]),[R,C]),et=(0,S.useMemo)(()=>{var h;return Io(C!=null?C:{},(h=E==null?void 0:E.permissions)!=null?h:[])},[Re,E==null?void 0:E.permissions]),$t=(0,S.useMemo)(()=>Oo(R!=null?R:{},et)+Eo()+Co()+(D().debug?xo():""),[et]),Be=(0,S.useRef)(null),tt=(0,S.useRef)(null);(0,S.useEffect)(()=>{var b,A,$;if(!E)return;if(tt.current!==xe){tt.current=xe,Be.current=Re;return}if(Be.current===Re)return;let h=((A=JSON.parse((b=Be.current)!=null?b:"[]")[0])!=null?A:{}).org_id;if(Be.current=Re,h===(R==null?void 0:R.org_id)&&y.current){G(!1),ie(1500),($=u.current)==null||$.injectJavaScript(Ro(R!=null?R:{},et));return}G(!1),L(se=>se+1)},[Re,E,xe]),(0,S.useEffect)(()=>(t||(Ce(e),De(e),$e(e)),()=>{Ce(e),De(e),$e(e)}),[t,e,xe,r]),(0,S.useEffect)(()=>{let h=I.AppState.addEventListener("change",b=>{b==="background"&&!so()&&Ce(e),b==="background"&&!go()&&De(e)});return()=>h.remove()},[e]);let nt=(0,S.useCallback)(async h=>{var A,$,se,ae,Wt,En;let b=So(h.nativeEvent.data);if(!b){if(f&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(h.nativeEvent.data,{app_id:f,instance_id:e})).catch(j=>{console.warn("[miniapp] onWebEvent l\u1ED7i",f,j)})}catch(j){console.warn("[miniapp] onWebEvent l\u1ED7i",f,j)}return}if(b.method==="log"){let{level:j,text:K}=b;he(`web:${e}`,j!=null?j:"log",K!=null?K:"");return}if(b.method==="pong"){ee.current||G(!0);return}if(b.method==="touchAtTop"){i.emit(!!b.at_top);return}if(b.method==="contextApplied"){ee.current&&clearTimeout(ee.current),ee.current=null,G(!0);return}if(b.method==="ready"){y.current=!0,G(!0);let j=(A=ue.getState().instances[e])==null?void 0:A.context;j&&(($=u.current)==null||$.injectJavaScript(sn(j)));return}try{let j=await Fo(b,{getHostData:()=>{var K,ge;return(ge=(K=ue.getState().instances[e])==null?void 0:K.host_data)!=null?ge:{}},getPermissions:()=>{var K,ge;return f?(ge=(K=N(f))==null?void 0:K.permissions)!=null?ge:[]:[]},getContext:()=>{var K,ge;return(ge=(K=ue.getState().instances[e])==null?void 0:K.context)!=null?ge:{}},is_dark:o,close:Qe,app_id:f!=null?f:"",instance_id:e,options:c,emit:(K,ge)=>{var Cn;(Cn=u.current)==null||Cn.injectJavaScript(Mo(K,ge))},playBeep:(se=c==null?void 0:c.playScannerBeep)!=null?se:(()=>{var K;(K=u.current)==null||K.injectJavaScript(Lo())}),isActive:()=>ue.getState().active_key===e&&I.AppState.currentState!=="background"});b.id&&((ae=u.current)==null||ae.injectJavaScript(_o(b.id,j)))}catch(j){if(!b.id)return;let K=j==null?void 0:j.code,ge=j instanceof g?j:new g(typeof K=="string"?K:"HOST_ERROR",String((Wt=j==null?void 0:j.message)!=null?Wt:j));(En=u.current)==null||En.injectJavaScript(vo(b.id,ge))}},[e,o,f,i,c]),zt=(0,S.useCallback)(()=>{x(!1),L(h=>h+1),Ae(h=>h+1)},[]);return(0,F.jsxs)(I.View,{style:[I.StyleSheet.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&be.behind],pointerEvents:t?"auto":"none",children:[ce&&(0,F.jsx)(yn,{scanner:ce,closing:ce===q,onClosed:()=>{var h;W(null),ce.absolute&&((h=u.current)==null||h.injectJavaScript(an(0)))},onHeight:ce.absolute?h=>{var b;return(b=u.current)==null?void 0:b.injectJavaScript(an(h))}:void 0}),E?(0,F.jsx)(fr.default,{ref:u,source:{uri:E.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?pn():E.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:$t,onMessage:nt,onShouldStartLoadWithRequest:h=>{let b=h.url;return h.isTopFrame===!1||!/^https?:\/\//i.test(b)?!0:(Promise.resolve(c!=null&&c.openUrl?c.openUrl(b):I.Linking.openURL(b)).catch(()=>{}),!1)},setSupportMultipleWindows:!1,bounces:!1,overScrollMode:"never",onLoadStart:h=>{Ce(e),De(e),$e(e),he(`webview:${e}`,"load start",Sn(h.nativeEvent.url)),y.current=!1,G(!1)},onError:h=>{Ce(e),De(e),$e(e),he(`webview:${e}`,"load error",Sn(h.nativeEvent.url),h.nativeEvent.description),x(!0),G(!1)},onLoadEnd:h=>{let b=h.nativeEvent.url;he(`webview:${e}`,"load end",Sn(b)),f&&(d==null||d({app_id:f,instance_id:e,url:b})),ie(1500)},onContentProcessDidTerminate:()=>{Ce(e),De(e),$e(e),y.current=!1,G(!1),L(h=>h+1)},onRenderProcessGone:()=>(Ce(e),De(e),$e(e),y.current=!1,G(!1),L(h=>h+1),!0),style:be.webview},xe):null,(M==null?void 0:M.layout)===pe.full&&(0,F.jsx)(yn,{scanner:M}),p&&(0,F.jsx)(Mi,{visible:!E||!re,interactive:T,children:(0,F.jsx)(vi,{splash:a,app:p.app,is_dark:o,error:T,has_bundle:!!E,retry:zt})})]})}),vi=S.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=Vt(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return(0,F.jsx)(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),Mi=({visible:e,interactive:t,children:n})=>{let o=(0,S.useRef)(new I.Animated.Value(e?1:0)).current,[r,i]=(0,S.useState)(e);return(0,S.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=I.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?(0,F.jsx)(I.Animated.View,{style:[I.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},_n=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,F.jsxs)(I.View,{style:[be.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,F.jsx)(I.View,{style:[be.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,F.jsx)(I.Image,{source:{uri:e.icon},style:be.splash_icon_image}):(0,F.jsx)(I.Text,{style:be.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,F.jsx)(I.Text,{style:[be.splash_name,{color:i}],children:e.name}),n==="error"?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(I.Text,{style:be.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,F.jsx)(I.TouchableOpacity,{activeOpacity:.7,style:[be.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,F.jsx)(I.Text,{style:[be.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(I.ActivityIndicator,{style:be.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,F.jsxs)(I.Text,{style:be.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},mr=(e,t)=>{let n=(0,S.useRef)(t),o=(0,S.useRef)(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},xi=({container:e,splash:t=_n,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{mr("container",e),mr("splash",t);let l=e,s=H(ue,M=>M.active_key),d=(0,S.useRef)(s);s&&(d.current=s);let u=H(ue,M=>Object.keys(M.instances).join("|")),y=H(ue,M=>{var q;return M.active_key?(q=M.instances[M.active_key])==null?void 0:q.app.name:void 0}),p=(0,S.useMemo)(()=>u?u.split("|"):[],[u]),[f,O]=(0,S.useState)({}),R=(0,S.useRef)(Si()).current;(0,S.useEffect)(()=>{if(!s||!r)return;let M=I.BackHandler.addEventListener("hardwareBackPress",()=>(Qe(),!0));return()=>M.remove()},[s,r]);let C=(0,S.useCallback)(()=>{let M=ue.getState().active_key;M&&O(q=>({...q,[M]:(q[M]||0)+1}))},[]);return p.length?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(l,{visible:!!s,title:y!=null?y:"",is_dark:n,close:Qe,reload:C,subscribeWebAtTop:R.subscribe,children:p.map(M=>(0,F.jsx)(_i,{instance_key:M,is_active:s===M,is_front:(s!=null?s:d.current)===M,is_dark:n,reload_tick:f[M]||0,web_at_top:R,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},M))}),(0,F.jsx)(Ko,{})]}):null},be=I.StyleSheet.create({webview:{flex:1,backgroundColor:"transparent"},behind:{zIndex:-1},splash:{flex:1,alignItems:"center",justifyContent:"center",gap:12},splash_icon:{width:72,height:72,borderRadius:20,alignItems:"center",justifyContent:"center",overflow:"hidden"},splash_icon_image:{width:72,height:72},splash_letter:{fontSize:28,fontWeight:"700",color:"#1D4ED8"},splash_name:{fontSize:16,fontWeight:"600"},splash_hint:{color:"#71717A"},splash_spinner:{marginTop:8},retry_button:{marginTop:4,paddingHorizontal:20,paddingVertical:10,borderRadius:999},retry_text:{fontWeight:"600"}}),yr=S.default.memo(xi);var ke=require("react");var wr=e=>`changelog_seen:${e}`,Ei=10*1e3,vn=e=>D().storage.getString(wr(e))||null,Mn=(e,t=(n=>(n=N(e))==null?void 0:n.version)())=>{t&&D().storage.setString(wr(e),t)},br=e=>{var o;let t=(o=N(e))==null?void 0:o.version;if(!t)return null;let n=vn(e);return n?hn(t,n)>0?{app_id:e,from:n,to:t}:null:(Mn(e,t),null)},Ci=e=>{var t,n,o;return(o=(n=(t=U.getState().catalog[e])==null?void 0:t.channel)!=null?n:D().channels[0])!=null?o:"production"},xn=async(e,{from:t,to:n,channel:o=Ci(e)}={})=>{let{client_token:r}=D(),i=new URLSearchParams({channel:o});t&&i.set("from",t),n&&i.set("to",n);let a=new AbortController,c=setTimeout(()=>a.abort(),Ei);try{let l=await fetch(`${Je}/api/miniapps/${encodeURIComponent(e)}/changelog?${i}`,{headers:{Authorization:`Bearer ${r}`},signal:a.signal});if(!l.ok)throw new Error(`changelog ${e} ${l.status}`);return(await l.json()).versions}finally{clearTimeout(c)}},Ar=(e,{from:t,to:n,enabled:o=!0}={})=>{let[r,i]=(0,ke.useState)([]),[a,c]=(0,ke.useState)(!1),[l,s]=(0,ke.useState)(),[d,u]=(0,ke.useState)(0),y=(0,ke.useCallback)(()=>u(p=>p+1),[]);return(0,ke.useEffect)(()=>{if(!e||!o)return;let p=!0;return c(!0),s(void 0),xn(e,{from:t,to:n}).then(f=>{p&&i(f)}).catch(f=>{var O;p&&s(String((f==null?void 0:f.name)==="AbortError"?"timeout":(O=f==null?void 0:f.message)!=null?O:f))}).finally(()=>{p&&c(!1)}),()=>{p=!1}},[e,t,n,o,d]),{versions:r,loading:a,error:l,reload:y}};0&&(module.exports={CodeType,DefaultMiniAppSplash,MINIAPP_PLATFORM_URL,MiniAppHost,MiniAppHostError,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,ToastType,closeMiniApp,configureMiniApp,createMmkvStorage,createReactNativeBiometrics,createRnfsFileSystem,ensureMiniApp,fetchMiniAppChangelog,getLocalMiniApp,getMiniAppCatalog,getMiniAppCatalogEntry,getMiniAppChangelogSeen,getMiniAppStatuses,getMiniAppUpdate,getPendingChangelog,installBundledMiniApp,markMiniAppChangelogSeen,onMiniAppEvent,openMiniApp,pauseMiniApp,pauseMiniAppDownloads,preloadMiniApp,releaseSpeechFor,restoreMiniApp,resumeMiniApp,resumeMiniAppDownloads,sendEventToWeb,syncMiniAppCatalog,uninstallMiniApp,updateMiniApp,uploadToUrl,useMiniAppChangelog,useMiniAppDownload,useMiniAppDownloadsPaused});
88
+ })(); true;`,bi=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Vt=(e,t)=>{if(typeof e!="string"||!e)throw new g("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},tr=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:d,isActive:u,playBeep:y})=>{var T,_,B,G,ce,Le,ge,R;let p=s==null?void 0:s.handlers,h={app_id:c,instance_id:l,close:a},L=()=>{var f;(f=s==null?void 0:s.haptic)==null||f.call(s,"impactLight"),y==null||y()},k=()=>new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let f=eo(t);return ft(e,()=>to(f,u))}case"speech.start":{if(!d)throw k();let f={};if((t==null?void 0:t.lang)!==void 0){if(typeof t.lang!="string"||!/^[a-zA-Z]{2,8}(-[a-zA-Z0-9]{1,8})*$/.test(t.lang))throw new g("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");f.lang=t.lang}for(let z of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[z])!==void 0){if(typeof t[z]!="boolean")throw new g("INVALID_PARAMS",`${z} ph\u1EA3i l\xE0 boolean`);f[z]=t[z]}if((t==null?void 0:t.mode)!==void 0&&t.mode!=="s2t"&&t.mode!=="voice")throw new g("INVALID_PARAMS","mode ph\u1EA3i l\xE0 's2t' ho\u1EB7c 'voice'");let I=(t==null?void 0:t.mode)==="s2t"?"s2t":"voice",P=I==="voice"?(T=s==null?void 0:s.voice)!=null?T:s==null?void 0:s.speech:void 0;if(xo(l,P),P){Mo(l,P);try{return await P.start({owner:l,app_id:c,mode:I,options:f,emit:d,isActive:u!=null?u:(()=>!0)})}catch(z){throw vo(l,P),z}}return Po(l,f,d,u)}case"speech.stop":{let f=Co(l);return f?f.stop(l):To(l)}case et.scan:return Do(l,yn(t),u,L);case et.start:{if(!d)throw k();return No(l,yn(t),d,u,L)}case et.stop:return Vo(l);case"uploadFiles":{let{task_id:f,...I}=t!=null?t:{};if(f!==void 0&&(typeof f!="string"||!f))throw new g("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return bo(lo(I),{instance_id:l,app_id:c,getContext:r,task_id:f,config:s==null?void 0:s.upload,emit:d,exclusivePick:P=>ft("uploadFiles.pick",P)})}case"uploadFiles.cancel":wo(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return fo(s==null?void 0:s.upload);case"getBiometricAvailability":return((_=s==null?void 0:s.biometrics)!=null?_:await pn()).getAvailability();case"authenticateBiometric":{let f=Vt(t==null?void 0:t.reason,"reason").trim();if(!f||f.length>200)throw new g("INVALID_PARAMS","reason must contain 1\u2013200 characters");let I=t==null?void 0:t.cancelButtonText;if(I!==void 0&&(typeof I!="string"||!I.trim()||I.length>80))throw new g("INVALID_PARAMS","Invalid cancelButtonText");return ft(e,async()=>{var z;return((z=s==null?void 0:s.biometrics)!=null?z:await pn()).authenticate({reason:f,cancelButtonText:I})})}case"requestPayment":{let f=p==null?void 0:p.requestPayment;if(!f)throw k();let I=t==null?void 0:t.amount;if(typeof I!="number"||!Number.isFinite(I)||I<=0)throw new g("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let P={...t,amount:I,currency:Vt(t==null?void 0:t.currency,"currency")};return ft(e,()=>f(P,h))}case"printImage":{let f=p==null?void 0:p.printImage;if(!f)throw k();let I=Vt(t==null?void 0:t.image,"image");await ft(e,()=>f({image:I},h));return}case"openScreen":if(!(p!=null&&p.openScreen))throw k();await p.openScreen({screen:Vt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},h);return;case"closeApp":a();return;case"openWebview":{let f=String((B=t==null?void 0:t.url)!=null?B:"");if(!/^https?:\/\//i.test(f))throw new g("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(f):yt.Linking.openURL(f));return}case"openLink":{let f=String((G=t==null?void 0:t.url)!=null?G:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(f)||/^(javascript|file|data|about|blob):/i.test(f))throw new g("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(f):yt.Linking.openURL(f))}catch(I){throw new g("NOT_SUPPORTED",String((Le=(ce=I==null?void 0:I.message)!=null?ce:I)!=null?Le:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let f=_o(t);if(!f||(u==null?void 0:u())===!1)return;s!=null&&s.showToast?s.showToast(f.message,{type:f.type}):So(f.message,f.type);return}case"haptic":{let f=bi.has(t==null?void 0:t.type)?t.type:"selection";(ge=s==null?void 0:s.haptic)==null||ge.call(s,f);return}case"getSystemInfo":return{platform:yt.Platform.OS==="ios"?"ios":"android",appVersion:(R=s==null?void 0:s.app_version)!=null?R:"",theme:i?"dark":"light"};case"getAccessToken":{let f=n().access_token;if(!f)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return f}case"getToken":{let f=t==null?void 0:t.type;if(f==="access"){let z=n().access_token;if(!z)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return z}if(f!=="partner"&&f!=="chatbox")throw new g("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(f)}`);let I=Qo[f];if(!o().includes(I))throw new g("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${I} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let P=f==="partner"?n().partner_token:n().chatbox_token;if(!P)throw new g("HOST_ERROR",`Kh\xF4ng c\xF3 ${I}`);return P}case"getUserInfo":{let f=n().user;if(!f)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return f}case"getPageInfo":{let f=n().page;if(!f)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return f}case"sendMessage":case"insertText":throw new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new g("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var Cn=e=>`bundle:${e}`,En=()=>`${F().file_system.document_dir}/miniapps`,Pn=En,Tn=(e,t,n="index.html",o=!1,r=[])=>{let i=`${Pn()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},xn=e=>{var t;F().storage.setString(Cn(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Ai=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,$=e=>{let t=F().storage.getString(Cn(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return Tn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},De=e=>F().file_system.exists(e.entry_uri.replace("file://","")),Rn=async e=>{let t=$(e.app_id);return(t==null?void 0:t.version)===e.version&&await De(t)},or=async(e,t)=>{let n=F().file_system,o=`${Pn()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},rr=async e=>{var t;await((t=At[e])==null?void 0:t.catch(()=>{})),F().storage.setString(Cn(e),""),await F().file_system.remove(`${Pn()}/${e}`).catch(()=>{})},nt=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},At={},ir=(e,t)=>{var i;let o=((i=At[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return At[e]=r,r.then(()=>{At[e]===r&&delete At[e]}),o},kn=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let c=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(c)return c}return 0},sr=({manifest:e,zip_path:t})=>ir(e.app_id,async()=>{var i;let n=F().file_system,o=$(e.app_id);if(o&&kn(o.version,e.version)>=0&&await De(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=Tn(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),xn(e),me("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),or(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),On=(e,{base_url:t,onProgress:n}={})=>{let o=F().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new nt},l=async()=>{var u;c();let s=$(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return xn(e),$(e.app_id);c();let d=o.download({url:t?Ai(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,p)=>{var L;let h=p>0?p:(L=e.size)!=null?L:0;h>0&&(n==null||n(Math.min(1,y/h)))}});r=d;try{let{status:y}=await d.promise;if(c(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else me("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let p=Tn(e.app_id,e.version,e.entry,!!e.context_update,(u=e.permissions)!=null?u:[]);return await o.remove(p.dir).catch(()=>{}),await o.mkdir(p.dir),await o.unzip(a,p.dir),xn(e),or(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(y){throw i?new nt:y}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:ir(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},bt={},_i=__DEV__?0:60*1e3,nr={},ar=(e,t)=>{var o,r;let n=$(e);return n&&Date.now()-((o=nr[t])!=null?o:0)<_i?Promise.resolve(n):((r=bt[e])!=null||(bt[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),c=await On(a,{base_url:t}).promise;return nr[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),$(e))).finally(()=>{bt[e]=void 0})),bt[e])};var qt=new Map,cr=(e,t)=>(qt.set(e,t),()=>{qt.get(e)===t&&qt.delete(e)}),lr=(e,t)=>{let n=qt.get(e);return n?n(t):!1};var W=require("react"),w=require("react-native");var C=require("react/jsx-runtime"),_t="#22C55E",Si="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",Mi=2,$t=18,vi=1600,St=14,xi=2e3,dr=.38,Ci=40,pr=2,Ei=8,Pi=2e3,Ti=250,ot=2e3,Ri=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:St},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:St},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:St},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:St}],ur=({color:e})=>(0,C.jsx)(C.Fragment,{children:Ri.map((t,n)=>(0,C.jsx)(w.View,{style:[x.corner,t,{borderColor:e}]},n))}),Bt=({style:e,children:t,...n})=>{let o=(0,W.useRef)(new w.Animated.Value(1)).current,r=i=>w.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,C.jsx)(w.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,C.jsx)(w.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},Ln=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var m,S;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:d}=e,u=c===fe.top,y=(0,W.useRef)(new w.Animated.Value(0)).current,p=r.useCameraDevice("back"),h=(0,W.useRef)(new w.Animated.Value(1)).current,[L,k]=(0,W.useState)(!1),[T,_]=(0,W.useState)(1),B=(0,W.useRef)(null),[G,ce]=(0,W.useState)(()=>{let{width:M,height:H}=w.Dimensions.get("window");return{width:M,height:u?H*dr:H,window_y:0}}),Le=j(ne,M=>M.last_value),ge=j(ne,M=>M.hit_tick),R=j(ne,M=>M.scan_count),f=j(ne,M=>M.notice),I=j(ne,M=>M.is_picking),P=(0,W.useRef)(null),z=tt(),xe=z.top,ee=(0,W.useRef)(new w.Animated.Value(0)).current,U=(0,W.useRef)(new w.Animated.Value(0)).current,le=(0,W.useRef)(new w.Animated.Value(0)).current,X=(0,W.useRef)(n);X.current=n,(0,W.useEffect)(()=>{if(!t)return;y.setValue(G.height);let M=w.Animated.timing(y,{toValue:0,duration:Ti,easing:w.Easing.out(w.Easing.cubic),useNativeDriver:!1});return M.start(({finished:H})=>{var ue;H&&((ue=X.current)==null||ue.call(X))}),()=>M.stop()},[t,y]);let re=Math.round(G.width*(u?.8:.78)),pe=Math.round(u?G.height*.46:re*.78),Pe=Math.round((G.height-pe)/2),Te=Math.round((G.width-re)/2),Xe=r.useCodeScanner({codeTypes:i,onCodeScanned:(0,W.useCallback)(M=>_n(M),[])});(0,W.useEffect)(()=>{let M=w.BackHandler.addEventListener("hardwareBackPress",()=>(An(),!0));return()=>M.remove()},[]);let Re=(0,W.useRef)(ge);(0,W.useEffect)(()=>{if(ge===Re.current)return;ee.setValue(1),le.setValue(1);let M=w.Animated.parallel([w.Animated.timing(ee,{toValue:0,duration:450,useNativeDriver:!0}),w.Animated.sequence([w.Animated.delay(xi),w.Animated.timing(le,{toValue:0,duration:250,useNativeDriver:!0})])]);return M.start(),()=>M.stop()},[ge,ee,le]),(0,W.useEffect)(()=>{let M=ue=>w.Animated.timing(U,{toValue:ue,duration:vi,easing:w.Easing.inOut(w.Easing.quad),useNativeDriver:!0}),H=w.Animated.loop(w.Animated.sequence([M(1),M(0)]));return H.start(),()=>H.stop()},[U]);let Fe=(0,W.useCallback)(()=>{w.Animated.timing(h,{toValue:0,duration:220,useNativeDriver:!0}).start()},[h]);(0,W.useEffect)(()=>{let M=setTimeout(Fe,Pi);return()=>clearTimeout(M)},[Fe]);let[ct,sn]=(0,W.useState)(!1);(0,W.useEffect)(()=>{let M=requestAnimationFrame(()=>{M=requestAnimationFrame(()=>sn(!0))});return()=>cancelAnimationFrame(M)},[]);let He=!!(p!=null&&p.hasTorch),lt=(m=p==null?void 0:p.neutralZoom)!=null?m:1,pt=p?Math.min(p.maxZoom/lt,Ei):1,an=lt*Math.min(T,pt),Ct=M=>{var de;let{touches:H}=M.nativeEvent;if(H.length!==2){B.current=null;return}let ue=Math.hypot(H[0].pageX-H[1].pageX,H[0].pageY-H[1].pageY);(de=B.current)!=null||(B.current={distance:ue,level:T}),_(Math.max(1,Math.min(pt,B.current.level*(ue/B.current.distance))))},Et=(0,C.jsx)(w.Text,{style:[x.hint,!!f&&x.hint_notice],numberOfLines:1,children:(S=f!=null?f:l)!=null?S:Si});return(0,C.jsx)(w.Animated.View,{ref:P,onTouchMove:Ct,onTouchEnd:()=>{B.current=null},pointerEvents:t?"none":"auto",style:u?[x.top,d&&x.top_absolute,t&&{height:y}]:x.full,onLayout:({nativeEvent:{layout:M}})=>{var H;t||(o==null||o(M.height),(H=P.current)==null||H.measureInWindow((ue,de)=>{ce({width:M.width,height:M.height,window_y:de||0})}))},children:(0,C.jsxs)(w.View,{style:t?[x.content_closing,{height:G.height}]:x.content,children:[p&&ct&&(0,C.jsx)(r.Camera,{style:w.StyleSheet.absoluteFill,device:p,isActive:!I,codeScanner:Xe,torch:L&&He?"on":"off",zoom:an,onPreviewStarted:Fe,onError:M=>Uo(M.message)}),(0,C.jsx)(w.Animated.View,{style:[x.preview_cover,{opacity:h}],pointerEvents:"none"}),G.height>0&&(0,C.jsxs)(w.View,{style:x.overlay,pointerEvents:"none",children:[(0,C.jsx)(w.View,{style:[x.dim_ring,{top:Pe-ot,left:Te-ot,width:re+ot*2,height:pe+ot*2}]}),(0,C.jsxs)(w.View,{style:{position:"absolute",top:Pe,left:Te,width:re,height:pe},children:[(0,C.jsx)(ur,{color:"#FFFFFF"}),(0,C.jsx)(w.Animated.View,{style:[w.StyleSheet.absoluteFill,{opacity:ee}],children:(0,C.jsx)(ur,{color:_t})}),(0,C.jsxs)(w.Animated.View,{style:[x.scan_line_wrap,{transform:[{translateY:U.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,pe-$t)]})}]}],children:[(0,C.jsx)(w.View,{style:x.scan_glow_outer}),(0,C.jsx)(w.View,{style:x.scan_glow_inner}),(0,C.jsx)(w.View,{style:x.scan_line})]})]}),(0,C.jsx)(w.View,{style:[x.hint_slot,u?{top:0,height:Pe-6,justifyContent:"flex-end"}:{top:Pe+pe+20}],children:Et}),a===Be.continuous&&!!Le&&(0,C.jsx)(w.Animated.View,{style:[x.result_slot,{top:u?Pe+pe-Ci:Pe+pe+52},{opacity:le}],children:(0,C.jsxs)(w.View,{style:x.result,children:[(0,C.jsx)(w.View,{style:x.check_badge,children:(0,C.jsx)(w.View,{style:x.check_mark})}),(0,C.jsx)(w.Text,{style:x.result_text,numberOfLines:1,children:Le}),(0,C.jsxs)(w.Text,{style:x.result_count,children:["\xB7 ",R," m\xE3"]})]})})]}),G.height>0&&(0,C.jsx)(w.View,{style:[x.close_slot,u?x.close_slot_top:{top:Math.max(12,xe-G.window_y+12)}],children:(0,C.jsxs)(Bt,{style:[x.close_button,!!s&&x.glass_surface],onPress:An,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&(0,C.jsx)(s,{style:x.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,C.jsx)(w.View,{style:[x.close_bar,x.close_bar_a]}),(0,C.jsx)(w.View,{style:[x.close_bar,x.close_bar_b]})]})}),(0,C.jsx)(w.View,{style:[x.toolbar_wrap,!u&&{bottom:z.bottom+20}],pointerEvents:"box-none",children:(0,C.jsxs)(w.View,{style:[x.toolbar,!!s&&x.glass_surface],children:[s&&(0,C.jsx)(s,{style:x.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,C.jsx)(Bt,{style:x.tool,onPress:qo,disabled:I,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,C.jsxs)(w.View,{style:x.image_icon,children:[(0,C.jsx)(w.View,{style:x.image_icon_dot}),(0,C.jsx)(w.View,{style:x.image_icon_hill})]})}),!!p&&pt>=pr&&(0,C.jsx)(Bt,{style:[x.tool,T>1&&x.tool_on],onPress:()=>_(M=>M>1?1:pr),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,C.jsxs)(w.Text,{style:[x.zoom_text,T>1&&x.zoom_text_on],children:[Math.round(T*10)/10,"x"]})}),He&&(0,C.jsx)(Bt,{style:[x.tool,L&&x.tool_on],onPress:()=>k(M=>!M),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:L},children:(0,C.jsx)(w.Text,{style:[x.torch_icon,L&&x.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},ki="rgba(0,0,0,0.5)",In=50,x=w.StyleSheet.create({top:{height:`${dr*100}%`,overflow:"hidden",backgroundColor:"#000000"},full:{position:"absolute",top:0,left:0,right:0,bottom:0},content:{flex:1,backgroundColor:"#000000"},top_absolute:{position:"absolute",top:0,left:0,right:0,zIndex:1},content_closing:{position:"absolute",left:0,right:0,bottom:0,backgroundColor:"#000000"},preview_cover:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,overflow:"hidden"},dim_ring:{position:"absolute",borderWidth:ot,borderColor:ki,borderRadius:ot+St},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:$t,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:$t,borderRadius:$t/2,backgroundColor:_t,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:_t,opacity:.2},scan_line:{height:Mi,borderRadius:1,backgroundColor:_t},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:In,height:In,borderRadius:In/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:_t},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});var Se=require("react"),O=require("react-native");var Y=require("react/jsx-runtime"),Fn={[be.info]:"#3B82F6",[be.success]:"#22C55E",[be.error]:"#EF4444"},gr=-120,zt=O.Platform.OS==="android",hr=({type:e})=>e===be.success?(0,Y.jsx)(O.View,{style:se.check_mark}):e===be.error?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(O.View,{style:[se.cross_bar,se.cross_a]}),(0,Y.jsx)(O.View,{style:[se.cross_bar,se.cross_b]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(O.View,{style:se.info_dot}),(0,Y.jsx)(O.View,{style:se.info_bar})]}),mr=()=>{let e=j(mt,y=>y.message),t=j(mt,y=>y.type),n=j(mt,y=>y.tick),o=(0,Se.useRef)(new O.Animated.Value(gr)).current,r=(0,Se.useRef)(new O.Animated.Value(0)).current,i=(0,Se.useRef)(new O.Animated.Value(.92)).current,a=(0,Se.useRef)(new O.Animated.Value(0)).current,[c,l]=(0,Se.useState)(),[s,d]=(0,Se.useState)(!1);(0,Se.useEffect)(()=>{let y=!0;return bn().then(p=>{y&&p&&l(()=>p)}),()=>{y=!1}},[]);let u=(0,Se.useRef)(n);return(0,Se.useEffect)(()=>{if(n===u.current)return;O.AccessibilityInfo.announceForAccessibility(e),d(!0),a.setValue(0),i.setValue(.92);let y=O.Animated.sequence([O.Animated.parallel([O.Animated.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),O.Animated.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),O.Animated.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),O.Animated.sequence([O.Animated.delay(90),O.Animated.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),O.Animated.delay(Ao[t]),O.Animated.parallel([O.Animated.timing(o,{toValue:gr,duration:240,useNativeDriver:!0}),O.Animated.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return y.start(({finished:p})=>{p&&d(!1)}),()=>y.stop()},[n]),s?(0,Y.jsx)(O.View,{style:[se.layer,{top:tt().top+(zt?12:8)}],pointerEvents:"none",children:(0,Y.jsxs)(O.Animated.View,{style:[se.toast,zt&&se.toast_android,!!c&&se.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&(0,Y.jsx)(c,{style:se.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),zt?(0,Y.jsx)(O.Animated.View,{style:[se.badge_halo,{backgroundColor:`${Fn[t]}33`,transform:[{scale:a}]}],children:(0,Y.jsx)(O.View,{style:[se.badge,{backgroundColor:Fn[t]}],children:(0,Y.jsx)(hr,{type:t})})}):(0,Y.jsx)(O.Animated.View,{style:[se.badge,{backgroundColor:Fn[t],transform:[{scale:a}]}],children:(0,Y.jsx)(hr,{type:t})}),(0,Y.jsx)(O.Text,{style:[se.message,zt&&se.message_android],numberOfLines:2,children:e})]})}):null},se=O.StyleSheet.create({layer:{position:"absolute",left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_android:{width:"100%",minHeight:60,gap:12,paddingLeft:10,paddingRight:16,paddingVertical:10,borderRadius:20,borderWidth:O.StyleSheet.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ae=Oe({active_key:null,instances:{}}),fr=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=F().keep_alive)==null?void 0:c.max_webviews;ae.setState(l=>{let s=t!=null?t:e.app_id,d={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},u=Object.keys(d);return a&&a>0&&u.length>a&&u.filter(y=>y!==s).sort((y,p)=>d[y].last_used_at-d[p].last_used_at).slice(0,u.length-a).forEach(y=>{delete d[y]}),i?{active_key:s,instances:d}:{instances:d}})},yr=e=>fr(e,!0),wr=e=>fr(e,!1),rt=()=>ae.setState({active_key:null}),Wt=e=>{ae.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var br="catalog",Oi="paused_apps",Ii="removed_apps",Li=10*1e3,Fi=2,Di=3e3,Ni=()=>{var e;try{return JSON.parse((e=F().storage.getString(br))!=null?e:"{}")}catch{return{}}},N=Oe({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),Ar=e=>{var t;return!!((t=F().manual_update)!=null&&t.includes(e))},Jt=new Set,_r=e=>{let t=new Set,n=()=>F().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=F().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},Ee=_r(Oi),We=_r(Ii);Tt(()=>{Ee.load(),We.load();let e=Ni(),t={};Object.keys(e).filter(n=>!We.has(n)).forEach(n=>{let o=$(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:Ee.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),N.setState({catalog:e,downloads:t})});var it=e=>j(N,t=>e?t.downloads[e]:void 0),Sr=()=>j(N,e=>e.pause_reasons.length>0),Ce=(...e)=>me("queue",...e),oe=[],Ne={},D=null,Ht=new Set,Ye={},Dn=new Set,Ve=e=>{Dn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Gt=e=>(Dn.add(e),()=>{Dn.delete(e)}),Mr=()=>N.getState().downloads,ye=(e,t)=>{let n=!!$(e),o=N.getState().downloads[e],r=t.status==="downloading"&&n?"updating":t.status,i={...o!=null?o:{status:"queued",progress:0},...t,...r?{status:r}:{},has_local:n};N.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?Ve({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Ve({type:"progress",app_id:e,progress:i.progress,version:i.version})},jt=(e,t)=>{var n;(n=Ye[e])==null||n.forEach(o=>o(t)),delete Ye[e]},Vi=()=>N.getState().pause_reasons.length>0,ze=e=>{var c;if(D)return;let t=e?oe.indexOf(e):Vi()?-1:oe.findIndex(l=>!Ee.has(l));if(t<0||t>=oe.length)return;let[n]=oe.splice(t,1),o=N.getState().catalog[n];if(!o){jt(n,$(n)),ze();return}let r=Date.now();Ne[n]=((c=Ne[n])!=null?c:0)+1,ye(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=On(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,ye(n,{progress:s/100,version:o.version}))}});D={app_id:n,handle:a,forced:!!e},Ce("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{Ce("installed",n,o.version,`${Date.now()-r}ms`),ye(n,{status:"installed",progress:1,version:o.version}),jt(n,l)}).catch(l=>{var d;if(l instanceof nt){if(Ht.has(n))return;Ce("paused",n),Ne[n]-=1,oe.unshift(n),ye(n,{status:Ee.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((d=l==null?void 0:l.message)!=null?d:l);if(console.warn("[miniapp-queue] failed",n,s),Ne[n]<Fi){ye(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var u;oe.includes(n)||(D==null?void 0:D.app_id)===n||(oe.push(n),ze((u=Ye[n])!=null&&u.length?n:void 0))},Di);return}ye(n,{status:"failed",progress:0,version:o.version,error:s}),jt(n,$(n))}).finally(()=>{D=null;let l=oe.find(s=>{var d;return(d=Ye[s])==null?void 0:d.length});ze(l)})},Kt=(e,{front:t=!1}={})=>{if((D==null?void 0:D.app_id)===e)return;let n=oe.indexOf(e);if(n>=0){if(!t)return;oe.splice(n,1)}t?oe.unshift(e):oe.push(e)},Ui=async e=>{let{host_id:t,client_token:n}=F(),o=new AbortController,r=setTimeout(()=>o.abort(),Li);try{let i=`${Qe}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},Mt=null,Yt=()=>(Mt!=null||(Mt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(F().channels.map(Ui)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(N.getState().catalog).filter(l=>!o[l]);F().storage.setString(br,JSON.stringify(o)),N.setState({catalog:o}),await Promise.all(r.map(l=>vr(l,{by_user:!1}))),r.forEach(l=>We.delete(l));let i=Object.keys(o).filter(l=>!We.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await Rn(l)){ye(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=$(l.app_id);if(Ar(l.app_id)&&!Jt.has(l.app_id)&&s&&await De(s)){ye(l.app_id,{status:"installed",progress:1,version:s.version}),c[l.app_id]={app_id:l.app_id,current_version:s.version,next_version:l.version};continue}a.push(l)}return N.setState({updates:c}),a.forEach(l=>{Ne[l.app_id]=0,ye(l.app_id,{status:Ee.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Kt(l.app_id)}),Ce("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Ve({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Ve({type:"update_available",...l})),ze(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),Ve({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{Mt=null}})()),Mt),vr=async(e,{by_user:t})=>{var r,i,a,c;if(t&&We.add(e),Ht.has(e))return;Ht.add(e),Ee.delete(e);let n=oe.indexOf(e);n>=0&&oe.splice(n,1),(D==null?void 0:D.app_id)===e&&D.handle.cancel();let o=(c=(a=(r=N.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=$(e))==null?void 0:i.version)!=null?c:"";ye(e,{status:"uninstalling",progress:0,version:o}),await rr(e),Wt(e),N.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Ne[e],Ht.delete(e),jt(e,null),Ce("uninstalled",e,t?"(user)":"(not in list)"),Ve({type:"uninstalled",app_id:e})},xr=e=>vr(e,{by_user:!0}),Cr=e=>{let t=st(e);return t?(We.delete(e),(D==null?void 0:D.app_id)===e||oe.includes(e)||(Ne[e]=0,ye(e,{status:Ee.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Kt(e),ze(),Ce("restore",e)),!0):!1},Er=e=>{if(Ee.has(e))return;if(Ee.add(e),Ce("pause app",e),(D==null?void 0:D.app_id)===e&&!D.forced){D.handle.cancel();return}let t=N.getState().downloads[e];oe.includes(e)&&t&&ye(e,{status:"paused",progress:0,version:t.version})},Pr=e=>{if(!Ee.delete(e))return;Ce("resume app",e);let t=N.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!oe.includes(e)&&st(e)&&(Ne[e]=0,Kt(e)),oe.includes(e)&&t&&ye(e,{status:"queued",progress:0,version:t.version}),ze()},Tr=e=>{let{pause_reasons:t}=N.getState();t.includes(e)||(N.setState({pause_reasons:[...t,e]}),Ce("pause",e),t.length===0&&Ve({type:"pause_change",paused:!0,reasons:[e]}),D&&!D.forced&&D.handle.cancel())},Rr=e=>{let{pause_reasons:t}=N.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);N.setState({pause_reasons:n}),Ce("resume",e),n.length===0&&Ve({type:"pause_change",paused:!1,reasons:n}),ze()},Nn=e=>N.getState().updates[e],Xt=async e=>{var n,o;let t=Nn(e);Jt.add(e);try{let r=await vt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=st(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(N.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),Ce("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),Ve({type:"update_applied",app_id:e,version:r.version}),!0)}finally{Jt.delete(e)}},kr=()=>Object.values(N.getState().catalog).map(e=>({...e,installed:!!$(e.app_id),removed_by_user:We.has(e.app_id)})),st=e=>N.getState().catalog[e],vt=async e=>{let t=st(e);if(!t)return;if(Ee.delete(e),We.delete(e),await Rn(t))return $(e);let n=$(e);if(Ar(e)&&!Jt.has(e)&&n&&await De(n))return n;let o=new Promise(r=>{var i;((i=Ye[e])!=null?i:Ye[e]=[]).push(r)});return(D==null?void 0:D.app_id)===e?D.forced=!0:(Ne[e]=0,Kt(e,{front:!0}),D&&!D.forced?D.handle.cancel():ze(e)),o};var q=require("react/jsx-runtime"),Vn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),Or=0,qi=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},Bi=v.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var Ct,Et;let u=(0,v.useRef)(null),y=(0,v.useRef)(!1),p=j(ae,m=>m.instances[e]),h=p==null?void 0:p.app.app_id,L=p==null?void 0:p.app.manifest_url,k=p==null?void 0:p.context,T=p==null?void 0:p.url_params,_=j(ne,m=>{var S;return((S=m.active)==null?void 0:S.owner)===e?m.active:null}),[B,G]=(0,v.useState)(null),[ce,Le]=(0,v.useState)(_);_!==ce&&(Le(_),_?G(null):(ce==null?void 0:ce.layout)===fe.top&&G(ce));let ge=(_==null?void 0:_.layout)===fe.top?_:B,[R,f]=(0,v.useState)(()=>h?$(h):null),[I,P]=(0,v.useState)(!1),[z,xe]=(0,v.useState)(0),[ee,U]=(0,v.useState)(0),[le,X]=(0,v.useState)(!1),re=(0,v.useRef)(null),pe=m=>{re.current&&clearTimeout(re.current),re.current=setTimeout(()=>{re.current=null,X(!0)},m)};(0,v.useEffect)(()=>()=>{re.current&&clearTimeout(re.current)},[]),(0,v.useEffect)(()=>{if(!h||!t&&R)return;let m=!0;return P(!1),(async()=>{let S=$(h),M=S?await De(S):!1;if(!m||(f(M?de=>!de||de.version!==S.version||de.permissions.join(",")!==S.permissions.join(",")?S:de:null),__DEV__&&Date.now()-Or>1e4&&(Or=Date.now(),await Yt()),!m))return;let H=await vt(h),ue=H!==void 0?H:L?await ar(h,L):$(h);if(m){if(!ue){P(!0);return}f(de=>de!=null?de:ue)}})(),()=>{m=!1}},[t,h,L,z]),(0,v.useEffect)(()=>cr(e,m=>u.current?(u.current.postMessage(m),!0):!1),[e]);let Pe=j(N,m=>{let S=h?m.downloads[h]:void 0;return(S==null?void 0:S.status)==="installed"?S.version:void 0});(0,v.useEffect)(()=>{if(t||!h||!R)return;let m=$(h);if(!m||m.version===R.version)return;let S=!0;return De(m).then(M=>{!S||!M||(me(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",R.version,"\u2192",m.version),f(m))}),()=>{S=!1}},[t,h,Pe,R==null?void 0:R.version]);let Te=j(N,m=>{var S;return h&&(S=m.apply_ticks[h])!=null?S:0});(0,v.useEffect)(()=>{if(!Te||!h)return;let m=$(h);if(!m||m.version===(R==null?void 0:R.version))return;let S=!0;return De(m).then(M=>{!S||!M||(me(`webview:${e}`,"c\u1EADp nh\u1EADt",R==null?void 0:R.version,"\u2192",m.version),X(!1),f(m))}),()=>{S=!1}},[Te]),(0,v.useEffect)(()=>{var M;let m=(M=F().keep_alive)==null?void 0:M.idle_close_ms;if(t||!m||m<=0)return;let S=setTimeout(()=>{Wt(e)},m);return()=>clearTimeout(S)},[t,e]),(0,v.useEffect)(()=>{r>0&&(P(!1),X(!1),U(m=>m+1),xe(m=>m+1))},[r]);let Xe=(0,v.useRef)(t);(0,v.useEffect)(()=>{var m;Xe.current!==t&&(Xe.current=t,y.current&&((m=u.current)==null||m.injectJavaScript(Go(t?"resumed":"paused"))))},[t]);let Re=`${(Ct=R==null?void 0:R.version)!=null?Ct:"none"}:${(Et=R==null?void 0:R.permissions.join(","))!=null?Et:""}:${ee}`,Fe=(0,v.useMemo)(()=>JSON.stringify([k!=null?k:{},T!=null?T:{}]),[k,T]),ct=(0,v.useMemo)(()=>{var m;return Zo(T!=null?T:{},(m=R==null?void 0:R.permissions)!=null?m:[])},[Fe,R==null?void 0:R.permissions]),sn=(0,v.useMemo)(()=>Xo(k!=null?k:{},ct)+jo()+Jo()+(F().debug?Ho():""),[ct]),He=(0,v.useRef)(null),lt=(0,v.useRef)(null);(0,v.useEffect)(()=>{var S,M,H;if(!R)return;if(lt.current!==Re){lt.current=Re,He.current=Fe;return}if(He.current===Fe)return;let m=((M=JSON.parse((S=He.current)!=null?S:"[]")[0])!=null?M:{}).org_id;if(He.current=Fe,m===(k==null?void 0:k.org_id)&&y.current){X(!1),pe(1500),(H=u.current)==null||H.injectJavaScript(Ko(k!=null?k:{},ct));return}X(!1),U(ue=>ue+1)},[Fe,R,Re]),(0,v.useEffect)(()=>(t||(Ie(e),$e(e),Je(e)),()=>{Ie(e),$e(e),Je(e)}),[t,e,Re,r]),(0,v.useEffect)(()=>{let m=V.AppState.addEventListener("change",S=>{S==="background"&&!Eo()&&Ie(e),S==="background"&&!Io()&&$e(e)});return()=>m.remove()},[e]);let pt=(0,v.useCallback)(async m=>{var M,H,ue,de,cn,Jn;let S=Bo(m.nativeEvent.data);if(!S){if(h&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(m.nativeEvent.data,{app_id:h,instance_id:e})).catch(K=>{console.warn("[miniapp] onWebEvent l\u1ED7i",h,K)})}catch(K){console.warn("[miniapp] onWebEvent l\u1ED7i",h,K)}return}if(S.method==="log"){let{level:K,text:Q}=S;me(`web:${e}`,K!=null?K:"log",Q!=null?Q:"");return}if(S.method==="pong"){re.current||X(!0);return}if(S.method==="touchAtTop"){i.emit(!!S.at_top);return}if(S.method==="contextApplied"){re.current&&clearTimeout(re.current),re.current=null,X(!0);return}if(S.method==="ready"){y.current=!0,X(!0);let K=(M=ae.getState().instances[e])==null?void 0:M.context;K&&((H=u.current)==null||H.injectJavaScript(Mn(K)));return}try{let K=await tr(S,{getHostData:()=>{var Q,we;return(we=(Q=ae.getState().instances[e])==null?void 0:Q.host_data)!=null?we:{}},getPermissions:()=>{var Q,we;return h?(we=(Q=$(h))==null?void 0:Q.permissions)!=null?we:[]:[]},getContext:()=>{var Q,we;return(we=(Q=ae.getState().instances[e])==null?void 0:Q.context)!=null?we:{}},is_dark:o,close:rt,app_id:h!=null?h:"",instance_id:e,options:c,emit:(Q,we)=>{var Gn;(Gn=u.current)==null||Gn.injectJavaScript(Wo(Q,we))},playBeep:(ue=c==null?void 0:c.playScannerBeep)!=null?ue:(()=>{var Q;(Q=u.current)==null||Q.injectJavaScript(er())}),isActive:()=>ae.getState().active_key===e&&V.AppState.currentState!=="background"});S.id&&((de=u.current)==null||de.injectJavaScript($o(S.id,K)))}catch(K){if(!S.id)return;let Q=K==null?void 0:K.code,we=K instanceof g?K:new g(typeof Q=="string"?Q:"HOST_ERROR",String((cn=K==null?void 0:K.message)!=null?cn:K));(Jn=u.current)==null||Jn.injectJavaScript(zo(S.id,we))}},[e,o,h,i,c]),an=(0,v.useCallback)(()=>{P(!1),U(m=>m+1),xe(m=>m+1)},[]);return(0,q.jsxs)(V.View,{style:[V.StyleSheet.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&Me.behind],pointerEvents:t?"auto":"none",children:[ge&&(0,q.jsx)(Ln,{scanner:ge,closing:ge===B,onClosed:()=>{var m;G(null),ge.absolute&&((m=u.current)==null||m.injectJavaScript(vn(0)))},onHeight:ge.absolute?m=>{var S;return(S=u.current)==null?void 0:S.injectJavaScript(vn(m))}:void 0}),R?(0,q.jsx)(Lr.default,{ref:u,source:{uri:R.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?En():R.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:sn,onMessage:pt,onShouldStartLoadWithRequest:m=>{let S=m.url;return m.isTopFrame===!1||!/^https?:\/\//i.test(S)?!0:(Promise.resolve(c!=null&&c.openUrl?c.openUrl(S):V.Linking.openURL(S)).catch(()=>{}),!1)},setSupportMultipleWindows:!1,bounces:!1,overScrollMode:"never",onLoadStart:m=>{Ie(e),$e(e),Je(e),me(`webview:${e}`,"load start",Vn(m.nativeEvent.url)),y.current=!1,X(!1)},onError:m=>{Ie(e),$e(e),Je(e),me(`webview:${e}`,"load error",Vn(m.nativeEvent.url),m.nativeEvent.description),P(!0),X(!1)},onLoadEnd:m=>{let S=m.nativeEvent.url;me(`webview:${e}`,"load end",Vn(S)),h&&(d==null||d({app_id:h,instance_id:e,url:S})),pe(1500)},onContentProcessDidTerminate:()=>{Ie(e),$e(e),Je(e),y.current=!1,X(!1),U(m=>m+1)},onRenderProcessGone:()=>(Ie(e),$e(e),Je(e),y.current=!1,X(!1),U(m=>m+1),!0),style:Me.webview},Re):null,(_==null?void 0:_.layout)===fe.full&&(0,q.jsx)(Ln,{scanner:_}),p&&(0,q.jsx)(zi,{visible:!R||!le,interactive:I,children:(0,q.jsx)($i,{splash:a,app:p.app,is_dark:o,error:I,has_bundle:!!R,retry:an})})]})}),$i=v.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=it(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return(0,q.jsx)(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),zi=({visible:e,interactive:t,children:n})=>{let o=(0,v.useRef)(new V.Animated.Value(e?1:0)).current,[r,i]=(0,v.useState)(e);return(0,v.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=V.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?(0,q.jsx)(V.Animated.View,{style:[V.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},Un=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,q.jsxs)(V.View,{style:[Me.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,q.jsx)(V.View,{style:[Me.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,q.jsx)(V.Image,{source:{uri:e.icon},style:Me.splash_icon_image}):(0,q.jsx)(V.Text,{style:Me.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,q.jsx)(V.Text,{style:[Me.splash_name,{color:i}],children:e.name}),n==="error"?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(V.Text,{style:Me.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,q.jsx)(V.TouchableOpacity,{activeOpacity:.7,style:[Me.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,q.jsx)(V.Text,{style:[Me.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(V.ActivityIndicator,{style:Me.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,q.jsxs)(V.Text,{style:Me.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},Ir=(e,t)=>{let n=(0,v.useRef)(t),o=(0,v.useRef)(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},Wi=({container:e,splash:t=Un,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{Ir("container",e),Ir("splash",t);let l=e,s=j(ae,_=>_.active_key),d=(0,v.useRef)(s);s&&(d.current=s);let u=j(ae,_=>Object.keys(_.instances).join("|")),y=j(ae,_=>{var B;return _.active_key?(B=_.instances[_.active_key])==null?void 0:B.app.name:void 0}),p=(0,v.useMemo)(()=>u?u.split("|"):[],[u]),[h,L]=(0,v.useState)({}),k=(0,v.useRef)(qi()).current;(0,v.useEffect)(()=>{if(!s||!r)return;let _=V.BackHandler.addEventListener("hardwareBackPress",()=>(rt(),!0));return()=>_.remove()},[s,r]);let T=(0,v.useCallback)(()=>{let _=ae.getState().active_key;_&&L(B=>({...B,[_]:(B[_]||0)+1}))},[]);return p.length?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(l,{visible:!!s,title:y!=null?y:"",is_dark:n,close:rt,reload:T,subscribeWebAtTop:k.subscribe,children:p.map(_=>(0,q.jsx)(Bi,{instance_key:_,is_active:s===_,is_front:(s!=null?s:d.current)===_,is_dark:n,reload_tick:h[_]||0,web_at_top:k,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},_))}),(0,q.jsx)(mr,{})]}):null},Me=V.StyleSheet.create({webview:{flex:1,backgroundColor:"transparent"},behind:{zIndex:-1},splash:{flex:1,alignItems:"center",justifyContent:"center",gap:12},splash_icon:{width:72,height:72,borderRadius:20,alignItems:"center",justifyContent:"center",overflow:"hidden"},splash_icon_image:{width:72,height:72},splash_letter:{fontSize:28,fontWeight:"700",color:"#1D4ED8"},splash_name:{fontSize:16,fontWeight:"600"},splash_hint:{color:"#71717A"},splash_spinner:{marginTop:8},retry_button:{marginTop:4,paddingHorizontal:20,paddingVertical:10,borderRadius:999},retry_text:{fontWeight:"600"}}),Fr=v.default.memo(Wi);var Ue=require("react");var Nr=e=>`changelog_seen:${e}`,Hi=10*1e3,Zt=e=>F().storage.getString(Nr(e))||null,at=(e,t=(n=>(n=$(e))==null?void 0:n.version)())=>{t&&F().storage.setString(Nr(e),t)},Bn=e=>{var o;let t=(o=$(e))==null?void 0:o.version;if(!t)return null;let n=Zt(e);return n?kn(t,n)>0?{app_id:e,from:n,to:t}:null:(at(e,t),null)},ji=e=>{var t,n,o;return(o=(n=(t=N.getState().catalog[e])==null?void 0:t.channel)!=null?n:F().channels[0])!=null?o:"production"},en=async(e,{from:t,to:n,channel:o=ji(e)}={})=>{let{client_token:r}=F(),i=new URLSearchParams({channel:o});t&&i.set("from",t),n&&i.set("to",n);let a=new AbortController,c=setTimeout(()=>a.abort(),Hi);try{let l=await fetch(`${Qe}/api/miniapps/${encodeURIComponent(e)}/changelog?${i}`,{headers:{Authorization:`Bearer ${r}`},signal:a.signal});if(!l.ok)throw new Error(`changelog ${e} ${l.status}`);return(await l.json()).versions}finally{clearTimeout(c)}},tn=(e,{from:t,to:n,enabled:o=!0}={})=>{let[r,i]=(0,Ue.useState)([]),[a,c]=(0,Ue.useState)(!1),[l,s]=(0,Ue.useState)(),[d,u]=(0,Ue.useState)(0),y=(0,Ue.useCallback)(()=>u(p=>p+1),[]);return(0,Ue.useEffect)(()=>{if(!e||!o)return;let p=!0;return c(!0),s(void 0),en(e,{from:t,to:n}).then(h=>{p&&i(h)}).catch(h=>{var L;p&&s(String((h==null?void 0:h.name)==="AbortError"?"timeout":(L=h==null?void 0:h.message)!=null?L:h))}).finally(()=>{p&&c(!1)}),()=>{p=!1}},[e,t,n,o,d]),{versions:r,loading:a,error:l,reload:y}},xt=Oe({request:null}),qn=!1,Ji=e=>{var t,n;return(n=(t=N.getState().catalog[e])==null?void 0:t.name)!=null?n:e},Qt=async(e,{name:t}={})=>{if(xt.getState().request||qn)return!1;let n=Bn(e);if(!n)return!1;qn=!0;try{let o=await en(e,{from:n.from,to:n.to});return o.length?(xt.setState({request:{...n,name:t!=null?t:Ji(e),versions:o}}),!0):(at(e,n.to),!1)}catch(o){return me("changelog failed",e,o),!1}finally{qn=!1}},nn=()=>{let{request:e}=xt.getState();e&&at(e.app_id,e.to),xt.setState({request:null})},on=()=>j(xt,e=>e.request),Dr=!1;Tt(()=>{if(Dr)return;Dr=!0;let e=()=>F().changelog!==!1;Gt(n=>{n.type==="status_change"&&n.state.status==="installed"&&!Zt(n.app_id)&&at(n.app_id,n.state.version),n.type==="update_applied"&&e()&&Qt(n.app_id)});let t=ae.getState().active_key;ae.subscribe(()=>{let{active_key:n,instances:o}=ae.getState();if(n===t)return;t=n;let r=n?o[n]:void 0;r&&e()&&Qt(r.app.app_id,{name:r.app.name})})});var ve=he(require("react")),b=require("react-native");var A=require("react/jsx-runtime"),Z={blue:"#007AFF",track:"#E5E5EA",overlay:"rgba(0, 0, 0, 0.6)",shadow:"#000000",title:"#1A1A1A",sub_title:"#666666",error:"#D92D20",hint:"#C0C0C0",surface:"#FFFFFF",background:"#F2F2F7"},$n=[{key:"new",label:"M\u1EDBi",color:"#007AFF",bg:"#E5F1FF"},{key:"fix",label:"S\u1EEDa l\u1ED7i",color:"#C4320A",bg:"#FFF1EB"},{key:"improve",label:"C\u1EA3i thi\u1EC7n",color:"#067647",bg:"#E7F7EE"}],zn=e=>({new:e.flatMap(t=>t.changelog.new),fix:e.flatMap(t=>t.changelog.fix),improve:e.flatMap(t=>t.changelog.improve)}),Gi=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleDateString("vi-VN")},rn=({changelog:e})=>(0,A.jsx)(b.View,{style:E.groups,children:$n.filter(t=>e[t.key].length).map(t=>(0,A.jsxs)(b.View,{style:E.group,children:[(0,A.jsx)(b.View,{style:[E.badge,{backgroundColor:t.bg}],children:(0,A.jsx)(b.Text,{style:[E.badge_text,{color:t.color}],children:t.label})}),e[t.key].map((n,o)=>(0,A.jsxs)(b.View,{style:E.item,children:[(0,A.jsx)(b.Text,{style:[E.bullet,{color:t.color}],children:"\u2022"}),(0,A.jsx)(b.Text,{style:E.item_text,children:n})]},o))]},t.key))}),Wn=({app_id:e,name:t,onClose:n})=>{let o=tt(),{versions:r,loading:i,error:a,reload:c}=tn(e);return(0,A.jsxs)(b.View,{style:[E.history,{paddingTop:o.top}],children:[(0,A.jsxs)(b.View,{style:E.history_header,children:[(0,A.jsxs)(b.Text,{style:E.history_title,numberOfLines:1,children:["L\u1ECBch s\u1EED c\u1EADp nh\u1EADt \xB7 ",t]}),(0,A.jsx)(b.TouchableOpacity,{onPress:n,hitSlop:12,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:(0,A.jsx)(b.Text,{style:E.link,children:"\u0110\xF3ng"})})]}),i&&!r.length?(0,A.jsx)(b.ActivityIndicator,{style:E.loading,color:Z.blue}):a&&!r.length?(0,A.jsxs)(b.View,{style:E.center,children:[(0,A.jsx)(b.Text,{style:E.sub_title,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c l\u1ECBch s\u1EED c\u1EADp nh\u1EADt."}),(0,A.jsx)(b.TouchableOpacity,{onPress:c,children:(0,A.jsx)(b.Text,{style:E.link,children:"Th\u1EED l\u1EA1i"})})]}):(0,A.jsxs)(b.ScrollView,{contentContainerStyle:[E.history_list,{paddingBottom:o.bottom+24}],children:[r.map(l=>(0,A.jsxs)(b.View,{style:E.card,children:[(0,A.jsxs)(b.View,{style:E.card_head,children:[(0,A.jsxs)(b.Text,{style:E.version,children:["v",l.version]}),(0,A.jsx)(b.Text,{style:E.date,children:Gi(l.created_at)})]}),(0,A.jsx)(rn,{changelog:l.changelog})]},l.version)),!r.length&&(0,A.jsx)(b.Text,{style:[E.sub_title,E.empty],children:"Ch\u01B0a c\xF3 ghi ch\xFA c\u1EADp nh\u1EADt."})]})]})},Hn=({request:e,changelog:t,onClose:n})=>{let[o,r]=(0,ve.useState)(!1);return(0,A.jsx)(b.Modal,{visible:!0,transparent:!o,animationType:o?"slide":"fade",statusBarTranslucent:!0,onRequestClose:n,children:o?(0,A.jsx)(Wn,{app_id:e.app_id,name:e.name,onClose:n}):(0,A.jsx)(b.Pressable,{style:E.overlay,onPress:n,children:(0,A.jsxs)(b.Pressable,{style:E.sheet,onPress:()=>{},children:[(0,A.jsx)(b.Text,{style:E.title,children:"C\xF3 g\xEC m\u1EDBi"}),(0,A.jsx)(b.Text,{style:E.sub_title,children:`${e.name} \xB7 v${e.from} \u2192 v${e.to}`}),(0,A.jsx)(b.ScrollView,{style:E.scroll,children:(0,A.jsx)(rn,{changelog:t})}),(0,A.jsx)(b.TouchableOpacity,{style:E.btn_primary,activeOpacity:.8,onPress:n,children:(0,A.jsx)(b.Text,{style:E.btn_primary_text,children:"\u0110\xE3 hi\u1EC3u"})}),(0,A.jsx)(b.TouchableOpacity,{style:E.btn_secondary,onPress:()=>r(!0),children:(0,A.jsx)(b.Text,{style:E.link,children:"Xem t\u1EA5t c\u1EA3 c\u1EADp nh\u1EADt"})})]})})})},jn=({update:e,is_updating:t,progress:n,has_failed:o,onUpdate:r,logo:i})=>{let a=(0,ve.useRef)(new b.Animated.Value(0)).current,c=(0,ve.useRef)(new b.Animated.Value(30)).current;return(0,ve.useEffect)(()=>{b.Animated.parallel([b.Animated.timing(a,{toValue:1,duration:400,useNativeDriver:!0}),b.Animated.spring(c,{toValue:0,friction:8,tension:40,useNativeDriver:!0})]).start()},[a,c]),(0,A.jsx)(b.Modal,{visible:!0,transparent:!0,animationType:"none",statusBarTranslucent:!0,onRequestClose:()=>{},children:(0,A.jsx)(b.View,{style:E.overlay,children:(0,A.jsxs)(b.Animated.View,{style:[E.container,{opacity:a,transform:[{translateY:c}]}],children:[i&&(0,A.jsx)(b.Image,{source:i,style:E.logo}),(0,A.jsx)(b.Text,{style:E.title,children:t?"\u0110ang c\u1EADp nh\u1EADt\u2026":"\u0110\xE3 c\xF3 b\u1EA3n c\u1EADp nh\u1EADt"}),!t&&(0,A.jsxs)(b.Text,{style:[E.sub_title,E.gap],children:[`Phi\xEAn b\u1EA3n ${e.next_version} \u0111\xE3 s\u1EB5n s\xE0ng (hi\u1EC7n t\u1EA1i ${e.current_version}).`,`
89
+ `,"Vui l\xF2ng c\u1EADp nh\u1EADt \u0111\u1EC3 ti\u1EBFp t\u1EE5c s\u1EED d\u1EE5ng."]}),!t&&o&&(0,A.jsx)(b.Text,{style:E.error_text,children:"C\u1EADp nh\u1EADt kh\xF4ng th\xE0nh c\xF4ng. Ki\u1EC3m tra k\u1EBFt n\u1ED1i m\u1EA1ng r\u1ED3i th\u1EED l\u1EA1i."}),t?(0,A.jsxs)(b.View,{style:E.progress_section,children:[(0,A.jsxs)(b.Text,{style:E.progress_text,children:[n,"%"]}),(0,A.jsx)(b.View,{style:E.progress_track,children:(0,A.jsx)(b.View,{style:[E.progress_fill,{width:`${n}%`}]})}),(0,A.jsx)(b.Text,{style:E.loading_hint,children:"Vui l\xF2ng kh\xF4ng t\u1EAFt \u1EE9ng d\u1EE5ng"})]}):(0,A.jsx)(b.TouchableOpacity,{style:[E.btn_primary,E.full],activeOpacity:.8,onPress:r,children:(0,A.jsx)(b.Text,{style:E.btn_primary_text,children:o?"Th\u1EED l\u1EA1i":"C\u1EADp nh\u1EADt ngay"})})]})})})},Ki=({app_ids:e,shouldShowUpdate:t,logo:n,renderUpdate:o,renderChangelog:r})=>{var k,T;let i=j(N,_=>_.updates),c=((k=e!=null?e:F().manual_update)!=null?k:[]).map(_=>i[_]).find(_=>!!_&&(!t||t(_))),l=it(c==null?void 0:c.app_id),[s,d]=(0,ve.useState)(!1),[u,y]=(0,ve.useState)(!1),p=(0,ve.useRef)(!1),h=on(),L=async()=>{if(!c||p.current)return;p.current=!0,d(!0),y(!1);let _=await Xt(c.app_id);p.current=!1,d(!1),y(!_)};if(c){let _=(l==null?void 0:l.status)==="updating"?Math.round(((T=l.progress)!=null?T:0)*100):0,B={update:c,is_updating:s,progress:_,has_failed:u,onUpdate:L};return(0,A.jsx)(A.Fragment,{children:o?o(B):(0,A.jsx)(jn,{...B,logo:n})})}if(h){let _={request:h,changelog:zn(h.versions),onClose:nn};return(0,A.jsx)(A.Fragment,{children:r?r(_):(0,A.jsx)(Hn,{..._})})}return null},Vr=b.Platform.select({ios:{shadowColor:Z.shadow,shadowOffset:{width:0,height:10},shadowOpacity:.1,shadowRadius:20},android:{elevation:10}}),E=b.StyleSheet.create({overlay:{flex:1,backgroundColor:Z.overlay,justifyContent:"center",alignItems:"center"},container:{width:"85%",maxWidth:340,backgroundColor:Z.surface,padding:24,borderRadius:28,alignItems:"center",...Vr},sheet:{width:"88%",maxWidth:380,maxHeight:"75%",backgroundColor:Z.surface,borderRadius:24,padding:22,...Vr},logo:{width:64,height:64,borderRadius:16,marginBottom:20},title:{fontSize:20,fontWeight:"700",color:Z.title,textAlign:"center"},sub_title:{fontSize:13,color:Z.sub_title,textAlign:"center",lineHeight:18,marginTop:6},gap:{marginBottom:15},error_text:{fontSize:12,textAlign:"center",color:Z.error,lineHeight:17,marginBottom:15},progress_section:{width:"100%",alignItems:"center",paddingVertical:8,marginTop:8,gap:12},progress_text:{fontSize:18,fontWeight:"700",color:Z.blue},progress_track:{width:"100%",height:6,borderRadius:3,backgroundColor:Z.track,overflow:"hidden"},progress_fill:{height:"100%",borderRadius:3,backgroundColor:Z.blue},loading_hint:{fontSize:12,color:Z.hint,textAlign:"center"},scroll:{marginTop:16,flexGrow:0},groups:{gap:14},group:{gap:6},badge:{alignSelf:"flex-start",paddingHorizontal:10,paddingVertical:3,borderRadius:999},badge_text:{fontSize:12,fontWeight:"700"},item:{flexDirection:"row",gap:8,paddingLeft:4},bullet:{fontSize:15,lineHeight:20},item_text:{flex:1,fontSize:15,lineHeight:20,color:Z.title},full:{width:"100%"},btn_primary:{marginTop:18,backgroundColor:Z.blue,paddingVertical:14,borderRadius:12,alignItems:"center"},btn_primary_text:{color:"white",fontWeight:"600",fontSize:16},btn_secondary:{paddingTop:12,alignItems:"center"},link:{color:Z.blue,fontSize:15,fontWeight:"600"},history:{flex:1,backgroundColor:Z.background},history_header:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",gap:12,paddingHorizontal:16,paddingVertical:14},history_title:{flex:1,fontSize:17,fontWeight:"700",color:Z.title},history_list:{paddingHorizontal:16,gap:12},card:{backgroundColor:Z.surface,borderRadius:16,padding:16,gap:12},card_head:{flexDirection:"row",justifyContent:"space-between",alignItems:"baseline"},version:{fontSize:16,fontWeight:"700",color:Z.title},date:{fontSize:13,color:Z.sub_title},loading:{marginTop:40},center:{alignItems:"center",marginTop:40,gap:12},empty:{marginTop:40}}),Ur=ve.default.memo(Ki);0&&(module.exports={CodeType,DefaultMiniAppChangelogPrompt,DefaultMiniAppSplash,DefaultMiniAppUpdatePrompt,MINIAPP_CHANGELOG_KINDS,MINIAPP_PLATFORM_URL,MiniAppChangelogGroups,MiniAppChangelogHistory,MiniAppHost,MiniAppHostError,MiniAppUpdates,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,ToastType,closeMiniApp,configureMiniApp,createMmkvStorage,createReactNativeBiometrics,createRnfsFileSystem,dismissMiniAppChangelog,ensureMiniApp,fetchMiniAppChangelog,getLocalMiniApp,getMiniAppCatalog,getMiniAppCatalogEntry,getMiniAppChangelogSeen,getMiniAppStatuses,getMiniAppUpdate,getPendingChangelog,installBundledMiniApp,markMiniAppChangelogSeen,mergeMiniAppChangelog,onMiniAppEvent,openMiniApp,pauseMiniApp,pauseMiniAppDownloads,preloadMiniApp,releaseSpeechFor,restoreMiniApp,resumeMiniApp,resumeMiniAppDownloads,sendEventToWeb,showMiniAppChangelog,syncMiniAppCatalog,uninstallMiniApp,updateMiniApp,uploadToUrl,useMiniAppChangelog,useMiniAppChangelogRequest,useMiniAppDownload,useMiniAppDownloadsPaused});