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