@retion-miniapp/react-native 0.14.0 → 0.15.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.d.mts CHANGED
@@ -270,6 +270,38 @@ interface MiniAppBridgeOptions {
270
270
  app_id: string;
271
271
  instance_id: string;
272
272
  }) => void | Promise<void>;
273
+ /**
274
+ * Thay nhận dạng giọng nói có sẵn (expo-speech-recognition) bằng của app — vd trợ lý voice AI.
275
+ * Web vẫn gọi speech.start / speech.stop và nhận speech.partial / speech.final / speech.end / speech.error như cũ
276
+ * (không phải cập nhật mini app web). Không truyền → dùng nhận dạng có sẵn.
277
+ */
278
+ speech?: MiniAppSpeechProvider;
279
+ }
280
+ /** Ngữ cảnh 1 lần web gọi speech.start (provider của app tự quản phiên). */
281
+ interface MiniAppSpeechStartContext {
282
+ /** WebView đang gọi — dùng làm khoá phiên cho stop / release */
283
+ owner: string;
284
+ app_id: string;
285
+ /** Tham số web truyền (đã kiểm tra hợp lệ) */
286
+ options: {
287
+ lang?: string;
288
+ continuous?: boolean;
289
+ interimResults?: boolean;
290
+ addsPunctuation?: boolean;
291
+ requiresOnDeviceRecognition?: boolean;
292
+ };
293
+ /** Gửi event về đúng WebView: speech.partial / speech.final ({ text }), speech.end, speech.error ({ code, message }) */
294
+ emit: (event: 'speech.partial' | 'speech.final' | 'speech.end' | 'speech.error', data?: unknown) => void;
295
+ /** false = mini app đã đóng / ẩn */
296
+ isActive: () => boolean;
297
+ }
298
+ interface MiniAppSpeechProvider {
299
+ /** Bắt đầu nghe. Resolve khi đã bắt đầu; throw MiniAppHostError (BUSY / PERMISSION_DENIED…) nếu không được. */
300
+ start: (context: MiniAppSpeechStartContext) => Promise<void>;
301
+ /** Web gọi speech.stop (chỉ chủ phiên). Provider tự quyết gửi speech.final / speech.end sau đó. */
302
+ stop: (owner: string) => void | Promise<void>;
303
+ /** Mini app đóng / ẩn / app xuống nền: huỷ phiên của owner, không cần gửi event. */
304
+ release?: (owner: string) => void;
273
305
  }
274
306
  /** Biometric verification on this device; does not issue a backend login token. */
275
307
  type MiniAppBiometryType = 'FaceID' | 'TouchID' | 'Biometrics';
@@ -772,4 +804,4 @@ interface UploadCapabilities {
772
804
  /** XHR (không phải fetch) để có tiến trình upload; RN đọc file từ uri (cả content://), không nạp vào JS. */
773
805
  declare const uploadToUrl: MiniAppUploader;
774
806
 
775
- export { CodeType, DefaultMiniAppSplash, type LocationOptions, type LocationResult, MINIAPP_PLATFORM_URL, type MiniAppBiometricAvailability, type MiniAppBiometricRequest, type MiniAppBiometricResult, type MiniAppBiometrics, type MiniAppBiometryType, type MiniAppBridgeOptions, type MiniAppCatalogEntry, type MiniAppCatalogItem, type MiniAppChannel, type MiniAppConfig, type MiniAppContainerProps, type MiniAppContext, type MiniAppDownloadState, type MiniAppDownloadStatus, type MiniAppDownloadTask, type MiniAppEvent, type MiniAppFileSystem, type MiniAppHandlerContext, type MiniAppHapticType, _default as MiniAppHost, type MiniAppHostData, BridgeError as MiniAppHostError, type MiniAppHostProps, type MiniAppKeepAlive, type MiniAppLaunch, type MiniAppLocalBundle, type MiniAppManifest, type MiniAppNativeHandlers, type MiniAppPaymentRequest, type MiniAppPaymentResult, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppStatuses, getMiniAppUpdate, installBundledMiniApp, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppDownload, useMiniAppDownloadsPaused };
807
+ export { CodeType, DefaultMiniAppSplash, type LocationOptions, type LocationResult, MINIAPP_PLATFORM_URL, type MiniAppBiometricAvailability, type MiniAppBiometricRequest, type MiniAppBiometricResult, type MiniAppBiometrics, type MiniAppBiometryType, type MiniAppBridgeOptions, type MiniAppCatalogEntry, type MiniAppCatalogItem, type MiniAppChannel, type MiniAppConfig, type MiniAppContainerProps, type MiniAppContext, type MiniAppDownloadState, type MiniAppDownloadStatus, type MiniAppDownloadTask, type MiniAppEvent, type MiniAppFileSystem, type MiniAppHandlerContext, type MiniAppHapticType, _default as MiniAppHost, type MiniAppHostData, BridgeError as MiniAppHostError, type MiniAppHostProps, type MiniAppKeepAlive, type MiniAppLaunch, type MiniAppLocalBundle, type MiniAppManifest, type MiniAppNativeHandlers, type MiniAppPaymentRequest, type MiniAppPaymentResult, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSpeechProvider, type MiniAppSpeechStartContext, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppStatuses, getMiniAppUpdate, installBundledMiniApp, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppDownload, useMiniAppDownloadsPaused };
package/dist/index.d.ts CHANGED
@@ -270,6 +270,38 @@ interface MiniAppBridgeOptions {
270
270
  app_id: string;
271
271
  instance_id: string;
272
272
  }) => void | Promise<void>;
273
+ /**
274
+ * Thay nhận dạng giọng nói có sẵn (expo-speech-recognition) bằng của app — vd trợ lý voice AI.
275
+ * Web vẫn gọi speech.start / speech.stop và nhận speech.partial / speech.final / speech.end / speech.error như cũ
276
+ * (không phải cập nhật mini app web). Không truyền → dùng nhận dạng có sẵn.
277
+ */
278
+ speech?: MiniAppSpeechProvider;
279
+ }
280
+ /** Ngữ cảnh 1 lần web gọi speech.start (provider của app tự quản phiên). */
281
+ interface MiniAppSpeechStartContext {
282
+ /** WebView đang gọi — dùng làm khoá phiên cho stop / release */
283
+ owner: string;
284
+ app_id: string;
285
+ /** Tham số web truyền (đã kiểm tra hợp lệ) */
286
+ options: {
287
+ lang?: string;
288
+ continuous?: boolean;
289
+ interimResults?: boolean;
290
+ addsPunctuation?: boolean;
291
+ requiresOnDeviceRecognition?: boolean;
292
+ };
293
+ /** Gửi event về đúng WebView: speech.partial / speech.final ({ text }), speech.end, speech.error ({ code, message }) */
294
+ emit: (event: 'speech.partial' | 'speech.final' | 'speech.end' | 'speech.error', data?: unknown) => void;
295
+ /** false = mini app đã đóng / ẩn */
296
+ isActive: () => boolean;
297
+ }
298
+ interface MiniAppSpeechProvider {
299
+ /** Bắt đầu nghe. Resolve khi đã bắt đầu; throw MiniAppHostError (BUSY / PERMISSION_DENIED…) nếu không được. */
300
+ start: (context: MiniAppSpeechStartContext) => Promise<void>;
301
+ /** Web gọi speech.stop (chỉ chủ phiên). Provider tự quyết gửi speech.final / speech.end sau đó. */
302
+ stop: (owner: string) => void | Promise<void>;
303
+ /** Mini app đóng / ẩn / app xuống nền: huỷ phiên của owner, không cần gửi event. */
304
+ release?: (owner: string) => void;
273
305
  }
274
306
  /** Biometric verification on this device; does not issue a backend login token. */
275
307
  type MiniAppBiometryType = 'FaceID' | 'TouchID' | 'Biometrics';
@@ -772,4 +804,4 @@ interface UploadCapabilities {
772
804
  /** XHR (không phải fetch) để có tiến trình upload; RN đọc file từ uri (cả content://), không nạp vào JS. */
773
805
  declare const uploadToUrl: MiniAppUploader;
774
806
 
775
- export { CodeType, DefaultMiniAppSplash, type LocationOptions, type LocationResult, MINIAPP_PLATFORM_URL, type MiniAppBiometricAvailability, type MiniAppBiometricRequest, type MiniAppBiometricResult, type MiniAppBiometrics, type MiniAppBiometryType, type MiniAppBridgeOptions, type MiniAppCatalogEntry, type MiniAppCatalogItem, type MiniAppChannel, type MiniAppConfig, type MiniAppContainerProps, type MiniAppContext, type MiniAppDownloadState, type MiniAppDownloadStatus, type MiniAppDownloadTask, type MiniAppEvent, type MiniAppFileSystem, type MiniAppHandlerContext, type MiniAppHapticType, _default as MiniAppHost, type MiniAppHostData, BridgeError as MiniAppHostError, type MiniAppHostProps, type MiniAppKeepAlive, type MiniAppLaunch, type MiniAppLocalBundle, type MiniAppManifest, type MiniAppNativeHandlers, type MiniAppPaymentRequest, type MiniAppPaymentResult, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppStatuses, getMiniAppUpdate, installBundledMiniApp, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppDownload, useMiniAppDownloadsPaused };
807
+ export { CodeType, DefaultMiniAppSplash, type LocationOptions, type LocationResult, MINIAPP_PLATFORM_URL, type MiniAppBiometricAvailability, type MiniAppBiometricRequest, type MiniAppBiometricResult, type MiniAppBiometrics, type MiniAppBiometryType, type MiniAppBridgeOptions, type MiniAppCatalogEntry, type MiniAppCatalogItem, type MiniAppChannel, type MiniAppConfig, type MiniAppContainerProps, type MiniAppContext, type MiniAppDownloadState, type MiniAppDownloadStatus, type MiniAppDownloadTask, type MiniAppEvent, type MiniAppFileSystem, type MiniAppHandlerContext, type MiniAppHapticType, _default as MiniAppHost, type MiniAppHostData, BridgeError as MiniAppHostError, type MiniAppHostProps, type MiniAppKeepAlive, type MiniAppLaunch, type MiniAppLocalBundle, type MiniAppManifest, type MiniAppNativeHandlers, type MiniAppPaymentRequest, type MiniAppPaymentResult, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSpeechProvider, type MiniAppSpeechStartContext, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppStatuses, getMiniAppUpdate, installBundledMiniApp, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppDownload, useMiniAppDownloadsPaused };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var ar=Object.create;var ht=Object.defineProperty;var cr=Object.getOwnPropertyDescriptor;var lr=Object.getOwnPropertyNames;var pr=Object.getPrototypeOf,ur=Object.prototype.hasOwnProperty;var dr=(e,t)=>{for(var n in t)ht(e,n,{get:t[n],enumerable:!0})},An=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of lr(t))!ur.call(e,r)&&r!==n&&ht(e,r,{get:()=>t[r],enumerable:!(o=cr(t,r))||o.enumerable});return e};var le=(e,t,n)=>(n=e!=null?ar(pr(e)):{},An(t||!e||!e.__esModule?ht(n,"default",{value:e,enumerable:!0}):n,e)),gr=e=>An(ht({},"__esModule",{value:!0}),e);var gi={};dr(gi,{CodeType:()=>Q,DefaultMiniAppSplash:()=>wn,MINIAPP_PLATFORM_URL:()=>yt,MiniAppHost:()=>sr,MiniAppHostError:()=>m,ScannerEndReason:()=>ze,ScannerEvent:()=>Mt,ScannerLayout:()=>pe,ScannerMethod:()=>He,ToastType:()=>fe,closeMiniApp:()=>Ke,configureMiniApp:()=>vn,createMmkvStorage:()=>En,createReactNativeBiometrics:()=>zt,createRnfsFileSystem:()=>xn,ensureMiniApp:()=>gt,getLocalMiniApp:()=>B,getMiniAppCatalog:()=>nr,getMiniAppCatalogEntry:()=>Ye,getMiniAppStatuses:()=>Jo,getMiniAppUpdate:()=>hn,installBundledMiniApp:()=>Po,onMiniAppEvent:()=>Ho,openMiniApp:()=>Bo,pauseMiniApp:()=>Xo,pauseMiniAppDownloads:()=>Qo,preloadMiniApp:()=>qo,releaseSpeechFor:()=>Re,restoreMiniApp:()=>Yo,resumeMiniApp:()=>Zo,resumeMiniAppDownloads:()=>er,sendEventToWeb:()=>ko,syncMiniAppCatalog:()=>Vt,uninstallMiniApp:()=>Ko,updateMiniApp:()=>tr,uploadToUrl:()=>Jt,useMiniAppDownload:()=>Nt,useMiniAppDownloadsPaused:()=>jo});module.exports=gr(gi);var yt="https://retion-miniapp-platform.vercel.app",Be=null,Sn=new Set,vn=e=>{Be=e,Sn.forEach(t=>t())},q=()=>{if(!Be)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Be},Mn=e=>{Sn.add(e),Be&&e()},me=(...e)=>{Be!=null&&Be.debug&&console.log("[miniapp]",...e)};var xn=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:c,contentLength:l})=>r==null?void 0:r(c,l)});return{promise:a.then(({statusCode:c})=>({status:c})),cancel:()=>e.stopDownload(i)}}}),En=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var A=le(require("react")),L=require("react-native"),ir=le(require("react-native-webview"));var st=require("react-native");var zt=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),wt,Wt=()=>(wt||(wt=import("react-native-biometrics").then(({default:e})=>zt(new e({allowDeviceCredentials:!1}))).catch(e=>{throw wt=void 0,new m("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),wt);var Ee=require("react-native");var Rn=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new m("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 m("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new m("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Tn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new m("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(Ee.Platform.OS==="android"){let s=Ee.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,g=Ee.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,d=await Ee.PermissionsAndroid.check(s);if(!c())return;let y=d||await Ee.PermissionsAndroid.check(g);if(!c())return;if(!d&&!y){let u=await Ee.PermissionsAndroid.requestMultiple([s,g]);if(!c())return;if(u[s]!==Ee.PermissionsAndroid.RESULTS.GRANTED&&u[g]!==Ee.PermissionsAndroid.RESULTS.GRANTED)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var d;if(!c())return;let g=(d={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?d:"LOCATION_ERROR";i(new m(g,s.message))},e)}})().catch(l=>i(l))});var Ht=require("react-native");var jt=20,Pn=20,Fn=/^[a-z][a-z0-9_-]{0,31}$/,mr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,fr=["low","medium","high"],ke=e=>!!e&&typeof e=="object"&&!Array.isArray(e),K=e=>new m("INVALID_PARAMS",e),ot=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Cn=(e,t)=>{if(e===void 0)return{};if(!ke(e)||Object.keys(e).length>Pn||Object.values(e).some(n=>typeof n!="string"))throw K(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Pn} key)`);return e},Dn=e=>{var n,o,r,i;if(e!==void 0&&!ke(e))throw K("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!Fn.test(t.source)))throw K("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"||!mr.test(a))))throw K("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,jt))throw K(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${jt}`);if(t.max_size!==void 0&&!ot(t.max_size,1,Number.MAX_SAFE_INTEGER))throw K("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!ot(t.concurrency,1,5))throw K("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:hr(t.process),target:yr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},hr=e=>{if(e===void 0)return{};if(!ke(e))throw K("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!ke(n))throw K("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 K(`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 K("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 K("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!ot(n.max_duration,1,3600))throw K("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!fr.includes(n.quality))throw K("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},yr=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!ke(e))throw K("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Fn.test(t))throw K("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 K("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 K("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 K(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Cn(e.headers,"upload.headers"),form_data:Cn(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},Nn=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},wr=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Nn(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},br=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"},et,_r=()=>(et!=null||(et=import("react-native-image-picker").catch(e=>{throw et=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),et),On=e=>async({accept:t,max_count:n,process:o})=>{var l,s,g,d,y,u,w,I,T;let r=await _r(),i=br(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(d=(g=o.image)==null?void 0:g.quality)!=null?d:.8,videoQuality:(u=(y=o.video)==null?void 0:y.quality)!=null?u:"medium",durationLimit:(w=o.video)==null?void 0:w.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let E=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new m(E,(I=c.errorMessage)!=null?I:c.errorCode)}return((T=c.assets)!=null?T:[]).filter(E=>E.uri).map((E,M)=>{var N,$,te;return{uri:E.uri,name:(N=E.fileName)!=null?N:`file_${M+1}`,mime_type:($=E.type)!=null?$:"application/octet-stream",size:E.fileSize,width:E.width,height:E.height,duration:E.duration,processed:!((te=E.type)!=null&&te.startsWith("video/"))||Ht.Platform.OS==="ios"}})},Ar={"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"},Sr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},vr=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var g;return(g=Ar[s])!=null?g:Sr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let g=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(u=>u.uri&&!u.error).map((u,w)=>{var I,T,E;return{uri:u.uri,name:(I=u.name)!=null?I:`file_${w+1}`,mime_type:(T=u.type)!=null?T:"application/octet-stream",size:(E=u.size)!=null?E:void 0}});if(Ht.Platform.OS!=="android"||!e.keepLocalCopy||!g.some(u=>u.uri.startsWith("content://")))return g;let d=await e.keepLocalCopy({files:g.map(u=>({uri:u.uri,fileName:u.name})),destination:"cachesDirectory"}),y=new Map(d.map(u=>[u.sourceUri,u.status==="success"?u.localUri:void 0]));return g.map(u=>{var w;return{...u,uri:(w=y.get(u.uri))!=null?w:u.uri}})}catch(s){let g=s==null?void 0:s.code;if(g===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw g===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new m("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},tt,Mr=async e=>(tt!=null||(tt=import("@react-native-documents/picker").then(t=>vr(t)).catch(t=>{throw tt=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await tt)(e)),Un={library:On("library"),camera:On("camera"),document:Mr},kn={type:"image",label:"\u1EA2nh",accept:["image/*"]},In={type:"video",label:"Video",accept:["video/*"]},Ln={library:[kn,In],camera:[kn,In],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"]}]},nt,Vn=()=>(nt!=null||(nt=import("react-native-compressor").catch(()=>(nt=void 0,null))),nt),Bn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},xr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Er={low:640,medium:1280,high:1920},Rr=async(e,{image:t})=>{var o;if(!t||!xr.has(e.mime_type.toLowerCase()))return e;let n=await Vn();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 Bn(n,r,e.size),processed:!0}}catch{return e}},Tr=async(e,{video:t})=>{var o;let n=await Vn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Er[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Bn(n,r,e.size),processed:!0}}catch{return e}},Pr={image:Rr,video:Tr},Cr=(e,t)=>t.split(".").reduce((n,o)=>ke(n)?n[o]:void 0,e),Jt=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new m("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([d,y])=>l.append(d,y)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let g=d=>{o.removeEventListener("abort",s),d()};c.open("POST",a.url),Object.entries(a.headers).forEach(([d,y])=>c.setRequestHeader(d,y)),c.upload.onprogress=d=>n(d.loaded,d.total||e.size||0),c.onload=()=>g(()=>{let d=c.responseText;try{d=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new m("UPLOAD_FAILED",`HTTP ${c.status}`));return}let y=Cr(d,a.url_field);if(typeof y!="string"||!y){i(new m("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:y,response:d})}),c.onerror=()=>g(()=>i(new m("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>g(()=>i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),qn=e=>{var o,r;let t={...Un};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:Jt};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}},$n=e=>{let{sources:t,targets:n}=qn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Un[i]&&Ln[i]).map(i=>[i,Ln[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:jt}},_t=new Map,zn=(e,t)=>`${e}:${t}`,Or=0,Wn=(e,t)=>{var n;typeof t=="string"&&((n=_t.get(zn(e,t)))==null||n.abort())},qe=e=>{for(let[t,n]of _t)t.startsWith(`${e}:`)&&n.abort()},bt=()=>new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),kr=(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)}},jn=async(e,t)=>{var l;let{sources:n,targets:o}=qn(t.config),r=n[e.source];if(!r)throw new m("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 m("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=zn(t.instance_id,(l=t.task_id)!=null?l:`auto-${++Or}`);_t.set(c,a);try{return await Ir(e,t,r,i,a.signal)}finally{_t.delete(c)}},Ir=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=d=>d()},l,s,g)=>{var p,x,ne;let d={app_id:n!=null?n:"",instance_id:t,context:{...(p=o==null?void 0:o())!=null?p:{}}},y=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:d}))).slice(0,e.max_count);if(g.aborted)throw bt();if(!y.length)throw new m("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let u=[],w=y.filter(P=>wr(P,e.accept)?!0:(u.push({name:P.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${P.mime_type||Nn(P.name)}`}),!1)),I=w.map(()=>0),T=w.map(P=>{var ce;return(ce=P.size)!=null?ce:0}),E=0,M=0,N=(P=!1)=>{if(!a||!r)return;let ce=Date.now();if(!P&&ce-M<200)return;M=ce;let _e=T.reduce((O,oe)=>O+oe,0),G=I.reduce((O,oe)=>O+oe,0);a("upload.progress",{task_id:r,loaded:G,total:_e,percent:_e?Math.min(100,Math.round(G/_e*100)):0,done_count:E,count:w.length})},$=[],te=0,Te=async()=>{var P,ce,_e;for(;te<w.length;){let G=te++,O=w[G];try{if(g.aborted)throw bt();let oe=O.mime_type.startsWith("image/")?"image":O.mime_type.startsWith("video/")?"video":void 0,H=oe&&!O.processed?(ce=(P=i==null?void 0:i.processors)==null?void 0:P[oe])!=null?ce:Pr[oe]:void 0;if(H&&(O=await H(O,e.process),T[G]=(_e=O.size)!=null?_e:T[G],g.aborted))throw bt();if(e.max_size&&O.size&&O.size>e.max_size)throw new m("FILE_TOO_LARGE",`File ${O.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let Z=(je,xe)=>{I[G]=je,xe&&(T[G]=xe),N()},re=await s({file:O,target:e.target,onProgress:Z,signal:g,caller:d});if(typeof(re==null?void 0:re.url)!="string"||!re.url)throw new m("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:ve,...Me}=re;$[G]={url:ve,name:O.name,mime_type:O.mime_type,size:O.size,width:O.width,height:O.height,duration:O.duration,...Object.keys(Me).length?{response:"response"in Me?Me.response:Me}:{}},I[G]=T[G]}catch(oe){u.push(kr(w[G].name,oe))}finally{E++,N(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,w.length)},Te)),g.aborted)throw bt();let ae=$.filter(P=>!!P);if(!ae.length){let P=u[0];throw new m((x=P==null?void 0:P.code)!=null?x:"UPLOAD_FAILED",(ne=P==null?void 0:P.message)!=null?ne:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:ae,failed:u}};var At=require("react"),Ie=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)})}},W=(e,t,n=Object.is)=>{let o=(0,At.useRef)(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return(0,At.useSyncExternalStore)(e.subscribe,r)};var fe={info:"info",success:"success",error:"error"},Lr=200,Hn={info:2e3,success:2e3,error:3e3},rt=Ie({message:"",type:fe.info,tick:0}),Jn=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Lr);return o?{message:o,type:Object.values(fe).includes(n)?n:fe.info}:null},Gn=(e,t=fe.info)=>{rt.setState(n=>({message:e,type:t,tick:n.tick+1}))};var ye=require("react-native");var $e=require("react-native");var he,Kn=()=>$e.Platform.OS==="android"&&!!(he!=null&&he.requesting_permission),Fr=1500,St=()=>new Promise(e=>{if($e.Platform.OS!=="android"||$e.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Fr),o=$e.AppState.addEventListener("change",r=>{r==="active"&&t()})}),Gt=e=>{var t;if(he===e&&(he=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&$e.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Yn=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(he)throw new m("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};he=r;try{let g;try{g=await import("expo-speech-recognition")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let d=g.ExpoSpeechRecognitionModule;if(r.native=d,r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let y;try{y=await d.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await St(),r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.granted)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await d.getStateAsync()!=="inactive")throw new m("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 m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(d.addListener("result",u=>{var w,I;he!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(I=(w=u.results[0])==null?void 0:w.transcript)!=null?I:""})}),d.addListener("error",u=>{he===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),d.addListener("end",()=>{he===r&&(Gt(r),n("speech.end"))})),r.started=!0,d.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:g.AVAudioSessionCategory.playAndRecord,categoryOptions:[g.AVAudioSessionCategoryOptions.defaultToSpeaker,g.AVAudioSessionCategoryOptions.allowBluetooth],mode:g.AVAudioSessionMode.measurement}})}catch(g){throw Gt(r),g}},Xn=e=>{let t=he;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Re=e=>{let t=he;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{Gt(t)}};var Zn={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"},Q={...Zn,all:Object.values(Zn)},He={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Mt={result:"scanner.result",end:"scanner.end"},ze={user:"user",web:"web",closed:"closed",error:"error"},pe={top:"top",full:"full"},Le={once:"once",continuous:"continuous"},Dr=1500,Qn=6e4,V,Y=Ie({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),to=()=>ye.Platform.OS==="android"&&!!(V!=null&&V.requesting_permission),Yt=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r,absolute:i}=e!=null?e:{},a={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(c=>Q.all.includes(c)))throw new m("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>Qn)throw new m("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${Qn}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new m("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(pe).includes(r))throw new m("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new m("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},Xt=e=>V!==e?!1:(V=void 0,Y.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Nr=()=>ye.Alert.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{ye.Linking.openSettings().catch(()=>{})}}]),no=async(e,t)=>{if(V)throw new m("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");V=e;let n=()=>{if(e.cancelled||!t())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=ye.Platform.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await St(),n(),c!=="granted")throw a&&Nr(),new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new m("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await Zt();n(),Y.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 Xt(e),o}},vt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{vt=e==null?void 0:e.insets}).catch(()=>{});var xt=()=>{var e;return vt!=null?vt:{top:ye.Platform.OS==="ios"?54:(e=ye.StatusBar.currentHeight)!=null?e:0,bottom:ye.Platform.OS==="ios"?34:48}},Zt=async()=>{if(ye.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},oo=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:Q.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Dr,hint:n.hint,layout:t===Le.once?pe.full:(i=n.layout)!=null?i:pe.top,absolute:t!==Le.once&&((a=n.layout)!=null?a:pe.top)===pe.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},ro=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=oo(e,Le.once,t);a.onHit=o,a.resolve=r,a.reject=i,no(a,n).catch(i)}),io=(e,t,n,o=()=>!0,r)=>{let i=oo(e,Le.continuous,t);return i.emit=n,i.onHit=r,no(i,o)},Et=(e,t,n)=>{var o,r;if(!Y.getState().active){e.cancelled=!0;return}if(Xt(e)){if(e.mode===Le.once){(o=e.reject)==null||o.call(e,t===ze.error?new m("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new m("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,Mt.end,n?{reason:t,message:n}:{reason:t})}},so=e=>{(V==null?void 0:V.owner)===e&&Et(V,ze.web)},Fe=e=>{(V==null?void 0:V.owner)===e&&Et(V,ze.closed)},Qt=()=>{V&&Et(V,ze.user)},ao=e=>{V&&Et(V,ze.error,e)},en=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=V;if(!(!o||!Y.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(o.last_seen.set(c,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Le.once){Xt(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}Y.setState(g=>({last_value:c,hit_tick:g.hit_tick+1,scan_count:g.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,Mt.result,{value:c,type:l})}}},Ur={1:Q.code128,2:Q.code39,4:Q.code93,8:Q.codabar,16:Q.dataMatrix,32:Q.ean13,64:Q.ean8,128:Q.itf,256:Q.qr,512:Q.upcA,1024:Q.upcE,2048:Q.pdf417,4096:Q.aztec},Vr=2500,eo=2e3,Kt=e=>{Y.setState({notice:e}),setTimeout(()=>{Y.getState().notice===e&&Y.setState({notice:null})},Vr)},co=async()=>{var t,n;let e=V;if(!(!e||Y.getState().is_picking)){e.requesting_permission=!0,Y.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:eo,maxHeight:eo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||V!==e)return;if(r.errorCode||!i){Kt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(V!==e)return;let l=c.map(({value:s,format:g})=>({value:s,code_type:Ur[g]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:g})=>({value:s,type:g!=null?g:"unknown"}));if(!l.length){Kt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}en(l,Date.now(),!0)}catch{V===e&&Kt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await St(),e.requesting_permission=!1,V===e&&Y.setState({is_picking:!1})}}};var Tt=1,m=class extends Error{constructor(n,o){super(o);this.code=n}},lo=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Tt&&typeof t.method=="string"?t:null}catch{return null}},at=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,po=(e,t)=>at({id:e,result:t}),uo=(e,t)=>at({id:e,error:{code:t.code,message:t.message}}),go=(e,t)=>at({event:e,data:t}),nn=e=>at({event:"context",data:e});var mo=()=>`(function () {
1
+ "use strict";var pr=Object.create;var ht=Object.defineProperty;var ur=Object.getOwnPropertyDescriptor;var dr=Object.getOwnPropertyNames;var gr=Object.getPrototypeOf,mr=Object.prototype.hasOwnProperty;var fr=(e,t)=>{for(var n in t)ht(e,n,{get:t[n],enumerable:!0})},Sn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of dr(t))!mr.call(e,r)&&r!==n&&ht(e,r,{get:()=>t[r],enumerable:!(o=ur(t,r))||o.enumerable});return e};var le=(e,t,n)=>(n=e!=null?pr(gr(e)):{},Sn(t||!e||!e.__esModule?ht(n,"default",{value:e,enumerable:!0}):n,e)),hr=e=>Sn(ht({},"__esModule",{value:!0}),e);var hi={};fr(hi,{CodeType:()=>ee,DefaultMiniAppSplash:()=>bn,MINIAPP_PLATFORM_URL:()=>yt,MiniAppHost:()=>lr,MiniAppHostError:()=>m,ScannerEndReason:()=>ze,ScannerEvent:()=>xt,ScannerLayout:()=>pe,ScannerMethod:()=>He,ToastType:()=>fe,closeMiniApp:()=>Ke,configureMiniApp:()=>Mn,createMmkvStorage:()=>Rn,createReactNativeBiometrics:()=>Wt,createRnfsFileSystem:()=>En,ensureMiniApp:()=>gt,getLocalMiniApp:()=>B,getMiniAppCatalog:()=>ir,getMiniAppCatalogEntry:()=>Ye,getMiniAppStatuses:()=>Yo,getMiniAppUpdate:()=>yn,installBundledMiniApp:()=>ko,onMiniAppEvent:()=>Ko,openMiniApp:()=>zo,pauseMiniApp:()=>er,pauseMiniAppDownloads:()=>nr,preloadMiniApp:()=>Wo,releaseSpeechFor:()=>Re,restoreMiniApp:()=>Qo,resumeMiniApp:()=>tr,resumeMiniAppDownloads:()=>or,sendEventToWeb:()=>Fo,syncMiniAppCatalog:()=>Bt,uninstallMiniApp:()=>Zo,updateMiniApp:()=>rr,uploadToUrl:()=>Gt,useMiniAppDownload:()=>Ut,useMiniAppDownloadsPaused:()=>Go});module.exports=hr(hi);var yt="https://retion-miniapp-platform.vercel.app",Be=null,vn=new Set,Mn=e=>{Be=e,vn.forEach(t=>t())},$=()=>{if(!Be)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Be},xn=e=>{vn.add(e),Be&&e()},me=(...e)=>{Be!=null&&Be.debug&&console.log("[miniapp]",...e)};var En=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:c,contentLength:l})=>r==null?void 0:r(c,l)});return{promise:a.then(({statusCode:c})=>({status:c})),cancel:()=>e.stopDownload(i)}}}),Rn=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var A=le(require("react")),L=require("react-native"),cr=le(require("react-native-webview"));var st=require("react-native");var Wt=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),wt,jt=()=>(wt||(wt=import("react-native-biometrics").then(({default:e})=>Wt(new e({allowDeviceCredentials:!1}))).catch(e=>{throw wt=void 0,new m("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),wt);var Ee=require("react-native");var Pn=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new m("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 m("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new m("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Tn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new m("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(Ee.Platform.OS==="android"){let s=Ee.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,g=Ee.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,d=await Ee.PermissionsAndroid.check(s);if(!c())return;let y=d||await Ee.PermissionsAndroid.check(g);if(!c())return;if(!d&&!y){let u=await Ee.PermissionsAndroid.requestMultiple([s,g]);if(!c())return;if(u[s]!==Ee.PermissionsAndroid.RESULTS.GRANTED&&u[g]!==Ee.PermissionsAndroid.RESULTS.GRANTED)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var d;if(!c())return;let g=(d={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?d:"LOCATION_ERROR";i(new m(g,s.message))},e)}})().catch(l=>i(l))});var Jt=require("react-native");var Ht=20,Cn=20,Dn=/^[a-z][a-z0-9_-]{0,31}$/,yr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,wr=["low","medium","high"],ke=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Y=e=>new m("INVALID_PARAMS",e),ot=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,On=(e,t)=>{if(e===void 0)return{};if(!ke(e)||Object.keys(e).length>Cn||Object.values(e).some(n=>typeof n!="string"))throw Y(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Cn} key)`);return e},Nn=e=>{var n,o,r,i;if(e!==void 0&&!ke(e))throw Y("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!Dn.test(t.source)))throw Y("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"||!yr.test(a))))throw Y("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,Ht))throw Y(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Ht}`);if(t.max_size!==void 0&&!ot(t.max_size,1,Number.MAX_SAFE_INTEGER))throw Y("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!ot(t.concurrency,1,5))throw Y("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:br(t.process),target:_r(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},br=e=>{if(e===void 0)return{};if(!ke(e))throw Y("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!ke(n))throw Y("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 Y(`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 Y("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 Y("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!ot(n.max_duration,1,3600))throw Y("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!wr.includes(n.quality))throw Y("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},_r=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!ke(e))throw Y("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Dn.test(t))throw Y("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 Y("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 Y("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 Y(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:On(e.headers,"upload.headers"),form_data:On(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},Un=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},Ar=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Un(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Sr=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"},et,vr=()=>(et!=null||(et=import("react-native-image-picker").catch(e=>{throw et=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),et),kn=e=>async({accept:t,max_count:n,process:o})=>{var l,s,g,d,y,u,w,I,P;let r=await vr(),i=Sr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(d=(g=o.image)==null?void 0:g.quality)!=null?d:.8,videoQuality:(u=(y=o.video)==null?void 0:y.quality)!=null?u:"medium",durationLimit:(w=o.video)==null?void 0:w.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let E=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new m(E,(I=c.errorMessage)!=null?I:c.errorCode)}return((P=c.assets)!=null?P:[]).filter(E=>E.uri).map((E,M)=>{var N,z,ne;return{uri:E.uri,name:(N=E.fileName)!=null?N:`file_${M+1}`,mime_type:(z=E.type)!=null?z:"application/octet-stream",size:E.fileSize,width:E.width,height:E.height,duration:E.duration,processed:!((ne=E.type)!=null&&ne.startsWith("video/"))||Jt.Platform.OS==="ios"}})},Mr={"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"},xr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},Er=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var g;return(g=Mr[s])!=null?g:xr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let g=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(u=>u.uri&&!u.error).map((u,w)=>{var I,P,E;return{uri:u.uri,name:(I=u.name)!=null?I:`file_${w+1}`,mime_type:(P=u.type)!=null?P:"application/octet-stream",size:(E=u.size)!=null?E:void 0}});if(Jt.Platform.OS!=="android"||!e.keepLocalCopy||!g.some(u=>u.uri.startsWith("content://")))return g;let d=await e.keepLocalCopy({files:g.map(u=>({uri:u.uri,fileName:u.name})),destination:"cachesDirectory"}),y=new Map(d.map(u=>[u.sourceUri,u.status==="success"?u.localUri:void 0]));return g.map(u=>{var w;return{...u,uri:(w=y.get(u.uri))!=null?w:u.uri}})}catch(s){let g=s==null?void 0:s.code;if(g===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw g===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new m("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},tt,Rr=async e=>(tt!=null||(tt=import("@react-native-documents/picker").then(t=>Er(t)).catch(t=>{throw tt=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await tt)(e)),Vn={library:kn("library"),camera:kn("camera"),document:Rr},In={type:"image",label:"\u1EA2nh",accept:["image/*"]},Ln={type:"video",label:"Video",accept:["video/*"]},Fn={library:[In,Ln],camera:[In,Ln],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"]}]},nt,Bn=()=>(nt!=null||(nt=import("react-native-compressor").catch(()=>(nt=void 0,null))),nt),qn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Pr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Tr={low:640,medium:1280,high:1920},Cr=async(e,{image:t})=>{var o;if(!t||!Pr.has(e.mime_type.toLowerCase()))return e;let n=await Bn();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 qn(n,r,e.size),processed:!0}}catch{return e}},Or=async(e,{video:t})=>{var o;let n=await Bn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Tr[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await qn(n,r,e.size),processed:!0}}catch{return e}},kr={image:Cr,video:Or},Ir=(e,t)=>t.split(".").reduce((n,o)=>ke(n)?n[o]:void 0,e),Gt=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new m("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([d,y])=>l.append(d,y)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let g=d=>{o.removeEventListener("abort",s),d()};c.open("POST",a.url),Object.entries(a.headers).forEach(([d,y])=>c.setRequestHeader(d,y)),c.upload.onprogress=d=>n(d.loaded,d.total||e.size||0),c.onload=()=>g(()=>{let d=c.responseText;try{d=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new m("UPLOAD_FAILED",`HTTP ${c.status}`));return}let y=Ir(d,a.url_field);if(typeof y!="string"||!y){i(new m("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:y,response:d})}),c.onerror=()=>g(()=>i(new m("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>g(()=>i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),$n=e=>{var o,r;let t={...Vn};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:Gt};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}},zn=e=>{let{sources:t,targets:n}=$n(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Vn[i]&&Fn[i]).map(i=>[i,Fn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Ht}},_t=new Map,Wn=(e,t)=>`${e}:${t}`,Lr=0,jn=(e,t)=>{var n;typeof t=="string"&&((n=_t.get(Wn(e,t)))==null||n.abort())},qe=e=>{for(let[t,n]of _t)t.startsWith(`${e}:`)&&n.abort()},bt=()=>new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Fr=(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)}},Hn=async(e,t)=>{var l;let{sources:n,targets:o}=$n(t.config),r=n[e.source];if(!r)throw new m("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 m("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=Wn(t.instance_id,(l=t.task_id)!=null?l:`auto-${++Lr}`);_t.set(c,a);try{return await Dr(e,t,r,i,a.signal)}finally{_t.delete(c)}},Dr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=d=>d()},l,s,g)=>{var p,x,q;let d={app_id:n!=null?n:"",instance_id:t,context:{...(p=o==null?void 0:o())!=null?p:{}}},y=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:d}))).slice(0,e.max_count);if(g.aborted)throw bt();if(!y.length)throw new m("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let u=[],w=y.filter(T=>Ar(T,e.accept)?!0:(u.push({name:T.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${T.mime_type||Un(T.name)}`}),!1)),I=w.map(()=>0),P=w.map(T=>{var ce;return(ce=T.size)!=null?ce:0}),E=0,M=0,N=(T=!1)=>{if(!a||!r)return;let ce=Date.now();if(!T&&ce-M<200)return;M=ce;let _e=P.reduce((O,oe)=>O+oe,0),K=I.reduce((O,oe)=>O+oe,0);a("upload.progress",{task_id:r,loaded:K,total:_e,percent:_e?Math.min(100,Math.round(K/_e*100)):0,done_count:E,count:w.length})},z=[],ne=0,Pe=async()=>{var T,ce,_e;for(;ne<w.length;){let K=ne++,O=w[K];try{if(g.aborted)throw bt();let oe=O.mime_type.startsWith("image/")?"image":O.mime_type.startsWith("video/")?"video":void 0,J=oe&&!O.processed?(ce=(T=i==null?void 0:i.processors)==null?void 0:T[oe])!=null?ce:kr[oe]:void 0;if(J&&(O=await J(O,e.process),P[K]=(_e=O.size)!=null?_e:P[K],g.aborted))throw bt();if(e.max_size&&O.size&&O.size>e.max_size)throw new m("FILE_TOO_LARGE",`File ${O.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let Q=(je,xe)=>{I[K]=je,xe&&(P[K]=xe),N()},re=await s({file:O,target:e.target,onProgress:Q,signal:g,caller:d});if(typeof(re==null?void 0:re.url)!="string"||!re.url)throw new m("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:ve,...Me}=re;z[K]={url:ve,name:O.name,mime_type:O.mime_type,size:O.size,width:O.width,height:O.height,duration:O.duration,...Object.keys(Me).length?{response:"response"in Me?Me.response:Me}:{}},I[K]=P[K]}catch(oe){u.push(Fr(w[K].name,oe))}finally{E++,N(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,w.length)},Pe)),g.aborted)throw bt();let ae=z.filter(T=>!!T);if(!ae.length){let T=u[0];throw new m((x=T==null?void 0:T.code)!=null?x:"UPLOAD_FAILED",(q=T==null?void 0:T.message)!=null?q:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:ae,failed:u}};var At=require("react"),Ie=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,At.useRef)(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return(0,At.useSyncExternalStore)(e.subscribe,r)};var fe={info:"info",success:"success",error:"error"},Nr=200,Jn={info:2e3,success:2e3,error:3e3},rt=Ie({message:"",type:fe.info,tick:0}),Gn=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Nr);return o?{message:o,type:Object.values(fe).includes(n)?n:fe.info}:null},Kn=(e,t=fe.info)=>{rt.setState(n=>({message:e,type:t,tick:n.tick+1}))};var ye=require("react-native");var $e=require("react-native");var he,St=new Map,Yn=(e,t)=>{St.set(e,t)},Xn=e=>{St.delete(e)},Zn=()=>$e.Platform.OS==="android"&&!!(he!=null&&he.requesting_permission),Ur=1500,vt=()=>new Promise(e=>{if($e.Platform.OS!=="android"||$e.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Ur),o=$e.AppState.addEventListener("change",r=>{r==="active"&&t()})}),Kt=e=>{var t;if(he===e&&(he=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&$e.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Qn=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(he)throw new m("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};he=r;try{let g;try{g=await import("expo-speech-recognition")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let d=g.ExpoSpeechRecognitionModule;if(r.native=d,r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let y;try{y=await d.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await vt(),r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.granted)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await d.getStateAsync()!=="inactive")throw new m("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 m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(d.addListener("result",u=>{var w,I;he!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(I=(w=u.results[0])==null?void 0:w.transcript)!=null?I:""})}),d.addListener("error",u=>{he===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),d.addListener("end",()=>{he===r&&(Kt(r),n("speech.end"))})),r.started=!0,d.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:g.AVAudioSessionCategory.playAndRecord,categoryOptions:[g.AVAudioSessionCategoryOptions.defaultToSpeaker,g.AVAudioSessionCategoryOptions.allowBluetooth],mode:g.AVAudioSessionMode.measurement}})}catch(g){throw Kt(r),g}},eo=e=>{let t=he;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Re=e=>{var o;let t=St.get(e);if(t){St.delete(e);try{(o=t.release)==null||o.call(t,e)}catch{}return}let n=he;if(!(!n||n.owner!==e||n.cancelled)&&(n.cancelled=!0,n.started))try{n.native.abort()}catch{Kt(n)}};var to={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"},ee={...to,all:Object.values(to)},He={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},xt={result:"scanner.result",end:"scanner.end"},ze={user:"user",web:"web",closed:"closed",error:"error"},pe={top:"top",full:"full"},Le={once:"once",continuous:"continuous"},Vr=1500,no=6e4,V,X=Ie({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),ro=()=>ye.Platform.OS==="android"&&!!(V!=null&&V.requesting_permission),Xt=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r,absolute:i}=e!=null?e:{},a={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(c=>ee.all.includes(c)))throw new m("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>no)throw new m("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${no}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new m("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(pe).includes(r))throw new m("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new m("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},Zt=e=>V!==e?!1:(V=void 0,X.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Br=()=>ye.Alert.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{ye.Linking.openSettings().catch(()=>{})}}]),io=async(e,t)=>{if(V)throw new m("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");V=e;let n=()=>{if(e.cancelled||!t())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=ye.Platform.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await vt(),n(),c!=="granted")throw a&&Br(),new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new m("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await Qt();n(),X.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 Zt(e),o}},Mt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{Mt=e==null?void 0:e.insets}).catch(()=>{});var Et=()=>{var e;return Mt!=null?Mt:{top:ye.Platform.OS==="ios"?54:(e=ye.StatusBar.currentHeight)!=null?e:0,bottom:ye.Platform.OS==="ios"?34:48}},Qt=async()=>{if(ye.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},so=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:ee.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Vr,hint:n.hint,layout:t===Le.once?pe.full:(i=n.layout)!=null?i:pe.top,absolute:t!==Le.once&&((a=n.layout)!=null?a:pe.top)===pe.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},ao=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=so(e,Le.once,t);a.onHit=o,a.resolve=r,a.reject=i,io(a,n).catch(i)}),co=(e,t,n,o=()=>!0,r)=>{let i=so(e,Le.continuous,t);return i.emit=n,i.onHit=r,io(i,o)},Rt=(e,t,n)=>{var o,r;if(!X.getState().active){e.cancelled=!0;return}if(Zt(e)){if(e.mode===Le.once){(o=e.reject)==null||o.call(e,t===ze.error?new m("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new m("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,xt.end,n?{reason:t,message:n}:{reason:t})}},lo=e=>{(V==null?void 0:V.owner)===e&&Rt(V,ze.web)},Fe=e=>{(V==null?void 0:V.owner)===e&&Rt(V,ze.closed)},en=()=>{V&&Rt(V,ze.user)},po=e=>{V&&Rt(V,ze.error,e)},tn=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=V;if(!(!o||!X.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(o.last_seen.set(c,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Le.once){Zt(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}X.setState(g=>({last_value:c,hit_tick:g.hit_tick+1,scan_count:g.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,xt.result,{value:c,type:l})}}},qr={1:ee.code128,2:ee.code39,4:ee.code93,8:ee.codabar,16:ee.dataMatrix,32:ee.ean13,64:ee.ean8,128:ee.itf,256:ee.qr,512:ee.upcA,1024:ee.upcE,2048:ee.pdf417,4096:ee.aztec},$r=2500,oo=2e3,Yt=e=>{X.setState({notice:e}),setTimeout(()=>{X.getState().notice===e&&X.setState({notice:null})},$r)},uo=async()=>{var t,n;let e=V;if(!(!e||X.getState().is_picking)){e.requesting_permission=!0,X.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:oo,maxHeight:oo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||V!==e)return;if(r.errorCode||!i){Yt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(V!==e)return;let l=c.map(({value:s,format:g})=>({value:s,code_type:qr[g]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:g})=>({value:s,type:g!=null?g:"unknown"}));if(!l.length){Yt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}tn(l,Date.now(),!0)}catch{V===e&&Yt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await vt(),e.requesting_permission=!1,V===e&&X.setState({is_picking:!1})}}};var Tt=1,m=class extends Error{constructor(n,o){super(o);this.code=n}},go=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Tt&&typeof t.method=="string"?t:null}catch{return null}},at=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,mo=(e,t)=>at({id:e,result:t}),fo=(e,t)=>at({id:e,error:{code:t.code,message:t.message}}),ho=(e,t)=>at({event:e,data:t}),on=e=>at({event:"context",data:e});var yo=()=>`(function () {
2
2
  var post = function (level, args) {
3
3
  try {
4
4
  var parts = [];
@@ -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;`,fo=()=>`(function () {
22
+ })(); true;`,wo=()=>`(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; }
@@ -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;`,ho=()=>`(function () {
41
+ })(); true;`,bo=()=>`(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;`,yo=e=>at({event:e}),wo=(e,t)=>{let n=bo(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
63
- ${nn(e)}`},bo=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),_o=(e,t={})=>{let n=bo(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${Tt} };
62
+ })(); true;`,_o=e=>at({event:e}),Ao=(e,t)=>{let n=So(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
63
+ ${on(e)}`},So=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),vo=(e,t={})=>{let n=So(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${Tt} };
64
64
  window.__RETION_MINIAPP_CONTEXT__ = ${JSON.stringify(e)};
65
65
  ${n?`try { history.replaceState(history.state, '', location.pathname + '?' + ${JSON.stringify(n)} + location.hash); } catch (e) {}`:""}
66
- true;`},Ao={partner:"partner_token",chatbox:"chatbox_token"},So=(e,t)=>{let n={...e};for(let o of Object.values(Ao))t.includes(o)||delete n[o];return n},tn=new Set,it=async(e,t)=>{if(tn.has(e))throw new m("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);tn.add(e);try{return await t()}finally{tn.delete(e)}},on=e=>`(function () {
66
+ true;`},Mo={partner:"partner_token",chatbox:"chatbox_token"},xo=(e,t)=>{let n={...e};for(let o of Object.values(Mo))t.includes(o)||delete n[o];return n},nn=new Set,it=async(e,t)=>{if(nn.has(e))throw new m("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);nn.add(e);try{return await t()}finally{nn.delete(e)}},rn=e=>`(function () {
67
67
  window.__retionScannerHeight = ${Math.max(0,Math.round(e))};
68
68
  window.dispatchEvent(new Event('retionscannerheight'));
69
- })(); true;`,vo=()=>`(function () {
69
+ })(); true;`,Eo=()=>`(function () {
70
70
  try {
71
71
  var AudioCtx = window.AudioContext || window.webkitAudioContext;
72
72
  if (!AudioCtx) { return; }
@@ -85,4 +85,4 @@
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;`,Br=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Rt=(e,t)=>{if(typeof e!="string"||!e)throw new m("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},Mo=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:g,isActive:d,playBeep:y})=>{var E,M,N,$,te,Te,ae;let u=s==null?void 0:s.handlers,w={app_id:c,instance_id:l,close:a},I=()=>{var p;(p=s==null?void 0:s.haptic)==null||p.call(s,"impactLight"),y==null||y()},T=()=>new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let p=Rn(t);return it(e,()=>Tn(p,d))}case"speech.start":{if(!g)throw T();let p={};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 m("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");p.lang=t.lang}for(let x of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[x])!==void 0){if(typeof t[x]!="boolean")throw new m("INVALID_PARAMS",`${x} ph\u1EA3i l\xE0 boolean`);p[x]=t[x]}return Yn(l,p,g,d)}case"speech.stop":return Xn(l);case He.scan:return ro(l,Yt(t),d,I);case He.start:{if(!g)throw T();return io(l,Yt(t),g,d,I)}case He.stop:return so(l);case"uploadFiles":{let{task_id:p,...x}=t!=null?t:{};if(p!==void 0&&(typeof p!="string"||!p))throw new m("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return jn(Dn(x),{instance_id:l,app_id:c,getContext:r,task_id:p,config:s==null?void 0:s.upload,emit:g,exclusivePick:ne=>it("uploadFiles.pick",ne)})}case"uploadFiles.cancel":Wn(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return $n(s==null?void 0:s.upload);case"getBiometricAvailability":return((E=s==null?void 0:s.biometrics)!=null?E:await Wt()).getAvailability();case"authenticateBiometric":{let p=Rt(t==null?void 0:t.reason,"reason").trim();if(!p||p.length>200)throw new m("INVALID_PARAMS","reason must contain 1\u2013200 characters");let x=t==null?void 0:t.cancelButtonText;if(x!==void 0&&(typeof x!="string"||!x.trim()||x.length>80))throw new m("INVALID_PARAMS","Invalid cancelButtonText");return it(e,async()=>{var P;return((P=s==null?void 0:s.biometrics)!=null?P:await Wt()).authenticate({reason:p,cancelButtonText:x})})}case"requestPayment":{let p=u==null?void 0:u.requestPayment;if(!p)throw T();let x=t==null?void 0:t.amount;if(typeof x!="number"||!Number.isFinite(x)||x<=0)throw new m("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let ne={...t,amount:x,currency:Rt(t==null?void 0:t.currency,"currency")};return it(e,()=>p(ne,w))}case"printImage":{let p=u==null?void 0:u.printImage;if(!p)throw T();let x=Rt(t==null?void 0:t.image,"image");await it(e,()=>p({image:x},w));return}case"openScreen":if(!(u!=null&&u.openScreen))throw T();await u.openScreen({screen:Rt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},w);return;case"closeApp":a();return;case"openWebview":{let p=String((M=t==null?void 0:t.url)!=null?M:"");if(!/^https?:\/\//i.test(p))throw new m("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(p):st.Linking.openURL(p));return}case"openLink":{let p=String((N=t==null?void 0:t.url)!=null?N:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(p)||/^(javascript|file|data|about|blob):/i.test(p))throw new m("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(p):st.Linking.openURL(p))}catch(x){throw new m("NOT_SUPPORTED",String((te=($=x==null?void 0:x.message)!=null?$:x)!=null?te:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let p=Jn(t);if(!p||(d==null?void 0:d())===!1)return;s!=null&&s.showToast?s.showToast(p.message,{type:p.type}):Gn(p.message,p.type);return}case"haptic":{let p=Br.has(t==null?void 0:t.type)?t.type:"selection";(Te=s==null?void 0:s.haptic)==null||Te.call(s,p);return}case"getSystemInfo":return{platform:st.Platform.OS==="ios"?"ios":"android",appVersion:(ae=s==null?void 0:s.app_version)!=null?ae:"",theme:i?"dark":"light"};case"getAccessToken":{let p=n().access_token;if(!p)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return p}case"getToken":{let p=t==null?void 0:t.type;if(p==="access"){let P=n().access_token;if(!P)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return P}if(p!=="partner"&&p!=="chatbox")throw new m("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(p)}`);let x=Ao[p];if(!o().includes(x))throw new m("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${x} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let ne=p==="partner"?n().partner_token:n().chatbox_token;if(!ne)throw new m("HOST_ERROR",`Kh\xF4ng c\xF3 ${x}`);return ne}case"getUserInfo":{let p=n().user;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return p}case"getPageInfo":{let p=n().page;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return p}case"sendMessage":case"insertText":throw new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new m("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var sn=e=>`bundle:${e}`,an=()=>`${q().file_system.document_dir}/miniapps`,cn=an,ln=(e,t,n="index.html",o=!1,r=[])=>{let i=`${cn()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},rn=e=>{var t;q().storage.setString(sn(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},qr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,B=e=>{let t=q().storage.getString(sn(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return ln(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Ce=e=>q().file_system.exists(e.entry_uri.replace("file://","")),pn=async e=>{let t=B(e.app_id);return(t==null?void 0:t.version)===e.version&&await Ce(t)},Eo=async(e,t)=>{let n=q().file_system,o=`${cn()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Ro=async e=>{var t;await((t=lt[e])==null?void 0:t.catch(()=>{})),q().storage.setString(sn(e),""),await q().file_system.remove(`${cn()}/${e}`).catch(()=>{})},Je=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},lt={},To=(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},$r=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let c=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(c)return c}return 0},Po=({manifest:e,zip_path:t})=>To(e.app_id,async()=>{var i;let n=q().file_system,o=B(e.app_id);if(o&&$r(o.version,e.version)>=0&&await Ce(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=ln(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),rn(e),me("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),Eo(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),un=(e,{base_url:t,onProgress:n}={})=>{let o=q().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new Je},l=async()=>{var d;c();let s=B(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return rn(e),B(e.app_id);c();let g=o.download({url:t?qr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,u)=>{var I;let w=u>0?u:(I=e.size)!=null?I:0;w>0&&(n==null||n(Math.min(1,y/w)))}});r=g;try{let{status:y}=await g.promise;if(c(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else me("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let u=ln(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(a,u.dir),rn(e),Eo(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),u}catch(y){throw i?new Je:y}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:To(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},ct={},zr=__DEV__?0:60*1e3,xo={},Co=(e,t)=>{var o,r;let n=B(e);return n&&Date.now()-((o=xo[t])!=null?o:0)<zr?Promise.resolve(n):((r=ct[e])!=null||(ct[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),c=await un(a,{base_url:t}).promise;return xo[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),B(e))).finally(()=>{ct[e]=void 0})),ct[e])};var Pt=new Map,Oo=(e,t)=>(Pt.set(e,t),()=>{Pt.get(e)===t&&Pt.delete(e)}),ko=(e,t)=>{let n=Pt.get(e);return n?n(t):!1};var F=require("react"),h=require("react-native");var v=require("react/jsx-runtime"),pt="#22C55E",Wr="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",jr=2,Ot=18,Hr=1600,ut=14,Jr=2e3,Fo=.38,Gr=40,Io=2,Kr=8,Yr=2e3,Xr=250,Ge=2e3,Zr=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:ut},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:ut},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:ut},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:ut}],Lo=({color:e})=>(0,v.jsx)(v.Fragment,{children:Zr.map((t,n)=>(0,v.jsx)(h.View,{style:[S.corner,t,{borderColor:e}]},n))}),Ct=({style:e,children:t,...n})=>{let o=(0,F.useRef)(new h.Animated.Value(1)).current,r=i=>h.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,v.jsx)(h.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,v.jsx)(h.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},gn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var f,_;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:g}=e,d=c===pe.top,y=(0,F.useRef)(new h.Animated.Value(0)).current,u=r.useCameraDevice("back"),w=(0,F.useRef)(new h.Animated.Value(1)).current,[I,T]=(0,F.useState)(!1),[E,M]=(0,F.useState)(1),N=(0,F.useRef)(null),[$,te]=(0,F.useState)(()=>{let{width:b,height:U}=h.Dimensions.get("window");return{width:b,height:d?U*Fo:U,window_y:0}}),Te=W(Y,b=>b.last_value),ae=W(Y,b=>b.hit_tick),p=W(Y,b=>b.scan_count),x=W(Y,b=>b.notice),ne=W(Y,b=>b.is_picking),P=(0,F.useRef)(null),ce=xt(),_e=ce.top,G=(0,F.useRef)(new h.Animated.Value(0)).current,O=(0,F.useRef)(new h.Animated.Value(0)).current,oe=(0,F.useRef)(new h.Animated.Value(0)).current,H=(0,F.useRef)(n);H.current=n,(0,F.useEffect)(()=>{if(!t)return;y.setValue($.height);let b=h.Animated.timing(y,{toValue:0,duration:Xr,easing:h.Easing.out(h.Easing.cubic),useNativeDriver:!1});return b.start(({finished:U})=>{var ie;U&&((ie=H.current)==null||ie.call(H))}),()=>b.stop()},[t,y]);let Z=Math.round($.width*(d?.8:.78)),re=Math.round(d?$.height*.46:Z*.78),ve=Math.round(($.height-re)/2),Me=Math.round(($.width-Z)/2),je=r.useCodeScanner({codeTypes:i,onCodeScanned:(0,F.useCallback)(b=>en(b),[])});(0,F.useEffect)(()=>{let b=h.BackHandler.addEventListener("hardwareBackPress",()=>(Qt(),!0));return()=>b.remove()},[]);let xe=(0,F.useRef)(ae);(0,F.useEffect)(()=>{if(ae===xe.current)return;G.setValue(1),oe.setValue(1);let b=h.Animated.parallel([h.Animated.timing(G,{toValue:0,duration:450,useNativeDriver:!0}),h.Animated.sequence([h.Animated.delay(Jr),h.Animated.timing(oe,{toValue:0,duration:250,useNativeDriver:!0})])]);return b.start(),()=>b.stop()},[ae,G,oe]),(0,F.useEffect)(()=>{let b=ie=>h.Animated.timing(O,{toValue:ie,duration:Hr,easing:h.Easing.inOut(h.Easing.quad),useNativeDriver:!0}),U=h.Animated.loop(h.Animated.sequence([b(1),b(0)]));return U.start(),()=>U.stop()},[O]);let Pe=(0,F.useCallback)(()=>{h.Animated.timing(w,{toValue:0,duration:220,useNativeDriver:!0}).start()},[w]);(0,F.useEffect)(()=>{let b=setTimeout(Pe,Yr);return()=>clearTimeout(b)},[Pe]);let[Xe,Bt]=(0,F.useState)(!1);(0,F.useEffect)(()=>{let b=requestAnimationFrame(()=>{b=requestAnimationFrame(()=>Bt(!0))});return()=>cancelAnimationFrame(b)},[]);let Ve=!!(u!=null&&u.hasTorch),Ze=(f=u==null?void 0:u.neutralZoom)!=null?f:1,Qe=u?Math.min(u.maxZoom/Ze,Kr):1,qt=Ze*Math.min(E,Qe),mt=b=>{var se;let{touches:U}=b.nativeEvent;if(U.length!==2){N.current=null;return}let ie=Math.hypot(U[0].pageX-U[1].pageX,U[0].pageY-U[1].pageY);(se=N.current)!=null||(N.current={distance:ie,level:E}),M(Math.max(1,Math.min(Qe,N.current.level*(ie/N.current.distance))))},ft=(0,v.jsx)(h.Text,{style:[S.hint,!!x&&S.hint_notice],numberOfLines:1,children:(_=x!=null?x:l)!=null?_:Wr});return(0,v.jsx)(h.Animated.View,{ref:P,onTouchMove:mt,onTouchEnd:()=>{N.current=null},pointerEvents:t?"none":"auto",style:d?[S.top,g&&S.top_absolute,t&&{height:y}]:S.full,onLayout:({nativeEvent:{layout:b}})=>{var U;t||(o==null||o(b.height),(U=P.current)==null||U.measureInWindow((ie,se)=>{te({width:b.width,height:b.height,window_y:se||0})}))},children:(0,v.jsxs)(h.View,{style:t?[S.content_closing,{height:$.height}]:S.content,children:[u&&Xe&&(0,v.jsx)(r.Camera,{style:h.StyleSheet.absoluteFill,device:u,isActive:!ne,codeScanner:je,torch:I&&Ve?"on":"off",zoom:qt,onPreviewStarted:Pe,onError:b=>ao(b.message)}),(0,v.jsx)(h.Animated.View,{style:[S.preview_cover,{opacity:w}],pointerEvents:"none"}),$.height>0&&(0,v.jsxs)(h.View,{style:S.overlay,pointerEvents:"none",children:[(0,v.jsx)(h.View,{style:[S.dim_ring,{top:ve-Ge,left:Me-Ge,width:Z+Ge*2,height:re+Ge*2}]}),(0,v.jsxs)(h.View,{style:{position:"absolute",top:ve,left:Me,width:Z,height:re},children:[(0,v.jsx)(Lo,{color:"#FFFFFF"}),(0,v.jsx)(h.Animated.View,{style:[h.StyleSheet.absoluteFill,{opacity:G}],children:(0,v.jsx)(Lo,{color:pt})}),(0,v.jsxs)(h.Animated.View,{style:[S.scan_line_wrap,{transform:[{translateY:O.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,re-Ot)]})}]}],children:[(0,v.jsx)(h.View,{style:S.scan_glow_outer}),(0,v.jsx)(h.View,{style:S.scan_glow_inner}),(0,v.jsx)(h.View,{style:S.scan_line})]})]}),(0,v.jsx)(h.View,{style:[S.hint_slot,d?{top:0,height:ve-6,justifyContent:"flex-end"}:{top:ve+re+20}],children:ft}),a===Le.continuous&&!!Te&&(0,v.jsx)(h.Animated.View,{style:[S.result_slot,{top:d?ve+re-Gr:ve+re+52},{opacity:oe}],children:(0,v.jsxs)(h.View,{style:S.result,children:[(0,v.jsx)(h.View,{style:S.check_badge,children:(0,v.jsx)(h.View,{style:S.check_mark})}),(0,v.jsx)(h.Text,{style:S.result_text,numberOfLines:1,children:Te}),(0,v.jsxs)(h.Text,{style:S.result_count,children:["\xB7 ",p," m\xE3"]})]})})]}),$.height>0&&(0,v.jsx)(h.View,{style:[S.close_slot,d?S.close_slot_top:{top:Math.max(12,_e-$.window_y+12)}],children:(0,v.jsxs)(Ct,{style:[S.close_button,!!s&&S.glass_surface],onPress:Qt,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&(0,v.jsx)(s,{style:S.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(h.View,{style:[S.close_bar,S.close_bar_a]}),(0,v.jsx)(h.View,{style:[S.close_bar,S.close_bar_b]})]})}),(0,v.jsx)(h.View,{style:[S.toolbar_wrap,!d&&{bottom:ce.bottom+20}],pointerEvents:"box-none",children:(0,v.jsxs)(h.View,{style:[S.toolbar,!!s&&S.glass_surface],children:[s&&(0,v.jsx)(s,{style:S.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(Ct,{style:S.tool,onPress:co,disabled:ne,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,v.jsxs)(h.View,{style:S.image_icon,children:[(0,v.jsx)(h.View,{style:S.image_icon_dot}),(0,v.jsx)(h.View,{style:S.image_icon_hill})]})}),!!u&&Qe>=Io&&(0,v.jsx)(Ct,{style:[S.tool,E>1&&S.tool_on],onPress:()=>M(b=>b>1?1:Io),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,v.jsxs)(h.Text,{style:[S.zoom_text,E>1&&S.zoom_text_on],children:[Math.round(E*10)/10,"x"]})}),Ve&&(0,v.jsx)(Ct,{style:[S.tool,I&&S.tool_on],onPress:()=>T(b=>!b),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:I},children:(0,v.jsx)(h.Text,{style:[S.torch_icon,I&&S.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},Qr="rgba(0,0,0,0.5)",dn=50,S=h.StyleSheet.create({top:{height:`${Fo*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:Ge,borderColor:Qr,borderRadius:Ge+ut},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:Ot,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:Ot,borderRadius:Ot/2,backgroundColor:pt,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:pt,opacity:.2},scan_line:{height:jr,borderRadius:1,backgroundColor:pt},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:dn,height:dn,borderRadius:dn/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:pt},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});var we=require("react"),R=require("react-native");var j=require("react/jsx-runtime"),mn={[fe.info]:"#3B82F6",[fe.success]:"#22C55E",[fe.error]:"#EF4444"},Do=-120,kt=R.Platform.OS==="android",No=({type:e})=>e===fe.success?(0,j.jsx)(R.View,{style:ee.check_mark}):e===fe.error?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(R.View,{style:[ee.cross_bar,ee.cross_a]}),(0,j.jsx)(R.View,{style:[ee.cross_bar,ee.cross_b]})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(R.View,{style:ee.info_dot}),(0,j.jsx)(R.View,{style:ee.info_bar})]}),Uo=()=>{let e=W(rt,y=>y.message),t=W(rt,y=>y.type),n=W(rt,y=>y.tick),o=(0,we.useRef)(new R.Animated.Value(Do)).current,r=(0,we.useRef)(new R.Animated.Value(0)).current,i=(0,we.useRef)(new R.Animated.Value(.92)).current,a=(0,we.useRef)(new R.Animated.Value(0)).current,[c,l]=(0,we.useState)(),[s,g]=(0,we.useState)(!1);(0,we.useEffect)(()=>{let y=!0;return Zt().then(u=>{y&&u&&l(()=>u)}),()=>{y=!1}},[]);let d=(0,we.useRef)(n);return(0,we.useEffect)(()=>{if(n===d.current)return;R.AccessibilityInfo.announceForAccessibility(e),g(!0),a.setValue(0),i.setValue(.92);let y=R.Animated.sequence([R.Animated.parallel([R.Animated.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),R.Animated.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),R.Animated.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),R.Animated.sequence([R.Animated.delay(90),R.Animated.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),R.Animated.delay(Hn[t]),R.Animated.parallel([R.Animated.timing(o,{toValue:Do,duration:240,useNativeDriver:!0}),R.Animated.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return y.start(({finished:u})=>{u&&g(!1)}),()=>y.stop()},[n]),s?(0,j.jsx)(R.View,{style:[ee.layer,{top:xt().top+(kt?12:8)}],pointerEvents:"none",children:(0,j.jsxs)(R.Animated.View,{style:[ee.toast,kt&&ee.toast_android,!!c&&ee.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&(0,j.jsx)(c,{style:ee.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),kt?(0,j.jsx)(R.Animated.View,{style:[ee.badge_halo,{backgroundColor:`${mn[t]}33`,transform:[{scale:a}]}],children:(0,j.jsx)(R.View,{style:[ee.badge,{backgroundColor:mn[t]}],children:(0,j.jsx)(No,{type:t})})}):(0,j.jsx)(R.Animated.View,{style:[ee.badge,{backgroundColor:mn[t],transform:[{scale:a}]}],children:(0,j.jsx)(No,{type:t})}),(0,j.jsx)(R.Text,{style:[ee.message,kt&&ee.message_android],numberOfLines:2,children:e})]})}):null},ee=R.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:R.StyleSheet.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ue=Ie({active_key:null,instances:{}}),Vo=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=q().keep_alive)==null?void 0:c.max_webviews;ue.setState(l=>{let s=t!=null?t:e.app_id,g={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},d=Object.keys(g);return a&&a>0&&d.length>a&&d.filter(y=>y!==s).sort((y,u)=>g[y].last_used_at-g[u].last_used_at).slice(0,d.length-a).forEach(y=>{delete g[y]}),i?{active_key:s,instances:g}:{instances:g}})},Bo=e=>Vo(e,!0),qo=e=>Vo(e,!1),Ke=()=>ue.setState({active_key:null}),It=e=>{ue.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var $o="catalog",ei="paused_apps",ti="removed_apps",ni=10*1e3,oi=2,ri=3e3,ii=()=>{var e;try{return JSON.parse((e=q().storage.getString($o))!=null?e:"{}")}catch{return{}}},D=Ie({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),zo=e=>{var t;return!!((t=q().manual_update)!=null&&t.includes(e))},Dt=new Set,Wo=e=>{let t=new Set,n=()=>q().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=q().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},Se=Wo(ei),Ue=Wo(ti);Mn(()=>{Se.load(),Ue.load();let e=ii(),t={};Object.keys(e).filter(n=>!Ue.has(n)).forEach(n=>{let o=B(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:Se.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),D.setState({catalog:e,downloads:t})});var Nt=e=>W(D,t=>e?t.downloads[e]:void 0),jo=()=>W(D,e=>e.pause_reasons.length>0),Ae=(...e)=>me("queue",...e),X=[],Oe={},C=null,Lt=new Set,We={},fn=new Set,De=e=>{fn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Ho=e=>(fn.add(e),()=>{fn.delete(e)}),Jo=()=>D.getState().downloads,de=(e,t)=>{let n=!!B(e),o=D.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};D.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?De({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&De({type:"progress",app_id:e,progress:i.progress,version:i.version})},Ft=(e,t)=>{var n;(n=We[e])==null||n.forEach(o=>o(t)),delete We[e]},si=()=>D.getState().pause_reasons.length>0,Ne=e=>{var c;if(C)return;let t=e?X.indexOf(e):si()?-1:X.findIndex(l=>!Se.has(l));if(t<0||t>=X.length)return;let[n]=X.splice(t,1),o=D.getState().catalog[n];if(!o){Ft(n,B(n)),Ne();return}let r=Date.now();Oe[n]=((c=Oe[n])!=null?c:0)+1,de(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=un(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,de(n,{progress:s/100,version:o.version}))}});C={app_id:n,handle:a,forced:!!e},Ae("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{Ae("installed",n,o.version,`${Date.now()-r}ms`),de(n,{status:"installed",progress:1,version:o.version}),Ft(n,l)}).catch(l=>{var g;if(l instanceof Je){if(Lt.has(n))return;Ae("paused",n),Oe[n]-=1,X.unshift(n),de(n,{status:Se.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((g=l==null?void 0:l.message)!=null?g:l);if(console.warn("[miniapp-queue] failed",n,s),Oe[n]<oi){de(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var d;X.includes(n)||(C==null?void 0:C.app_id)===n||(X.push(n),Ne((d=We[n])!=null&&d.length?n:void 0))},ri);return}de(n,{status:"failed",progress:0,version:o.version,error:s}),Ft(n,B(n))}).finally(()=>{C=null;let l=X.find(s=>{var g;return(g=We[s])==null?void 0:g.length});Ne(l)})},Ut=(e,{front:t=!1}={})=>{if((C==null?void 0:C.app_id)===e)return;let n=X.indexOf(e);if(n>=0){if(!t)return;X.splice(n,1)}t?X.unshift(e):X.push(e)},ai=async e=>{let{host_id:t,client_token:n}=q(),o=new AbortController,r=setTimeout(()=>o.abort(),ni);try{let i=`${yt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},dt=null,Vt=()=>(dt!=null||(dt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(q().channels.map(ai)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(D.getState().catalog).filter(l=>!o[l]);q().storage.setString($o,JSON.stringify(o)),D.setState({catalog:o}),await Promise.all(r.map(l=>Go(l,{by_user:!1}))),r.forEach(l=>Ue.delete(l));let i=Object.keys(o).filter(l=>!Ue.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await pn(l)){de(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=B(l.app_id);if(zo(l.app_id)&&!Dt.has(l.app_id)&&s&&await Ce(s)){de(l.app_id,{status:"installed",progress:1,version:s.version}),c[l.app_id]={app_id:l.app_id,current_version:s.version,next_version:l.version};continue}a.push(l)}return D.setState({updates:c}),a.forEach(l=>{Oe[l.app_id]=0,de(l.app_id,{status:Se.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Ut(l.app_id)}),Ae("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),De({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>De({type:"update_available",...l})),Ne(),{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),De({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{dt=null}})()),dt),Go=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ue.add(e),Lt.has(e))return;Lt.add(e),Se.delete(e);let n=X.indexOf(e);n>=0&&X.splice(n,1),(C==null?void 0:C.app_id)===e&&C.handle.cancel();let o=(c=(a=(r=D.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=B(e))==null?void 0:i.version)!=null?c:"";de(e,{status:"uninstalling",progress:0,version:o}),await Ro(e),It(e),D.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Oe[e],Lt.delete(e),Ft(e,null),Ae("uninstalled",e,t?"(user)":"(not in list)"),De({type:"uninstalled",app_id:e})},Ko=e=>Go(e,{by_user:!0}),Yo=e=>{let t=Ye(e);return t?(Ue.delete(e),(C==null?void 0:C.app_id)===e||X.includes(e)||(Oe[e]=0,de(e,{status:Se.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Ut(e),Ne(),Ae("restore",e)),!0):!1},Xo=e=>{if(Se.has(e))return;if(Se.add(e),Ae("pause app",e),(C==null?void 0:C.app_id)===e&&!C.forced){C.handle.cancel();return}let t=D.getState().downloads[e];X.includes(e)&&t&&de(e,{status:"paused",progress:0,version:t.version})},Zo=e=>{if(!Se.delete(e))return;Ae("resume app",e);let t=D.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!X.includes(e)&&Ye(e)&&(Oe[e]=0,Ut(e)),X.includes(e)&&t&&de(e,{status:"queued",progress:0,version:t.version}),Ne()},Qo=e=>{let{pause_reasons:t}=D.getState();t.includes(e)||(D.setState({pause_reasons:[...t,e]}),Ae("pause",e),t.length===0&&De({type:"pause_change",paused:!0,reasons:[e]}),C&&!C.forced&&C.handle.cancel())},er=e=>{let{pause_reasons:t}=D.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);D.setState({pause_reasons:n}),Ae("resume",e),n.length===0&&De({type:"pause_change",paused:!1,reasons:n}),Ne()},hn=e=>D.getState().updates[e],tr=async e=>{var n,o;let t=hn(e);Dt.add(e);try{let r=await gt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=Ye(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(D.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),Ae("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Dt.delete(e)}},nr=()=>Object.values(D.getState().catalog).map(e=>({...e,installed:!!B(e.app_id),removed_by_user:Ue.has(e.app_id)})),Ye=e=>D.getState().catalog[e],gt=async e=>{let t=Ye(e);if(!t)return;if(Se.delete(e),Ue.delete(e),await pn(t))return B(e);let n=B(e);if(zo(e)&&!Dt.has(e)&&n&&await Ce(n))return n;let o=new Promise(r=>{var i;((i=We[e])!=null?i:We[e]=[]).push(r)});return(C==null?void 0:C.app_id)===e?C.forced=!0:(Oe[e]=0,Ut(e,{front:!0}),C&&!C.forced?C.handle.cancel():Ne(e)),o};var k=require("react/jsx-runtime"),yn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),or=0,ci=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},li=A.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:g})=>{var mt,ft;let d=(0,A.useRef)(null),y=(0,A.useRef)(!1),u=W(ue,f=>f.instances[e]),w=u==null?void 0:u.app.app_id,I=u==null?void 0:u.app.manifest_url,T=u==null?void 0:u.context,E=u==null?void 0:u.url_params,M=W(Y,f=>{var _;return((_=f.active)==null?void 0:_.owner)===e?f.active:null}),[N,$]=(0,A.useState)(null),[te,Te]=(0,A.useState)(M);M!==te&&(Te(M),M?$(null):(te==null?void 0:te.layout)===pe.top&&$(te));let ae=(M==null?void 0:M.layout)===pe.top?M:N,[p,x]=(0,A.useState)(()=>w?B(w):null),[ne,P]=(0,A.useState)(!1),[ce,_e]=(0,A.useState)(0),[G,O]=(0,A.useState)(0),[oe,H]=(0,A.useState)(!1),Z=(0,A.useRef)(null),re=f=>{Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{Z.current=null,H(!0)},f)};(0,A.useEffect)(()=>()=>{Z.current&&clearTimeout(Z.current)},[]),(0,A.useEffect)(()=>{if(!w||!t&&p)return;let f=!0;return P(!1),(async()=>{let _=B(w),b=_?await Ce(_):!1;if(!f||(x(b?se=>!se||se.version!==_.version||se.permissions.join(",")!==_.permissions.join(",")?_:se:null),__DEV__&&Date.now()-or>1e4&&(or=Date.now(),await Vt()),!f))return;let U=await gt(w),ie=U!==void 0?U:I?await Co(w,I):B(w);if(f){if(!ie){P(!0);return}x(se=>se!=null?se:ie)}})(),()=>{f=!1}},[t,w,I,ce]),(0,A.useEffect)(()=>Oo(e,f=>d.current?(d.current.postMessage(f),!0):!1),[e]);let ve=W(D,f=>{let _=w?f.downloads[w]:void 0;return(_==null?void 0:_.status)==="installed"?_.version:void 0});(0,A.useEffect)(()=>{if(t||!w||!p)return;let f=B(w);if(!f||f.version===p.version)return;let _=!0;return Ce(f).then(b=>{!_||!b||(me(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",p.version,"\u2192",f.version),x(f))}),()=>{_=!1}},[t,w,ve,p==null?void 0:p.version]);let Me=W(D,f=>{var _;return w&&(_=f.apply_ticks[w])!=null?_:0});(0,A.useEffect)(()=>{if(!Me||!w)return;let f=B(w);if(!f||f.version===(p==null?void 0:p.version))return;let _=!0;return Ce(f).then(b=>{!_||!b||(me(`webview:${e}`,"c\u1EADp nh\u1EADt",p==null?void 0:p.version,"\u2192",f.version),H(!1),x(f))}),()=>{_=!1}},[Me]),(0,A.useEffect)(()=>{var b;let f=(b=q().keep_alive)==null?void 0:b.idle_close_ms;if(t||!f||f<=0)return;let _=setTimeout(()=>{It(e)},f);return()=>clearTimeout(_)},[t,e]),(0,A.useEffect)(()=>{r>0&&(P(!1),H(!1),O(f=>f+1),_e(f=>f+1))},[r]);let je=(0,A.useRef)(t);(0,A.useEffect)(()=>{var f;je.current!==t&&(je.current=t,y.current&&((f=d.current)==null||f.injectJavaScript(yo(t?"resumed":"paused"))))},[t]);let xe=`${(mt=p==null?void 0:p.version)!=null?mt:"none"}:${(ft=p==null?void 0:p.permissions.join(","))!=null?ft:""}:${G}`,Pe=(0,A.useMemo)(()=>JSON.stringify([T!=null?T:{},E!=null?E:{}]),[T,E]),Xe=(0,A.useMemo)(()=>{var f;return So(E!=null?E:{},(f=p==null?void 0:p.permissions)!=null?f:[])},[Pe,p==null?void 0:p.permissions]),Bt=(0,A.useMemo)(()=>_o(T!=null?T:{},Xe)+fo()+ho()+(q().debug?mo():""),[Xe]),Ve=(0,A.useRef)(null),Ze=(0,A.useRef)(null);(0,A.useEffect)(()=>{var _,b,U;if(!p)return;if(Ze.current!==xe){Ze.current=xe,Ve.current=Pe;return}if(Ve.current===Pe)return;let f=((b=JSON.parse((_=Ve.current)!=null?_:"[]")[0])!=null?b:{}).org_id;if(Ve.current=Pe,f===(T==null?void 0:T.org_id)&&y.current){H(!1),re(1500),(U=d.current)==null||U.injectJavaScript(wo(T!=null?T:{},Xe));return}H(!1),O(ie=>ie+1)},[Pe,p,xe]),(0,A.useEffect)(()=>(t||(Re(e),Fe(e),qe(e)),()=>{Re(e),Fe(e),qe(e)}),[t,e,xe,r]),(0,A.useEffect)(()=>{let f=L.AppState.addEventListener("change",_=>{_==="background"&&!Kn()&&Re(e),_==="background"&&!to()&&Fe(e)});return()=>f.remove()},[e]);let Qe=(0,A.useCallback)(async f=>{var b,U,ie,se,$t,bn;let _=lo(f.nativeEvent.data);if(!_){if(w&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(f.nativeEvent.data,{app_id:w,instance_id:e})).catch(z=>{console.warn("[miniapp] onWebEvent l\u1ED7i",w,z)})}catch(z){console.warn("[miniapp] onWebEvent l\u1ED7i",w,z)}return}if(_.method==="log"){let{level:z,text:J}=_;me(`web:${e}`,z!=null?z:"log",J!=null?J:"");return}if(_.method==="pong"){Z.current||H(!0);return}if(_.method==="touchAtTop"){i.emit(!!_.at_top);return}if(_.method==="contextApplied"){Z.current&&clearTimeout(Z.current),Z.current=null,H(!0);return}if(_.method==="ready"){y.current=!0,H(!0);let z=(b=ue.getState().instances[e])==null?void 0:b.context;z&&((U=d.current)==null||U.injectJavaScript(nn(z)));return}try{let z=await Mo(_,{getHostData:()=>{var J,ge;return(ge=(J=ue.getState().instances[e])==null?void 0:J.host_data)!=null?ge:{}},getPermissions:()=>{var J,ge;return w?(ge=(J=B(w))==null?void 0:J.permissions)!=null?ge:[]:[]},getContext:()=>{var J,ge;return(ge=(J=ue.getState().instances[e])==null?void 0:J.context)!=null?ge:{}},is_dark:o,close:Ke,app_id:w!=null?w:"",instance_id:e,options:c,emit:(J,ge)=>{var _n;(_n=d.current)==null||_n.injectJavaScript(go(J,ge))},playBeep:(ie=c==null?void 0:c.playScannerBeep)!=null?ie:(()=>{var J;(J=d.current)==null||J.injectJavaScript(vo())}),isActive:()=>ue.getState().active_key===e&&L.AppState.currentState!=="background"});_.id&&((se=d.current)==null||se.injectJavaScript(po(_.id,z)))}catch(z){if(!_.id)return;let J=z==null?void 0:z.code,ge=z instanceof m?z:new m(typeof J=="string"?J:"HOST_ERROR",String(($t=z==null?void 0:z.message)!=null?$t:z));(bn=d.current)==null||bn.injectJavaScript(uo(_.id,ge))}},[e,o,w,i,c]),qt=(0,A.useCallback)(()=>{P(!1),O(f=>f+1),_e(f=>f+1)},[]);return(0,k.jsxs)(L.View,{style:[L.StyleSheet.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&be.behind],pointerEvents:t?"auto":"none",children:[ae&&(0,k.jsx)(gn,{scanner:ae,closing:ae===N,onClosed:()=>{var f;$(null),ae.absolute&&((f=d.current)==null||f.injectJavaScript(on(0)))},onHeight:ae.absolute?f=>{var _;return(_=d.current)==null?void 0:_.injectJavaScript(on(f))}:void 0}),p?(0,k.jsx)(ir.default,{ref:d,source:{uri:p.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?an():p.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:Bt,onMessage:Qe,bounces:!1,overScrollMode:"never",onLoadStart:f=>{Re(e),Fe(e),qe(e),me(`webview:${e}`,"load start",yn(f.nativeEvent.url)),y.current=!1,H(!1)},onError:f=>{Re(e),Fe(e),qe(e),me(`webview:${e}`,"load error",yn(f.nativeEvent.url),f.nativeEvent.description),P(!0),H(!1)},onLoadEnd:f=>{let _=f.nativeEvent.url;me(`webview:${e}`,"load end",yn(_)),w&&(g==null||g({app_id:w,instance_id:e,url:_})),re(1500)},onContentProcessDidTerminate:()=>{Re(e),Fe(e),qe(e),y.current=!1,H(!1),O(f=>f+1)},onRenderProcessGone:()=>(Re(e),Fe(e),qe(e),y.current=!1,H(!1),O(f=>f+1),!0),style:be.webview},xe):null,(M==null?void 0:M.layout)===pe.full&&(0,k.jsx)(gn,{scanner:M}),u&&(0,k.jsx)(ui,{visible:!p||!oe,interactive:ne,children:(0,k.jsx)(pi,{splash:a,app:u.app,is_dark:o,error:ne,has_bundle:!!p,retry:qt})})]})}),pi=A.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=Nt(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return(0,k.jsx)(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),ui=({visible:e,interactive:t,children:n})=>{let o=(0,A.useRef)(new L.Animated.Value(e?1:0)).current,[r,i]=(0,A.useState)(e);return(0,A.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=L.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?(0,k.jsx)(L.Animated.View,{style:[L.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},wn=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,k.jsxs)(L.View,{style:[be.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,k.jsx)(L.View,{style:[be.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,k.jsx)(L.Image,{source:{uri:e.icon},style:be.splash_icon_image}):(0,k.jsx)(L.Text,{style:be.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,k.jsx)(L.Text,{style:[be.splash_name,{color:i}],children:e.name}),n==="error"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(L.Text,{style:be.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,k.jsx)(L.TouchableOpacity,{activeOpacity:.7,style:[be.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,k.jsx)(L.Text,{style:[be.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(L.ActivityIndicator,{style:be.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,k.jsxs)(L.Text,{style:be.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},rr=(e,t)=>{let n=(0,A.useRef)(t),o=(0,A.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.`))},di=({container:e,splash:t=wn,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{rr("container",e),rr("splash",t);let l=e,s=W(ue,M=>M.active_key),g=(0,A.useRef)(s);s&&(g.current=s);let d=W(ue,M=>Object.keys(M.instances).join("|")),y=W(ue,M=>{var N;return M.active_key?(N=M.instances[M.active_key])==null?void 0:N.app.name:void 0}),u=(0,A.useMemo)(()=>d?d.split("|"):[],[d]),[w,I]=(0,A.useState)({}),T=(0,A.useRef)(ci()).current;(0,A.useEffect)(()=>{if(!s||!r)return;let M=L.BackHandler.addEventListener("hardwareBackPress",()=>(Ke(),!0));return()=>M.remove()},[s,r]);let E=(0,A.useCallback)(()=>{let M=ue.getState().active_key;M&&I(N=>({...N,[M]:(N[M]||0)+1}))},[]);return u.length?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(l,{visible:!!s,title:y!=null?y:"",is_dark:n,close:Ke,reload:E,subscribeWebAtTop:T.subscribe,children:u.map(M=>(0,k.jsx)(li,{instance_key:M,is_active:s===M,is_front:(s!=null?s:g.current)===M,is_dark:n,reload_tick:w[M]||0,web_at_top:T,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},M))}),(0,k.jsx)(Uo,{})]}):null},be=L.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"}}),sr=A.default.memo(di);0&&(module.exports={CodeType,DefaultMiniAppSplash,MINIAPP_PLATFORM_URL,MiniAppHost,MiniAppHostError,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,ToastType,closeMiniApp,configureMiniApp,createMmkvStorage,createReactNativeBiometrics,createRnfsFileSystem,ensureMiniApp,getLocalMiniApp,getMiniAppCatalog,getMiniAppCatalogEntry,getMiniAppStatuses,getMiniAppUpdate,installBundledMiniApp,onMiniAppEvent,openMiniApp,pauseMiniApp,pauseMiniAppDownloads,preloadMiniApp,releaseSpeechFor,restoreMiniApp,resumeMiniApp,resumeMiniAppDownloads,sendEventToWeb,syncMiniAppCatalog,uninstallMiniApp,updateMiniApp,uploadToUrl,useMiniAppDownload,useMiniAppDownloadsPaused});
88
+ })(); true;`,zr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Pt=(e,t)=>{if(typeof e!="string"||!e)throw new m("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},Ro=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:g,isActive:d,playBeep:y})=>{var E,M,N,z,ne,Pe,ae;let u=s==null?void 0:s.handlers,w={app_id:c,instance_id:l,close:a},I=()=>{var p;(p=s==null?void 0:s.haptic)==null||p.call(s,"impactLight"),y==null||y()},P=()=>new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let p=Pn(t);return it(e,()=>Tn(p,d))}case"speech.start":{if(!g)throw P();let p={};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 m("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");p.lang=t.lang}for(let q of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[q])!==void 0){if(typeof t[q]!="boolean")throw new m("INVALID_PARAMS",`${q} ph\u1EA3i l\xE0 boolean`);p[q]=t[q]}let x=s==null?void 0:s.speech;if(x){Yn(l,x);try{return await x.start({owner:l,app_id:c,options:p,emit:g,isActive:d!=null?d:(()=>!0)})}catch(q){throw Xn(l),q}}return Qn(l,p,g,d)}case"speech.stop":return s!=null&&s.speech?s.speech.stop(l):eo(l);case He.scan:return ao(l,Xt(t),d,I);case He.start:{if(!g)throw P();return co(l,Xt(t),g,d,I)}case He.stop:return lo(l);case"uploadFiles":{let{task_id:p,...x}=t!=null?t:{};if(p!==void 0&&(typeof p!="string"||!p))throw new m("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return Hn(Nn(x),{instance_id:l,app_id:c,getContext:r,task_id:p,config:s==null?void 0:s.upload,emit:g,exclusivePick:q=>it("uploadFiles.pick",q)})}case"uploadFiles.cancel":jn(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return zn(s==null?void 0:s.upload);case"getBiometricAvailability":return((E=s==null?void 0:s.biometrics)!=null?E:await jt()).getAvailability();case"authenticateBiometric":{let p=Pt(t==null?void 0:t.reason,"reason").trim();if(!p||p.length>200)throw new m("INVALID_PARAMS","reason must contain 1\u2013200 characters");let x=t==null?void 0:t.cancelButtonText;if(x!==void 0&&(typeof x!="string"||!x.trim()||x.length>80))throw new m("INVALID_PARAMS","Invalid cancelButtonText");return it(e,async()=>{var T;return((T=s==null?void 0:s.biometrics)!=null?T:await jt()).authenticate({reason:p,cancelButtonText:x})})}case"requestPayment":{let p=u==null?void 0:u.requestPayment;if(!p)throw P();let x=t==null?void 0:t.amount;if(typeof x!="number"||!Number.isFinite(x)||x<=0)throw new m("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let q={...t,amount:x,currency:Pt(t==null?void 0:t.currency,"currency")};return it(e,()=>p(q,w))}case"printImage":{let p=u==null?void 0:u.printImage;if(!p)throw P();let x=Pt(t==null?void 0:t.image,"image");await it(e,()=>p({image:x},w));return}case"openScreen":if(!(u!=null&&u.openScreen))throw P();await u.openScreen({screen:Pt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},w);return;case"closeApp":a();return;case"openWebview":{let p=String((M=t==null?void 0:t.url)!=null?M:"");if(!/^https?:\/\//i.test(p))throw new m("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(p):st.Linking.openURL(p));return}case"openLink":{let p=String((N=t==null?void 0:t.url)!=null?N:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(p)||/^(javascript|file|data|about|blob):/i.test(p))throw new m("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(p):st.Linking.openURL(p))}catch(x){throw new m("NOT_SUPPORTED",String((ne=(z=x==null?void 0:x.message)!=null?z:x)!=null?ne:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let p=Gn(t);if(!p||(d==null?void 0:d())===!1)return;s!=null&&s.showToast?s.showToast(p.message,{type:p.type}):Kn(p.message,p.type);return}case"haptic":{let p=zr.has(t==null?void 0:t.type)?t.type:"selection";(Pe=s==null?void 0:s.haptic)==null||Pe.call(s,p);return}case"getSystemInfo":return{platform:st.Platform.OS==="ios"?"ios":"android",appVersion:(ae=s==null?void 0:s.app_version)!=null?ae:"",theme:i?"dark":"light"};case"getAccessToken":{let p=n().access_token;if(!p)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return p}case"getToken":{let p=t==null?void 0:t.type;if(p==="access"){let T=n().access_token;if(!T)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return T}if(p!=="partner"&&p!=="chatbox")throw new m("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(p)}`);let x=Mo[p];if(!o().includes(x))throw new m("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${x} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let q=p==="partner"?n().partner_token:n().chatbox_token;if(!q)throw new m("HOST_ERROR",`Kh\xF4ng c\xF3 ${x}`);return q}case"getUserInfo":{let p=n().user;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return p}case"getPageInfo":{let p=n().page;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return p}case"sendMessage":case"insertText":throw new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new m("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var an=e=>`bundle:${e}`,cn=()=>`${$().file_system.document_dir}/miniapps`,ln=cn,pn=(e,t,n="index.html",o=!1,r=[])=>{let i=`${ln()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},sn=e=>{var t;$().storage.setString(an(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Wr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,B=e=>{let t=$().storage.getString(an(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return pn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Ce=e=>$().file_system.exists(e.entry_uri.replace("file://","")),un=async e=>{let t=B(e.app_id);return(t==null?void 0:t.version)===e.version&&await Ce(t)},To=async(e,t)=>{let n=$().file_system,o=`${ln()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Co=async e=>{var t;await((t=lt[e])==null?void 0:t.catch(()=>{})),$().storage.setString(an(e),""),await $().file_system.remove(`${ln()}/${e}`).catch(()=>{})},Je=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},lt={},Oo=(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},jr=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let c=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(c)return c}return 0},ko=({manifest:e,zip_path:t})=>Oo(e.app_id,async()=>{var i;let n=$().file_system,o=B(e.app_id);if(o&&jr(o.version,e.version)>=0&&await Ce(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=pn(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),sn(e),me("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),To(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),dn=(e,{base_url:t,onProgress:n}={})=>{let o=$().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new Je},l=async()=>{var d;c();let s=B(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return sn(e),B(e.app_id);c();let g=o.download({url:t?Wr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,u)=>{var I;let w=u>0?u:(I=e.size)!=null?I:0;w>0&&(n==null||n(Math.min(1,y/w)))}});r=g;try{let{status:y}=await g.promise;if(c(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else me("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let u=pn(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(a,u.dir),sn(e),To(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),u}catch(y){throw i?new Je:y}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:Oo(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},ct={},Hr=__DEV__?0:60*1e3,Po={},Io=(e,t)=>{var o,r;let n=B(e);return n&&Date.now()-((o=Po[t])!=null?o:0)<Hr?Promise.resolve(n):((r=ct[e])!=null||(ct[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),c=await dn(a,{base_url:t}).promise;return Po[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),B(e))).finally(()=>{ct[e]=void 0})),ct[e])};var Ct=new Map,Lo=(e,t)=>(Ct.set(e,t),()=>{Ct.get(e)===t&&Ct.delete(e)}),Fo=(e,t)=>{let n=Ct.get(e);return n?n(t):!1};var F=require("react"),h=require("react-native");var v=require("react/jsx-runtime"),pt="#22C55E",Jr="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",Gr=2,kt=18,Kr=1600,ut=14,Yr=2e3,Uo=.38,Xr=40,Do=2,Zr=8,Qr=2e3,ei=250,Ge=2e3,ti=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:ut},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:ut},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:ut},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:ut}],No=({color:e})=>(0,v.jsx)(v.Fragment,{children:ti.map((t,n)=>(0,v.jsx)(h.View,{style:[S.corner,t,{borderColor:e}]},n))}),Ot=({style:e,children:t,...n})=>{let o=(0,F.useRef)(new h.Animated.Value(1)).current,r=i=>h.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,v.jsx)(h.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,v.jsx)(h.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},mn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var f,_;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:g}=e,d=c===pe.top,y=(0,F.useRef)(new h.Animated.Value(0)).current,u=r.useCameraDevice("back"),w=(0,F.useRef)(new h.Animated.Value(1)).current,[I,P]=(0,F.useState)(!1),[E,M]=(0,F.useState)(1),N=(0,F.useRef)(null),[z,ne]=(0,F.useState)(()=>{let{width:b,height:U}=h.Dimensions.get("window");return{width:b,height:d?U*Uo:U,window_y:0}}),Pe=j(X,b=>b.last_value),ae=j(X,b=>b.hit_tick),p=j(X,b=>b.scan_count),x=j(X,b=>b.notice),q=j(X,b=>b.is_picking),T=(0,F.useRef)(null),ce=Et(),_e=ce.top,K=(0,F.useRef)(new h.Animated.Value(0)).current,O=(0,F.useRef)(new h.Animated.Value(0)).current,oe=(0,F.useRef)(new h.Animated.Value(0)).current,J=(0,F.useRef)(n);J.current=n,(0,F.useEffect)(()=>{if(!t)return;y.setValue(z.height);let b=h.Animated.timing(y,{toValue:0,duration:ei,easing:h.Easing.out(h.Easing.cubic),useNativeDriver:!1});return b.start(({finished:U})=>{var ie;U&&((ie=J.current)==null||ie.call(J))}),()=>b.stop()},[t,y]);let Q=Math.round(z.width*(d?.8:.78)),re=Math.round(d?z.height*.46:Q*.78),ve=Math.round((z.height-re)/2),Me=Math.round((z.width-Q)/2),je=r.useCodeScanner({codeTypes:i,onCodeScanned:(0,F.useCallback)(b=>tn(b),[])});(0,F.useEffect)(()=>{let b=h.BackHandler.addEventListener("hardwareBackPress",()=>(en(),!0));return()=>b.remove()},[]);let xe=(0,F.useRef)(ae);(0,F.useEffect)(()=>{if(ae===xe.current)return;K.setValue(1),oe.setValue(1);let b=h.Animated.parallel([h.Animated.timing(K,{toValue:0,duration:450,useNativeDriver:!0}),h.Animated.sequence([h.Animated.delay(Yr),h.Animated.timing(oe,{toValue:0,duration:250,useNativeDriver:!0})])]);return b.start(),()=>b.stop()},[ae,K,oe]),(0,F.useEffect)(()=>{let b=ie=>h.Animated.timing(O,{toValue:ie,duration:Kr,easing:h.Easing.inOut(h.Easing.quad),useNativeDriver:!0}),U=h.Animated.loop(h.Animated.sequence([b(1),b(0)]));return U.start(),()=>U.stop()},[O]);let Te=(0,F.useCallback)(()=>{h.Animated.timing(w,{toValue:0,duration:220,useNativeDriver:!0}).start()},[w]);(0,F.useEffect)(()=>{let b=setTimeout(Te,Qr);return()=>clearTimeout(b)},[Te]);let[Xe,qt]=(0,F.useState)(!1);(0,F.useEffect)(()=>{let b=requestAnimationFrame(()=>{b=requestAnimationFrame(()=>qt(!0))});return()=>cancelAnimationFrame(b)},[]);let Ve=!!(u!=null&&u.hasTorch),Ze=(f=u==null?void 0:u.neutralZoom)!=null?f:1,Qe=u?Math.min(u.maxZoom/Ze,Zr):1,$t=Ze*Math.min(E,Qe),mt=b=>{var se;let{touches:U}=b.nativeEvent;if(U.length!==2){N.current=null;return}let ie=Math.hypot(U[0].pageX-U[1].pageX,U[0].pageY-U[1].pageY);(se=N.current)!=null||(N.current={distance:ie,level:E}),M(Math.max(1,Math.min(Qe,N.current.level*(ie/N.current.distance))))},ft=(0,v.jsx)(h.Text,{style:[S.hint,!!x&&S.hint_notice],numberOfLines:1,children:(_=x!=null?x:l)!=null?_:Jr});return(0,v.jsx)(h.Animated.View,{ref:T,onTouchMove:mt,onTouchEnd:()=>{N.current=null},pointerEvents:t?"none":"auto",style:d?[S.top,g&&S.top_absolute,t&&{height:y}]:S.full,onLayout:({nativeEvent:{layout:b}})=>{var U;t||(o==null||o(b.height),(U=T.current)==null||U.measureInWindow((ie,se)=>{ne({width:b.width,height:b.height,window_y:se||0})}))},children:(0,v.jsxs)(h.View,{style:t?[S.content_closing,{height:z.height}]:S.content,children:[u&&Xe&&(0,v.jsx)(r.Camera,{style:h.StyleSheet.absoluteFill,device:u,isActive:!q,codeScanner:je,torch:I&&Ve?"on":"off",zoom:$t,onPreviewStarted:Te,onError:b=>po(b.message)}),(0,v.jsx)(h.Animated.View,{style:[S.preview_cover,{opacity:w}],pointerEvents:"none"}),z.height>0&&(0,v.jsxs)(h.View,{style:S.overlay,pointerEvents:"none",children:[(0,v.jsx)(h.View,{style:[S.dim_ring,{top:ve-Ge,left:Me-Ge,width:Q+Ge*2,height:re+Ge*2}]}),(0,v.jsxs)(h.View,{style:{position:"absolute",top:ve,left:Me,width:Q,height:re},children:[(0,v.jsx)(No,{color:"#FFFFFF"}),(0,v.jsx)(h.Animated.View,{style:[h.StyleSheet.absoluteFill,{opacity:K}],children:(0,v.jsx)(No,{color:pt})}),(0,v.jsxs)(h.Animated.View,{style:[S.scan_line_wrap,{transform:[{translateY:O.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,re-kt)]})}]}],children:[(0,v.jsx)(h.View,{style:S.scan_glow_outer}),(0,v.jsx)(h.View,{style:S.scan_glow_inner}),(0,v.jsx)(h.View,{style:S.scan_line})]})]}),(0,v.jsx)(h.View,{style:[S.hint_slot,d?{top:0,height:ve-6,justifyContent:"flex-end"}:{top:ve+re+20}],children:ft}),a===Le.continuous&&!!Pe&&(0,v.jsx)(h.Animated.View,{style:[S.result_slot,{top:d?ve+re-Xr:ve+re+52},{opacity:oe}],children:(0,v.jsxs)(h.View,{style:S.result,children:[(0,v.jsx)(h.View,{style:S.check_badge,children:(0,v.jsx)(h.View,{style:S.check_mark})}),(0,v.jsx)(h.Text,{style:S.result_text,numberOfLines:1,children:Pe}),(0,v.jsxs)(h.Text,{style:S.result_count,children:["\xB7 ",p," m\xE3"]})]})})]}),z.height>0&&(0,v.jsx)(h.View,{style:[S.close_slot,d?S.close_slot_top:{top:Math.max(12,_e-z.window_y+12)}],children:(0,v.jsxs)(Ot,{style:[S.close_button,!!s&&S.glass_surface],onPress:en,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&(0,v.jsx)(s,{style:S.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(h.View,{style:[S.close_bar,S.close_bar_a]}),(0,v.jsx)(h.View,{style:[S.close_bar,S.close_bar_b]})]})}),(0,v.jsx)(h.View,{style:[S.toolbar_wrap,!d&&{bottom:ce.bottom+20}],pointerEvents:"box-none",children:(0,v.jsxs)(h.View,{style:[S.toolbar,!!s&&S.glass_surface],children:[s&&(0,v.jsx)(s,{style:S.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(Ot,{style:S.tool,onPress:uo,disabled:q,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,v.jsxs)(h.View,{style:S.image_icon,children:[(0,v.jsx)(h.View,{style:S.image_icon_dot}),(0,v.jsx)(h.View,{style:S.image_icon_hill})]})}),!!u&&Qe>=Do&&(0,v.jsx)(Ot,{style:[S.tool,E>1&&S.tool_on],onPress:()=>M(b=>b>1?1:Do),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,v.jsxs)(h.Text,{style:[S.zoom_text,E>1&&S.zoom_text_on],children:[Math.round(E*10)/10,"x"]})}),Ve&&(0,v.jsx)(Ot,{style:[S.tool,I&&S.tool_on],onPress:()=>P(b=>!b),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:I},children:(0,v.jsx)(h.Text,{style:[S.torch_icon,I&&S.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},ni="rgba(0,0,0,0.5)",gn=50,S=h.StyleSheet.create({top:{height:`${Uo*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:Ge,borderColor:ni,borderRadius:Ge+ut},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:kt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:kt,borderRadius:kt/2,backgroundColor:pt,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:pt,opacity:.2},scan_line:{height:Gr,borderRadius:1,backgroundColor:pt},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:gn,height:gn,borderRadius:gn/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:pt},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});var we=require("react"),R=require("react-native");var H=require("react/jsx-runtime"),fn={[fe.info]:"#3B82F6",[fe.success]:"#22C55E",[fe.error]:"#EF4444"},Vo=-120,It=R.Platform.OS==="android",Bo=({type:e})=>e===fe.success?(0,H.jsx)(R.View,{style:te.check_mark}):e===fe.error?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(R.View,{style:[te.cross_bar,te.cross_a]}),(0,H.jsx)(R.View,{style:[te.cross_bar,te.cross_b]})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(R.View,{style:te.info_dot}),(0,H.jsx)(R.View,{style:te.info_bar})]}),qo=()=>{let e=j(rt,y=>y.message),t=j(rt,y=>y.type),n=j(rt,y=>y.tick),o=(0,we.useRef)(new R.Animated.Value(Vo)).current,r=(0,we.useRef)(new R.Animated.Value(0)).current,i=(0,we.useRef)(new R.Animated.Value(.92)).current,a=(0,we.useRef)(new R.Animated.Value(0)).current,[c,l]=(0,we.useState)(),[s,g]=(0,we.useState)(!1);(0,we.useEffect)(()=>{let y=!0;return Qt().then(u=>{y&&u&&l(()=>u)}),()=>{y=!1}},[]);let d=(0,we.useRef)(n);return(0,we.useEffect)(()=>{if(n===d.current)return;R.AccessibilityInfo.announceForAccessibility(e),g(!0),a.setValue(0),i.setValue(.92);let y=R.Animated.sequence([R.Animated.parallel([R.Animated.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),R.Animated.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),R.Animated.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),R.Animated.sequence([R.Animated.delay(90),R.Animated.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),R.Animated.delay(Jn[t]),R.Animated.parallel([R.Animated.timing(o,{toValue:Vo,duration:240,useNativeDriver:!0}),R.Animated.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return y.start(({finished:u})=>{u&&g(!1)}),()=>y.stop()},[n]),s?(0,H.jsx)(R.View,{style:[te.layer,{top:Et().top+(It?12:8)}],pointerEvents:"none",children:(0,H.jsxs)(R.Animated.View,{style:[te.toast,It&&te.toast_android,!!c&&te.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&(0,H.jsx)(c,{style:te.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),It?(0,H.jsx)(R.Animated.View,{style:[te.badge_halo,{backgroundColor:`${fn[t]}33`,transform:[{scale:a}]}],children:(0,H.jsx)(R.View,{style:[te.badge,{backgroundColor:fn[t]}],children:(0,H.jsx)(Bo,{type:t})})}):(0,H.jsx)(R.Animated.View,{style:[te.badge,{backgroundColor:fn[t],transform:[{scale:a}]}],children:(0,H.jsx)(Bo,{type:t})}),(0,H.jsx)(R.Text,{style:[te.message,It&&te.message_android],numberOfLines:2,children:e})]})}):null},te=R.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:R.StyleSheet.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ue=Ie({active_key:null,instances:{}}),$o=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=$().keep_alive)==null?void 0:c.max_webviews;ue.setState(l=>{let s=t!=null?t:e.app_id,g={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},d=Object.keys(g);return a&&a>0&&d.length>a&&d.filter(y=>y!==s).sort((y,u)=>g[y].last_used_at-g[u].last_used_at).slice(0,d.length-a).forEach(y=>{delete g[y]}),i?{active_key:s,instances:g}:{instances:g}})},zo=e=>$o(e,!0),Wo=e=>$o(e,!1),Ke=()=>ue.setState({active_key:null}),Lt=e=>{ue.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var jo="catalog",oi="paused_apps",ri="removed_apps",ii=10*1e3,si=2,ai=3e3,ci=()=>{var e;try{return JSON.parse((e=$().storage.getString(jo))!=null?e:"{}")}catch{return{}}},D=Ie({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),Ho=e=>{var t;return!!((t=$().manual_update)!=null&&t.includes(e))},Nt=new Set,Jo=e=>{let t=new Set,n=()=>$().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=$().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},Se=Jo(oi),Ue=Jo(ri);xn(()=>{Se.load(),Ue.load();let e=ci(),t={};Object.keys(e).filter(n=>!Ue.has(n)).forEach(n=>{let o=B(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:Se.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),D.setState({catalog:e,downloads:t})});var Ut=e=>j(D,t=>e?t.downloads[e]:void 0),Go=()=>j(D,e=>e.pause_reasons.length>0),Ae=(...e)=>me("queue",...e),Z=[],Oe={},C=null,Ft=new Set,We={},hn=new Set,De=e=>{hn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Ko=e=>(hn.add(e),()=>{hn.delete(e)}),Yo=()=>D.getState().downloads,de=(e,t)=>{let n=!!B(e),o=D.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};D.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?De({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&De({type:"progress",app_id:e,progress:i.progress,version:i.version})},Dt=(e,t)=>{var n;(n=We[e])==null||n.forEach(o=>o(t)),delete We[e]},li=()=>D.getState().pause_reasons.length>0,Ne=e=>{var c;if(C)return;let t=e?Z.indexOf(e):li()?-1:Z.findIndex(l=>!Se.has(l));if(t<0||t>=Z.length)return;let[n]=Z.splice(t,1),o=D.getState().catalog[n];if(!o){Dt(n,B(n)),Ne();return}let r=Date.now();Oe[n]=((c=Oe[n])!=null?c:0)+1,de(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=dn(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,de(n,{progress:s/100,version:o.version}))}});C={app_id:n,handle:a,forced:!!e},Ae("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{Ae("installed",n,o.version,`${Date.now()-r}ms`),de(n,{status:"installed",progress:1,version:o.version}),Dt(n,l)}).catch(l=>{var g;if(l instanceof Je){if(Ft.has(n))return;Ae("paused",n),Oe[n]-=1,Z.unshift(n),de(n,{status:Se.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((g=l==null?void 0:l.message)!=null?g:l);if(console.warn("[miniapp-queue] failed",n,s),Oe[n]<si){de(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var d;Z.includes(n)||(C==null?void 0:C.app_id)===n||(Z.push(n),Ne((d=We[n])!=null&&d.length?n:void 0))},ai);return}de(n,{status:"failed",progress:0,version:o.version,error:s}),Dt(n,B(n))}).finally(()=>{C=null;let l=Z.find(s=>{var g;return(g=We[s])==null?void 0:g.length});Ne(l)})},Vt=(e,{front:t=!1}={})=>{if((C==null?void 0:C.app_id)===e)return;let n=Z.indexOf(e);if(n>=0){if(!t)return;Z.splice(n,1)}t?Z.unshift(e):Z.push(e)},pi=async e=>{let{host_id:t,client_token:n}=$(),o=new AbortController,r=setTimeout(()=>o.abort(),ii);try{let i=`${yt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},dt=null,Bt=()=>(dt!=null||(dt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all($().channels.map(pi)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(D.getState().catalog).filter(l=>!o[l]);$().storage.setString(jo,JSON.stringify(o)),D.setState({catalog:o}),await Promise.all(r.map(l=>Xo(l,{by_user:!1}))),r.forEach(l=>Ue.delete(l));let i=Object.keys(o).filter(l=>!Ue.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await un(l)){de(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=B(l.app_id);if(Ho(l.app_id)&&!Nt.has(l.app_id)&&s&&await Ce(s)){de(l.app_id,{status:"installed",progress:1,version:s.version}),c[l.app_id]={app_id:l.app_id,current_version:s.version,next_version:l.version};continue}a.push(l)}return D.setState({updates:c}),a.forEach(l=>{Oe[l.app_id]=0,de(l.app_id,{status:Se.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Vt(l.app_id)}),Ae("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),De({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>De({type:"update_available",...l})),Ne(),{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),De({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{dt=null}})()),dt),Xo=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ue.add(e),Ft.has(e))return;Ft.add(e),Se.delete(e);let n=Z.indexOf(e);n>=0&&Z.splice(n,1),(C==null?void 0:C.app_id)===e&&C.handle.cancel();let o=(c=(a=(r=D.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=B(e))==null?void 0:i.version)!=null?c:"";de(e,{status:"uninstalling",progress:0,version:o}),await Co(e),Lt(e),D.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Oe[e],Ft.delete(e),Dt(e,null),Ae("uninstalled",e,t?"(user)":"(not in list)"),De({type:"uninstalled",app_id:e})},Zo=e=>Xo(e,{by_user:!0}),Qo=e=>{let t=Ye(e);return t?(Ue.delete(e),(C==null?void 0:C.app_id)===e||Z.includes(e)||(Oe[e]=0,de(e,{status:Se.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Vt(e),Ne(),Ae("restore",e)),!0):!1},er=e=>{if(Se.has(e))return;if(Se.add(e),Ae("pause app",e),(C==null?void 0:C.app_id)===e&&!C.forced){C.handle.cancel();return}let t=D.getState().downloads[e];Z.includes(e)&&t&&de(e,{status:"paused",progress:0,version:t.version})},tr=e=>{if(!Se.delete(e))return;Ae("resume app",e);let t=D.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!Z.includes(e)&&Ye(e)&&(Oe[e]=0,Vt(e)),Z.includes(e)&&t&&de(e,{status:"queued",progress:0,version:t.version}),Ne()},nr=e=>{let{pause_reasons:t}=D.getState();t.includes(e)||(D.setState({pause_reasons:[...t,e]}),Ae("pause",e),t.length===0&&De({type:"pause_change",paused:!0,reasons:[e]}),C&&!C.forced&&C.handle.cancel())},or=e=>{let{pause_reasons:t}=D.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);D.setState({pause_reasons:n}),Ae("resume",e),n.length===0&&De({type:"pause_change",paused:!1,reasons:n}),Ne()},yn=e=>D.getState().updates[e],rr=async e=>{var n,o;let t=yn(e);Nt.add(e);try{let r=await gt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=Ye(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(D.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),Ae("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Nt.delete(e)}},ir=()=>Object.values(D.getState().catalog).map(e=>({...e,installed:!!B(e.app_id),removed_by_user:Ue.has(e.app_id)})),Ye=e=>D.getState().catalog[e],gt=async e=>{let t=Ye(e);if(!t)return;if(Se.delete(e),Ue.delete(e),await un(t))return B(e);let n=B(e);if(Ho(e)&&!Nt.has(e)&&n&&await Ce(n))return n;let o=new Promise(r=>{var i;((i=We[e])!=null?i:We[e]=[]).push(r)});return(C==null?void 0:C.app_id)===e?C.forced=!0:(Oe[e]=0,Vt(e,{front:!0}),C&&!C.forced?C.handle.cancel():Ne(e)),o};var k=require("react/jsx-runtime"),wn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),sr=0,ui=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},di=A.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:g})=>{var mt,ft;let d=(0,A.useRef)(null),y=(0,A.useRef)(!1),u=j(ue,f=>f.instances[e]),w=u==null?void 0:u.app.app_id,I=u==null?void 0:u.app.manifest_url,P=u==null?void 0:u.context,E=u==null?void 0:u.url_params,M=j(X,f=>{var _;return((_=f.active)==null?void 0:_.owner)===e?f.active:null}),[N,z]=(0,A.useState)(null),[ne,Pe]=(0,A.useState)(M);M!==ne&&(Pe(M),M?z(null):(ne==null?void 0:ne.layout)===pe.top&&z(ne));let ae=(M==null?void 0:M.layout)===pe.top?M:N,[p,x]=(0,A.useState)(()=>w?B(w):null),[q,T]=(0,A.useState)(!1),[ce,_e]=(0,A.useState)(0),[K,O]=(0,A.useState)(0),[oe,J]=(0,A.useState)(!1),Q=(0,A.useRef)(null),re=f=>{Q.current&&clearTimeout(Q.current),Q.current=setTimeout(()=>{Q.current=null,J(!0)},f)};(0,A.useEffect)(()=>()=>{Q.current&&clearTimeout(Q.current)},[]),(0,A.useEffect)(()=>{if(!w||!t&&p)return;let f=!0;return T(!1),(async()=>{let _=B(w),b=_?await Ce(_):!1;if(!f||(x(b?se=>!se||se.version!==_.version||se.permissions.join(",")!==_.permissions.join(",")?_:se:null),__DEV__&&Date.now()-sr>1e4&&(sr=Date.now(),await Bt()),!f))return;let U=await gt(w),ie=U!==void 0?U:I?await Io(w,I):B(w);if(f){if(!ie){T(!0);return}x(se=>se!=null?se:ie)}})(),()=>{f=!1}},[t,w,I,ce]),(0,A.useEffect)(()=>Lo(e,f=>d.current?(d.current.postMessage(f),!0):!1),[e]);let ve=j(D,f=>{let _=w?f.downloads[w]:void 0;return(_==null?void 0:_.status)==="installed"?_.version:void 0});(0,A.useEffect)(()=>{if(t||!w||!p)return;let f=B(w);if(!f||f.version===p.version)return;let _=!0;return Ce(f).then(b=>{!_||!b||(me(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",p.version,"\u2192",f.version),x(f))}),()=>{_=!1}},[t,w,ve,p==null?void 0:p.version]);let Me=j(D,f=>{var _;return w&&(_=f.apply_ticks[w])!=null?_:0});(0,A.useEffect)(()=>{if(!Me||!w)return;let f=B(w);if(!f||f.version===(p==null?void 0:p.version))return;let _=!0;return Ce(f).then(b=>{!_||!b||(me(`webview:${e}`,"c\u1EADp nh\u1EADt",p==null?void 0:p.version,"\u2192",f.version),J(!1),x(f))}),()=>{_=!1}},[Me]),(0,A.useEffect)(()=>{var b;let f=(b=$().keep_alive)==null?void 0:b.idle_close_ms;if(t||!f||f<=0)return;let _=setTimeout(()=>{Lt(e)},f);return()=>clearTimeout(_)},[t,e]),(0,A.useEffect)(()=>{r>0&&(T(!1),J(!1),O(f=>f+1),_e(f=>f+1))},[r]);let je=(0,A.useRef)(t);(0,A.useEffect)(()=>{var f;je.current!==t&&(je.current=t,y.current&&((f=d.current)==null||f.injectJavaScript(_o(t?"resumed":"paused"))))},[t]);let xe=`${(mt=p==null?void 0:p.version)!=null?mt:"none"}:${(ft=p==null?void 0:p.permissions.join(","))!=null?ft:""}:${K}`,Te=(0,A.useMemo)(()=>JSON.stringify([P!=null?P:{},E!=null?E:{}]),[P,E]),Xe=(0,A.useMemo)(()=>{var f;return xo(E!=null?E:{},(f=p==null?void 0:p.permissions)!=null?f:[])},[Te,p==null?void 0:p.permissions]),qt=(0,A.useMemo)(()=>vo(P!=null?P:{},Xe)+wo()+bo()+($().debug?yo():""),[Xe]),Ve=(0,A.useRef)(null),Ze=(0,A.useRef)(null);(0,A.useEffect)(()=>{var _,b,U;if(!p)return;if(Ze.current!==xe){Ze.current=xe,Ve.current=Te;return}if(Ve.current===Te)return;let f=((b=JSON.parse((_=Ve.current)!=null?_:"[]")[0])!=null?b:{}).org_id;if(Ve.current=Te,f===(P==null?void 0:P.org_id)&&y.current){J(!1),re(1500),(U=d.current)==null||U.injectJavaScript(Ao(P!=null?P:{},Xe));return}J(!1),O(ie=>ie+1)},[Te,p,xe]),(0,A.useEffect)(()=>(t||(Re(e),Fe(e),qe(e)),()=>{Re(e),Fe(e),qe(e)}),[t,e,xe,r]),(0,A.useEffect)(()=>{let f=L.AppState.addEventListener("change",_=>{_==="background"&&!Zn()&&Re(e),_==="background"&&!ro()&&Fe(e)});return()=>f.remove()},[e]);let Qe=(0,A.useCallback)(async f=>{var b,U,ie,se,zt,_n;let _=go(f.nativeEvent.data);if(!_){if(w&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(f.nativeEvent.data,{app_id:w,instance_id:e})).catch(W=>{console.warn("[miniapp] onWebEvent l\u1ED7i",w,W)})}catch(W){console.warn("[miniapp] onWebEvent l\u1ED7i",w,W)}return}if(_.method==="log"){let{level:W,text:G}=_;me(`web:${e}`,W!=null?W:"log",G!=null?G:"");return}if(_.method==="pong"){Q.current||J(!0);return}if(_.method==="touchAtTop"){i.emit(!!_.at_top);return}if(_.method==="contextApplied"){Q.current&&clearTimeout(Q.current),Q.current=null,J(!0);return}if(_.method==="ready"){y.current=!0,J(!0);let W=(b=ue.getState().instances[e])==null?void 0:b.context;W&&((U=d.current)==null||U.injectJavaScript(on(W)));return}try{let W=await Ro(_,{getHostData:()=>{var G,ge;return(ge=(G=ue.getState().instances[e])==null?void 0:G.host_data)!=null?ge:{}},getPermissions:()=>{var G,ge;return w?(ge=(G=B(w))==null?void 0:G.permissions)!=null?ge:[]:[]},getContext:()=>{var G,ge;return(ge=(G=ue.getState().instances[e])==null?void 0:G.context)!=null?ge:{}},is_dark:o,close:Ke,app_id:w!=null?w:"",instance_id:e,options:c,emit:(G,ge)=>{var An;(An=d.current)==null||An.injectJavaScript(ho(G,ge))},playBeep:(ie=c==null?void 0:c.playScannerBeep)!=null?ie:(()=>{var G;(G=d.current)==null||G.injectJavaScript(Eo())}),isActive:()=>ue.getState().active_key===e&&L.AppState.currentState!=="background"});_.id&&((se=d.current)==null||se.injectJavaScript(mo(_.id,W)))}catch(W){if(!_.id)return;let G=W==null?void 0:W.code,ge=W instanceof m?W:new m(typeof G=="string"?G:"HOST_ERROR",String((zt=W==null?void 0:W.message)!=null?zt:W));(_n=d.current)==null||_n.injectJavaScript(fo(_.id,ge))}},[e,o,w,i,c]),$t=(0,A.useCallback)(()=>{T(!1),O(f=>f+1),_e(f=>f+1)},[]);return(0,k.jsxs)(L.View,{style:[L.StyleSheet.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&be.behind],pointerEvents:t?"auto":"none",children:[ae&&(0,k.jsx)(mn,{scanner:ae,closing:ae===N,onClosed:()=>{var f;z(null),ae.absolute&&((f=d.current)==null||f.injectJavaScript(rn(0)))},onHeight:ae.absolute?f=>{var _;return(_=d.current)==null?void 0:_.injectJavaScript(rn(f))}:void 0}),p?(0,k.jsx)(cr.default,{ref:d,source:{uri:p.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?cn():p.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:qt,onMessage:Qe,bounces:!1,overScrollMode:"never",onLoadStart:f=>{Re(e),Fe(e),qe(e),me(`webview:${e}`,"load start",wn(f.nativeEvent.url)),y.current=!1,J(!1)},onError:f=>{Re(e),Fe(e),qe(e),me(`webview:${e}`,"load error",wn(f.nativeEvent.url),f.nativeEvent.description),T(!0),J(!1)},onLoadEnd:f=>{let _=f.nativeEvent.url;me(`webview:${e}`,"load end",wn(_)),w&&(g==null||g({app_id:w,instance_id:e,url:_})),re(1500)},onContentProcessDidTerminate:()=>{Re(e),Fe(e),qe(e),y.current=!1,J(!1),O(f=>f+1)},onRenderProcessGone:()=>(Re(e),Fe(e),qe(e),y.current=!1,J(!1),O(f=>f+1),!0),style:be.webview},xe):null,(M==null?void 0:M.layout)===pe.full&&(0,k.jsx)(mn,{scanner:M}),u&&(0,k.jsx)(mi,{visible:!p||!oe,interactive:q,children:(0,k.jsx)(gi,{splash:a,app:u.app,is_dark:o,error:q,has_bundle:!!p,retry:$t})})]})}),gi=A.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=Ut(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return(0,k.jsx)(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),mi=({visible:e,interactive:t,children:n})=>{let o=(0,A.useRef)(new L.Animated.Value(e?1:0)).current,[r,i]=(0,A.useState)(e);return(0,A.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=L.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?(0,k.jsx)(L.Animated.View,{style:[L.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},bn=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,k.jsxs)(L.View,{style:[be.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,k.jsx)(L.View,{style:[be.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,k.jsx)(L.Image,{source:{uri:e.icon},style:be.splash_icon_image}):(0,k.jsx)(L.Text,{style:be.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,k.jsx)(L.Text,{style:[be.splash_name,{color:i}],children:e.name}),n==="error"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(L.Text,{style:be.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,k.jsx)(L.TouchableOpacity,{activeOpacity:.7,style:[be.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,k.jsx)(L.Text,{style:[be.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(L.ActivityIndicator,{style:be.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,k.jsxs)(L.Text,{style:be.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},ar=(e,t)=>{let n=(0,A.useRef)(t),o=(0,A.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.`))},fi=({container:e,splash:t=bn,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{ar("container",e),ar("splash",t);let l=e,s=j(ue,M=>M.active_key),g=(0,A.useRef)(s);s&&(g.current=s);let d=j(ue,M=>Object.keys(M.instances).join("|")),y=j(ue,M=>{var N;return M.active_key?(N=M.instances[M.active_key])==null?void 0:N.app.name:void 0}),u=(0,A.useMemo)(()=>d?d.split("|"):[],[d]),[w,I]=(0,A.useState)({}),P=(0,A.useRef)(ui()).current;(0,A.useEffect)(()=>{if(!s||!r)return;let M=L.BackHandler.addEventListener("hardwareBackPress",()=>(Ke(),!0));return()=>M.remove()},[s,r]);let E=(0,A.useCallback)(()=>{let M=ue.getState().active_key;M&&I(N=>({...N,[M]:(N[M]||0)+1}))},[]);return u.length?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(l,{visible:!!s,title:y!=null?y:"",is_dark:n,close:Ke,reload:E,subscribeWebAtTop:P.subscribe,children:u.map(M=>(0,k.jsx)(di,{instance_key:M,is_active:s===M,is_front:(s!=null?s:g.current)===M,is_dark:n,reload_tick:w[M]||0,web_at_top:P,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},M))}),(0,k.jsx)(qo,{})]}):null},be=L.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"}}),lr=A.default.memo(fi);0&&(module.exports={CodeType,DefaultMiniAppSplash,MINIAPP_PLATFORM_URL,MiniAppHost,MiniAppHostError,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,ToastType,closeMiniApp,configureMiniApp,createMmkvStorage,createReactNativeBiometrics,createRnfsFileSystem,ensureMiniApp,getLocalMiniApp,getMiniAppCatalog,getMiniAppCatalogEntry,getMiniAppStatuses,getMiniAppUpdate,installBundledMiniApp,onMiniAppEvent,openMiniApp,pauseMiniApp,pauseMiniAppDownloads,preloadMiniApp,releaseSpeechFor,restoreMiniApp,resumeMiniApp,resumeMiniAppDownloads,sendEventToWeb,syncMiniAppCatalog,uninstallMiniApp,updateMiniApp,uploadToUrl,useMiniAppDownload,useMiniAppDownloadsPaused});
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var jt="https://retion-miniapp-platform.vercel.app",Ve=null,On=new Set,lr=e=>{Ve=e,On.forEach(t=>t())},F=()=>{if(!Ve)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Ve},kn=e=>{On.add(e),Ve&&e()},ue=(...e)=>{Ve!=null&&Ve.debug&&console.log("[miniapp]",...e)};var pr=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:c,contentLength:l})=>r==null?void 0:r(c,l)});return{promise:a.then(({statusCode:c})=>({status:c})),cancel:()=>e.stopDownload(i)}}}),ur=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});import Rn,{useCallback as Mn,useEffect as le,useMemo as qt,useRef as be,useState as Ce}from"react";import{AppState as ir,ActivityIndicator as Fi,Animated as Sn,BackHandler as Di,Image as Ni,StyleSheet as Tn,Text as yt,TouchableOpacity as Ui,View as xn}from"react-native";import Vi from"react-native-webview";import{Linking as _o,Platform as Wr}from"react-native";var In=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),_t,Ht=()=>(_t||(_t=import("react-native-biometrics").then(({default:e})=>In(new e({allowDeviceCredentials:!1}))).catch(e=>{throw _t=void 0,new m("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),_t);import{PermissionsAndroid as Be,Platform as dr}from"react-native";var Ln=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new m("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 m("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new m("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Fn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new m("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(dr.OS==="android"){let s=Be.PERMISSIONS.ACCESS_FINE_LOCATION,g=Be.PERMISSIONS.ACCESS_COARSE_LOCATION,d=await Be.check(s);if(!c())return;let h=d||await Be.check(g);if(!c())return;if(!d&&!h){let u=await Be.requestMultiple([s,g]);if(!c())return;if(u[s]!==Be.RESULTS.GRANTED&&u[g]!==Be.RESULTS.GRANTED)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var d;if(!c())return;let g=(d={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?d:"LOCATION_ERROR";i(new m(g,s.message))},e)}})().catch(l=>i(l))});import{Platform as $n}from"react-native";var Jt=20,Dn=20,zn=/^[a-z][a-z0-9_-]{0,31}$/,gr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,mr=["low","medium","high"],Oe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),W=e=>new m("INVALID_PARAMS",e),nt=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Nn=(e,t)=>{if(e===void 0)return{};if(!Oe(e)||Object.keys(e).length>Dn||Object.values(e).some(n=>typeof n!="string"))throw W(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Dn} key)`);return e},Wn=e=>{var n,o,r,i;if(e!==void 0&&!Oe(e))throw W("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!zn.test(t.source)))throw W("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"||!gr.test(a))))throw W("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!nt(t.max_count,1,Jt))throw W(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Jt}`);if(t.max_size!==void 0&&!nt(t.max_size,1,Number.MAX_SAFE_INTEGER))throw W("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!nt(t.concurrency,1,5))throw W("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:fr(t.process),target:hr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},fr=e=>{if(e===void 0)return{};if(!Oe(e))throw W("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Oe(n))throw W("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!nt(n[o],1,1e4))throw W(`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 W("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(!Oe(n))throw W("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!nt(n.max_duration,1,3600))throw W("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!mr.includes(n.quality))throw W("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},hr=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Oe(e))throw W("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!zn.test(t))throw W("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Oe(e.params))throw W("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 W("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 W(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Nn(e.headers,"upload.headers"),form_data:Nn(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},jn=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},yr=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=jn(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},wr=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"},Qe,br=()=>(Qe!=null||(Qe=import("react-native-image-picker").catch(e=>{throw Qe=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),Qe),Un=e=>async({accept:t,max_count:n,process:o})=>{var l,s,g,d,h,u,y,P,M;let r=await br(),i=wr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(d=(g=o.image)==null?void 0:g.quality)!=null?d:.8,videoQuality:(u=(h=o.video)==null?void 0:h.quality)!=null?u:"medium",durationLimit:(y=o.video)==null?void 0:y.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let v=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new m(v,(P=c.errorMessage)!=null?P:c.errorCode)}return((M=c.assets)!=null?M:[]).filter(v=>v.uri).map((v,A)=>{var O,N,X;return{uri:v.uri,name:(O=v.fileName)!=null?O:`file_${A+1}`,mime_type:(N=v.type)!=null?N:"application/octet-stream",size:v.fileSize,width:v.width,height:v.height,duration:v.duration,processed:!((X=v.type)!=null&&X.startsWith("video/"))||$n.OS==="ios"}})},_r={"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"},Ar={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},Sr=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var g;return(g=_r[s])!=null?g:Ar[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let g=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(u=>u.uri&&!u.error).map((u,y)=>{var P,M,v;return{uri:u.uri,name:(P=u.name)!=null?P:`file_${y+1}`,mime_type:(M=u.type)!=null?M:"application/octet-stream",size:(v=u.size)!=null?v:void 0}});if($n.OS!=="android"||!e.keepLocalCopy||!g.some(u=>u.uri.startsWith("content://")))return g;let d=await e.keepLocalCopy({files:g.map(u=>({uri:u.uri,fileName:u.name})),destination:"cachesDirectory"}),h=new Map(d.map(u=>[u.sourceUri,u.status==="success"?u.localUri:void 0]));return g.map(u=>{var y;return{...u,uri:(y=h.get(u.uri))!=null?y:u.uri}})}catch(s){let g=s==null?void 0:s.code;if(g===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw g===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new m("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},et,vr=async e=>(et!=null||(et=import("@react-native-documents/picker").then(t=>Sr(t)).catch(t=>{throw et=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await et)(e)),Hn={library:Un("library"),camera:Un("camera"),document:vr},Vn={type:"image",label:"\u1EA2nh",accept:["image/*"]},Bn={type:"video",label:"Video",accept:["video/*"]},qn={library:[Vn,Bn],camera:[Vn,Bn],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},tt,Jn=()=>(tt!=null||(tt=import("react-native-compressor").catch(()=>(tt=void 0,null))),tt),Gn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Mr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),xr={low:640,medium:1280,high:1920},Er=async(e,{image:t})=>{var o;if(!t||!Mr.has(e.mime_type.toLowerCase()))return e;let n=await Jn();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 Gn(n,r,e.size),processed:!0}}catch{return e}},Rr=async(e,{video:t})=>{var o;let n=await Jn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:xr[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Gn(n,r,e.size),processed:!0}}catch{return e}},Tr={image:Er,video:Rr},Pr=(e,t)=>t.split(".").reduce((n,o)=>Oe(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 m("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([d,h])=>l.append(d,h)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let g=d=>{o.removeEventListener("abort",s),d()};c.open("POST",a.url),Object.entries(a.headers).forEach(([d,h])=>c.setRequestHeader(d,h)),c.upload.onprogress=d=>n(d.loaded,d.total||e.size||0),c.onload=()=>g(()=>{let d=c.responseText;try{d=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new m("UPLOAD_FAILED",`HTTP ${c.status}`));return}let h=Pr(d,a.url_field);if(typeof h!="string"||!h){i(new m("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:h,response:d})}),c.onerror=()=>g(()=>i(new m("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>g(()=>i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),Yn=e=>{var o,r;let t={...Hn};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:Kn};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}},Xn=e=>{let{sources:t,targets:n}=Yn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Hn[i]&&qn[i]).map(i=>[i,qn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Jt}},St=new Map,Zn=(e,t)=>`${e}:${t}`,Cr=0,Qn=(e,t)=>{var n;typeof t=="string"&&((n=St.get(Zn(e,t)))==null||n.abort())},qe=e=>{for(let[t,n]of St)t.startsWith(`${e}:`)&&n.abort()},At=()=>new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Or=(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)}},eo=async(e,t)=>{var l;let{sources:n,targets:o}=Yn(t.config),r=n[e.source];if(!r)throw new m("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 m("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=Zn(t.instance_id,(l=t.task_id)!=null?l:`auto-${++Cr}`);St.set(c,a);try{return await kr(e,t,r,i,a.signal)}finally{St.delete(c)}},kr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=d=>d()},l,s,g)=>{var p,S,Z;let d={app_id:n!=null?n:"",instance_id:t,context:{...(p=o==null?void 0:o())!=null?p:{}}},h=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:d}))).slice(0,e.max_count);if(g.aborted)throw At();if(!h.length)throw new m("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let u=[],y=h.filter(x=>yr(x,e.accept)?!0:(u.push({name:x.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${x.mime_type||jn(x.name)}`}),!1)),P=y.map(()=>0),M=y.map(x=>{var ie;return(ie=x.size)!=null?ie:0}),v=0,A=0,O=(x=!1)=>{if(!a||!r)return;let ie=Date.now();if(!x&&ie-A<200)return;A=ie;let fe=M.reduce((T,Q)=>T+Q,0),z=P.reduce((T,Q)=>T+Q,0);a("upload.progress",{task_id:r,loaded:z,total:fe,percent:fe?Math.min(100,Math.round(z/fe*100)):0,done_count:v,count:y.length})},N=[],X=0,xe=async()=>{var x,ie,fe;for(;X<y.length;){let z=X++,T=y[z];try{if(g.aborted)throw At();let Q=T.mime_type.startsWith("image/")?"image":T.mime_type.startsWith("video/")?"video":void 0,B=Q&&!T.processed?(ie=(x=i==null?void 0:i.processors)==null?void 0:x[Q])!=null?ie:Tr[Q]:void 0;if(B&&(T=await B(T,e.process),M[z]=(fe=T.size)!=null?fe:M[z],g.aborted))throw At();if(e.max_size&&T.size&&T.size>e.max_size)throw new m("FILE_TOO_LARGE",`File ${T.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let K=(We,Se)=>{P[z]=We,Se&&(M[z]=Se),O()},ee=await s({file:T,target:e.target,onProgress:K,signal:g,caller:d});if(typeof(ee==null?void 0:ee.url)!="string"||!ee.url)throw new m("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:_e,...Ae}=ee;N[z]={url:_e,name:T.name,mime_type:T.mime_type,size:T.size,width:T.width,height:T.height,duration:T.duration,...Object.keys(Ae).length?{response:"response"in Ae?Ae.response:Ae}:{}},P[z]=M[z]}catch(Q){u.push(Or(y[z].name,Q))}finally{v++,O(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,y.length)},xe)),g.aborted)throw At();let re=N.filter(x=>!!x);if(!re.length){let x=u[0];throw new m((S=x==null?void 0:x.code)!=null?S:"UPLOAD_FAILED",(Z=x==null?void 0:x.message)!=null?Z:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:re,failed:u}};import{useRef as Ir,useSyncExternalStore as Lr}from"react";var ke=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)})}},V=(e,t,n=Object.is)=>{let o=Ir(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return Lr(e.subscribe,r)};var he={info:"info",success:"success",error:"error"},Fr=200,to={info:2e3,success:2e3,error:3e3},ot=ke({message:"",type:he.info,tick:0}),no=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Fr);return o?{message:o,type:Object.values(he).includes(n)?n:he.info}:null},oo=(e,t=he.info)=>{ot.setState(n=>({message:e,type:t,tick:n.tick+1}))};import{Alert as Nr,Linking as Ur,Platform as rt,StatusBar as Vr}from"react-native";import{AppState as ro,Platform as Kt}from"react-native";var de,io=()=>Kt.OS==="android"&&!!(de!=null&&de.requesting_permission),Dr=1500,vt=()=>new Promise(e=>{if(Kt.OS!=="android"||ro.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Dr),o=ro.addEventListener("change",r=>{r==="active"&&t()})}),Gt=e=>{var t;if(de===e&&(de=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Kt.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},so=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(de)throw new m("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};de=r;try{let g;try{g=await import("expo-speech-recognition")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let d=g.ExpoSpeechRecognitionModule;if(r.native=d,r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let h;try{h=await d.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await vt(),r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!h.granted)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await d.getStateAsync()!=="inactive")throw new m("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 m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(d.addListener("result",u=>{var y,P;de!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(P=(y=u.results[0])==null?void 0:y.transcript)!=null?P:""})}),d.addListener("error",u=>{de===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),d.addListener("end",()=>{de===r&&(Gt(r),n("speech.end"))})),r.started=!0,d.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:g.AVAudioSessionCategory.playAndRecord,categoryOptions:[g.AVAudioSessionCategoryOptions.defaultToSpeaker,g.AVAudioSessionCategoryOptions.allowBluetooth],mode:g.AVAudioSessionMode.measurement}})}catch(g){throw Gt(r),g}},ao=e=>{let t=de;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Re=e=>{let t=de;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{Gt(t)}};var co={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"},oe={...co,all:Object.values(co)},it={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Xt={result:"scanner.result",end:"scanner.end"},je={user:"user",web:"web",closed:"closed",error:"error"},ge={top:"top",full:"full"},Ie={once:"once",continuous:"continuous"},Br=1500,lo=6e4,I,j=ke({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),uo=()=>rt.OS==="android"&&!!(I!=null&&I.requesting_permission),Zt=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r,absolute:i}=e!=null?e:{},a={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(c=>oe.all.includes(c)))throw new m("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>lo)throw new m("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${lo}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new m("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(ge).includes(r))throw new m("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new m("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},Qt=e=>I!==e?!1:(I=void 0,j.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),qr=()=>Nr.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:()=>{Ur.openSettings().catch(()=>{})}}]),go=async(e,t)=>{if(I)throw new m("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");I=e;let n=()=>{if(e.cancelled||!t())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=rt.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await vt(),n(),c!=="granted")throw a&&qr(),new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new m("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await en();n(),j.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 Qt(e),o}},Mt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{Mt=e==null?void 0:e.insets}).catch(()=>{});var xt=()=>{var e;return Mt!=null?Mt:{top:rt.OS==="ios"?54:(e=Vr.currentHeight)!=null?e:0,bottom:rt.OS==="ios"?34:48}},en=async()=>{if(rt.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},mo=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:oe.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Br,hint:n.hint,layout:t===Ie.once?ge.full:(i=n.layout)!=null?i:ge.top,absolute:t!==Ie.once&&((a=n.layout)!=null?a:ge.top)===ge.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},fo=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=mo(e,Ie.once,t);a.onHit=o,a.resolve=r,a.reject=i,go(a,n).catch(i)}),ho=(e,t,n,o=()=>!0,r)=>{let i=mo(e,Ie.continuous,t);return i.emit=n,i.onHit=r,go(i,o)},Et=(e,t,n)=>{var o,r;if(!j.getState().active){e.cancelled=!0;return}if(Qt(e)){if(e.mode===Ie.once){(o=e.reject)==null||o.call(e,t===je.error?new m("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new m("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,Xt.end,n?{reason:t,message:n}:{reason:t})}},yo=e=>{(I==null?void 0:I.owner)===e&&Et(I,je.web)},Le=e=>{(I==null?void 0:I.owner)===e&&Et(I,je.closed)},tn=()=>{I&&Et(I,je.user)},wo=e=>{I&&Et(I,je.error,e)},nn=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=I;if(!(!o||!j.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(o.last_seen.set(c,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Ie.once){Qt(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}j.setState(g=>({last_value:c,hit_tick:g.hit_tick+1,scan_count:g.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,Xt.result,{value:c,type:l})}}},$r={1:oe.code128,2:oe.code39,4:oe.code93,8:oe.codabar,16:oe.dataMatrix,32:oe.ean13,64:oe.ean8,128:oe.itf,256:oe.qr,512:oe.upcA,1024:oe.upcE,2048:oe.pdf417,4096:oe.aztec},zr=2500,po=2e3,Yt=e=>{j.setState({notice:e}),setTimeout(()=>{j.getState().notice===e&&j.setState({notice:null})},zr)},bo=async()=>{var t,n;let e=I;if(!(!e||j.getState().is_picking)){e.requesting_permission=!0,j.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:po,maxHeight:po}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||I!==e)return;if(r.errorCode||!i){Yt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(I!==e)return;let l=c.map(({value:s,format:g})=>({value:s,code_type:$r[g]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:g})=>({value:s,type:g!=null?g:"unknown"}));if(!l.length){Yt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}nn(l,Date.now(),!0)}catch{I===e&&Yt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await vt(),e.requesting_permission=!1,I===e&&j.setState({is_picking:!1})}}};var Tt=1,m=class extends Error{constructor(n,o){super(o);this.code=n}},Ao=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Tt&&typeof t.method=="string"?t:null}catch{return null}},at=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,So=(e,t)=>at({id:e,result:t}),vo=(e,t)=>at({id:e,error:{code:t.code,message:t.message}}),Mo=(e,t)=>at({event:e,data:t}),rn=e=>at({event:"context",data:e});var xo=()=>`(function () {
1
+ var Ht="https://retion-miniapp-platform.vercel.app",Ve=null,kn=new Set,dr=e=>{Ve=e,kn.forEach(t=>t())},D=()=>{if(!Ve)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Ve},In=e=>{kn.add(e),Ve&&e()},ue=(...e)=>{Ve!=null&&Ve.debug&&console.log("[miniapp]",...e)};var gr=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:c,contentLength:l})=>r==null?void 0:r(c,l)});return{promise:a.then(({statusCode:c})=>({status:c})),cancel:()=>e.stopDownload(i)}}}),mr=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});import Pn,{useCallback as xn,useEffect as le,useMemo as $t,useRef as be,useState as Ce}from"react";import{AppState as cr,ActivityIndicator as Ui,Animated as vn,BackHandler as Vi,Image as Bi,StyleSheet as Tn,Text as yt,TouchableOpacity as qi,View as En}from"react-native";import $i from"react-native-webview";import{Linking as vo,Platform as Jr}from"react-native";var Ln=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),_t,Jt=()=>(_t||(_t=import("react-native-biometrics").then(({default:e})=>Ln(new e({allowDeviceCredentials:!1}))).catch(e=>{throw _t=void 0,new m("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),_t);import{PermissionsAndroid as Be,Platform as fr}from"react-native";var Fn=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new m("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 m("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new m("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Dn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new m("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(fr.OS==="android"){let s=Be.PERMISSIONS.ACCESS_FINE_LOCATION,g=Be.PERMISSIONS.ACCESS_COARSE_LOCATION,d=await Be.check(s);if(!c())return;let h=d||await Be.check(g);if(!c())return;if(!d&&!h){let u=await Be.requestMultiple([s,g]);if(!c())return;if(u[s]!==Be.RESULTS.GRANTED&&u[g]!==Be.RESULTS.GRANTED)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var d;if(!c())return;let g=(d={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?d:"LOCATION_ERROR";i(new m(g,s.message))},e)}})().catch(l=>i(l))});import{Platform as zn}from"react-native";var Gt=20,Nn=20,Wn=/^[a-z][a-z0-9_-]{0,31}$/,hr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,yr=["low","medium","high"],Oe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),j=e=>new m("INVALID_PARAMS",e),nt=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Un=(e,t)=>{if(e===void 0)return{};if(!Oe(e)||Object.keys(e).length>Nn||Object.values(e).some(n=>typeof n!="string"))throw j(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Nn} key)`);return e},jn=e=>{var n,o,r,i;if(e!==void 0&&!Oe(e))throw j("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!Wn.test(t.source)))throw j("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"||!hr.test(a))))throw j("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!nt(t.max_count,1,Gt))throw j(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Gt}`);if(t.max_size!==void 0&&!nt(t.max_size,1,Number.MAX_SAFE_INTEGER))throw j("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!nt(t.concurrency,1,5))throw j("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:wr(t.process),target:br(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},wr=e=>{if(e===void 0)return{};if(!Oe(e))throw j("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Oe(n))throw j("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!nt(n[o],1,1e4))throw j(`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 j("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(!Oe(n))throw j("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!nt(n.max_duration,1,3600))throw j("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!yr.includes(n.quality))throw j("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},br=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Oe(e))throw j("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Wn.test(t))throw j("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Oe(e.params))throw j("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 j("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 j(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Un(e.headers,"upload.headers"),form_data:Un(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},Hn=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},_r=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Hn(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Ar=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"},Qe,Sr=()=>(Qe!=null||(Qe=import("react-native-image-picker").catch(e=>{throw Qe=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),Qe),Vn=e=>async({accept:t,max_count:n,process:o})=>{var l,s,g,d,h,u,y,T,M;let r=await Sr(),i=Ar(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(d=(g=o.image)==null?void 0:g.quality)!=null?d:.8,videoQuality:(u=(h=o.video)==null?void 0:h.quality)!=null?u:"medium",durationLimit:(y=o.video)==null?void 0:y.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let v=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new m(v,(T=c.errorMessage)!=null?T:c.errorCode)}return((M=c.assets)!=null?M:[]).filter(v=>v.uri).map((v,A)=>{var O,U,Z;return{uri:v.uri,name:(O=v.fileName)!=null?O:`file_${A+1}`,mime_type:(U=v.type)!=null?U:"application/octet-stream",size:v.fileSize,width:v.width,height:v.height,duration:v.duration,processed:!((Z=v.type)!=null&&Z.startsWith("video/"))||zn.OS==="ios"}})},vr={"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"},Mr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},xr=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var g;return(g=vr[s])!=null?g:Mr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let g=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(u=>u.uri&&!u.error).map((u,y)=>{var T,M,v;return{uri:u.uri,name:(T=u.name)!=null?T:`file_${y+1}`,mime_type:(M=u.type)!=null?M:"application/octet-stream",size:(v=u.size)!=null?v:void 0}});if(zn.OS!=="android"||!e.keepLocalCopy||!g.some(u=>u.uri.startsWith("content://")))return g;let d=await e.keepLocalCopy({files:g.map(u=>({uri:u.uri,fileName:u.name})),destination:"cachesDirectory"}),h=new Map(d.map(u=>[u.sourceUri,u.status==="success"?u.localUri:void 0]));return g.map(u=>{var y;return{...u,uri:(y=h.get(u.uri))!=null?y:u.uri}})}catch(s){let g=s==null?void 0:s.code;if(g===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw g===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new m("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},et,Er=async e=>(et!=null||(et=import("@react-native-documents/picker").then(t=>xr(t)).catch(t=>{throw et=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await et)(e)),Jn={library:Vn("library"),camera:Vn("camera"),document:Er},Bn={type:"image",label:"\u1EA2nh",accept:["image/*"]},qn={type:"video",label:"Video",accept:["video/*"]},$n={library:[Bn,qn],camera:[Bn,qn],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"]}]},tt,Gn=()=>(tt!=null||(tt=import("react-native-compressor").catch(()=>(tt=void 0,null))),tt),Kn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Rr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Pr={low:640,medium:1280,high:1920},Tr=async(e,{image:t})=>{var o;if(!t||!Rr.has(e.mime_type.toLowerCase()))return e;let n=await Gn();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 Kn(n,r,e.size),processed:!0}}catch{return e}},Cr=async(e,{video:t})=>{var o;let n=await Gn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Pr[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Kn(n,r,e.size),processed:!0}}catch{return e}},Or={image:Tr,video:Cr},kr=(e,t)=>t.split(".").reduce((n,o)=>Oe(n)?n[o]:void 0,e),Yn=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new m("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([d,h])=>l.append(d,h)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let g=d=>{o.removeEventListener("abort",s),d()};c.open("POST",a.url),Object.entries(a.headers).forEach(([d,h])=>c.setRequestHeader(d,h)),c.upload.onprogress=d=>n(d.loaded,d.total||e.size||0),c.onload=()=>g(()=>{let d=c.responseText;try{d=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new m("UPLOAD_FAILED",`HTTP ${c.status}`));return}let h=kr(d,a.url_field);if(typeof h!="string"||!h){i(new m("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:h,response:d})}),c.onerror=()=>g(()=>i(new m("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>g(()=>i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),Xn=e=>{var o,r;let t={...Jn};for(let[i,a]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))a?t[i]=a:delete t[i];let n={url:Yn};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}},Zn=e=>{let{sources:t,targets:n}=Xn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Jn[i]&&$n[i]).map(i=>[i,$n[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Gt}},St=new Map,Qn=(e,t)=>`${e}:${t}`,Ir=0,eo=(e,t)=>{var n;typeof t=="string"&&((n=St.get(Qn(e,t)))==null||n.abort())},qe=e=>{for(let[t,n]of St)t.startsWith(`${e}:`)&&n.abort()},At=()=>new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Lr=(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)}},to=async(e,t)=>{var l;let{sources:n,targets:o}=Xn(t.config),r=n[e.source];if(!r)throw new m("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 m("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=Qn(t.instance_id,(l=t.task_id)!=null?l:`auto-${++Ir}`);St.set(c,a);try{return await Fr(e,t,r,i,a.signal)}finally{St.delete(c)}},Fr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=d=>d()},l,s,g)=>{var p,S,L;let d={app_id:n!=null?n:"",instance_id:t,context:{...(p=o==null?void 0:o())!=null?p:{}}},h=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:d}))).slice(0,e.max_count);if(g.aborted)throw At();if(!h.length)throw new m("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let u=[],y=h.filter(x=>_r(x,e.accept)?!0:(u.push({name:x.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${x.mime_type||Hn(x.name)}`}),!1)),T=y.map(()=>0),M=y.map(x=>{var ie;return(ie=x.size)!=null?ie:0}),v=0,A=0,O=(x=!1)=>{if(!a||!r)return;let ie=Date.now();if(!x&&ie-A<200)return;A=ie;let fe=M.reduce((P,Q)=>P+Q,0),W=T.reduce((P,Q)=>P+Q,0);a("upload.progress",{task_id:r,loaded:W,total:fe,percent:fe?Math.min(100,Math.round(W/fe*100)):0,done_count:v,count:y.length})},U=[],Z=0,xe=async()=>{var x,ie,fe;for(;Z<y.length;){let W=Z++,P=y[W];try{if(g.aborted)throw At();let Q=P.mime_type.startsWith("image/")?"image":P.mime_type.startsWith("video/")?"video":void 0,q=Q&&!P.processed?(ie=(x=i==null?void 0:i.processors)==null?void 0:x[Q])!=null?ie:Or[Q]:void 0;if(q&&(P=await q(P,e.process),M[W]=(fe=P.size)!=null?fe:M[W],g.aborted))throw At();if(e.max_size&&P.size&&P.size>e.max_size)throw new m("FILE_TOO_LARGE",`File ${P.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let Y=(We,Se)=>{T[W]=We,Se&&(M[W]=Se),O()},ee=await s({file:P,target:e.target,onProgress:Y,signal:g,caller:d});if(typeof(ee==null?void 0:ee.url)!="string"||!ee.url)throw new m("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:_e,...Ae}=ee;U[W]={url:_e,name:P.name,mime_type:P.mime_type,size:P.size,width:P.width,height:P.height,duration:P.duration,...Object.keys(Ae).length?{response:"response"in Ae?Ae.response:Ae}:{}},T[W]=M[W]}catch(Q){u.push(Lr(y[W].name,Q))}finally{v++,O(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,y.length)},xe)),g.aborted)throw At();let re=U.filter(x=>!!x);if(!re.length){let x=u[0];throw new m((S=x==null?void 0:x.code)!=null?S:"UPLOAD_FAILED",(L=x==null?void 0:x.message)!=null?L:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:re,failed:u}};import{useRef as Dr,useSyncExternalStore as Nr}from"react";var ke=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)})}},B=(e,t,n=Object.is)=>{let o=Dr(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return Nr(e.subscribe,r)};var he={info:"info",success:"success",error:"error"},Ur=200,no={info:2e3,success:2e3,error:3e3},ot=ke({message:"",type:he.info,tick:0}),oo=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Ur);return o?{message:o,type:Object.values(he).includes(n)?n:he.info}:null},ro=(e,t=he.info)=>{ot.setState(n=>({message:e,type:t,tick:n.tick+1}))};import{Alert as Br,Linking as qr,Platform as rt,StatusBar as $r}from"react-native";import{AppState as io,Platform as Yt}from"react-native";var de,vt=new Map,so=(e,t)=>{vt.set(e,t)},ao=e=>{vt.delete(e)},co=()=>Yt.OS==="android"&&!!(de!=null&&de.requesting_permission),Vr=1500,Mt=()=>new Promise(e=>{if(Yt.OS!=="android"||io.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Vr),o=io.addEventListener("change",r=>{r==="active"&&t()})}),Kt=e=>{var t;if(de===e&&(de=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Yt.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},lo=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(de)throw new m("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};de=r;try{let g;try{g=await import("expo-speech-recognition")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let d=g.ExpoSpeechRecognitionModule;if(r.native=d,r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let h;try{h=await d.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await Mt(),r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!h.granted)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await d.getStateAsync()!=="inactive")throw new m("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 m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(d.addListener("result",u=>{var y,T;de!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(T=(y=u.results[0])==null?void 0:y.transcript)!=null?T:""})}),d.addListener("error",u=>{de===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),d.addListener("end",()=>{de===r&&(Kt(r),n("speech.end"))})),r.started=!0,d.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:g.AVAudioSessionCategory.playAndRecord,categoryOptions:[g.AVAudioSessionCategoryOptions.defaultToSpeaker,g.AVAudioSessionCategoryOptions.allowBluetooth],mode:g.AVAudioSessionMode.measurement}})}catch(g){throw Kt(r),g}},po=e=>{let t=de;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Re=e=>{var o;let t=vt.get(e);if(t){vt.delete(e);try{(o=t.release)==null||o.call(t,e)}catch{}return}let n=de;if(!(!n||n.owner!==e||n.cancelled)&&(n.cancelled=!0,n.started))try{n.native.abort()}catch{Kt(n)}};var uo={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"},oe={...uo,all:Object.values(uo)},it={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Zt={result:"scanner.result",end:"scanner.end"},je={user:"user",web:"web",closed:"closed",error:"error"},ge={top:"top",full:"full"},Ie={once:"once",continuous:"continuous"},zr=1500,go=6e4,I,H=ke({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),fo=()=>rt.OS==="android"&&!!(I!=null&&I.requesting_permission),Qt=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r,absolute:i}=e!=null?e:{},a={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(c=>oe.all.includes(c)))throw new m("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>go)throw new m("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${go}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new m("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(ge).includes(r))throw new m("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new m("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},en=e=>I!==e?!1:(I=void 0,H.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Wr=()=>Br.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:()=>{qr.openSettings().catch(()=>{})}}]),ho=async(e,t)=>{if(I)throw new m("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");I=e;let n=()=>{if(e.cancelled||!t())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=rt.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await Mt(),n(),c!=="granted")throw a&&Wr(),new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new m("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await tn();n(),H.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,absolute:e.absolute,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw en(e),o}},xt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{xt=e==null?void 0:e.insets}).catch(()=>{});var Et=()=>{var e;return xt!=null?xt:{top:rt.OS==="ios"?54:(e=$r.currentHeight)!=null?e:0,bottom:rt.OS==="ios"?34:48}},tn=async()=>{if(rt.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},yo=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:oe.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:zr,hint:n.hint,layout:t===Ie.once?ge.full:(i=n.layout)!=null?i:ge.top,absolute:t!==Ie.once&&((a=n.layout)!=null?a:ge.top)===ge.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},wo=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=yo(e,Ie.once,t);a.onHit=o,a.resolve=r,a.reject=i,ho(a,n).catch(i)}),bo=(e,t,n,o=()=>!0,r)=>{let i=yo(e,Ie.continuous,t);return i.emit=n,i.onHit=r,ho(i,o)},Rt=(e,t,n)=>{var o,r;if(!H.getState().active){e.cancelled=!0;return}if(en(e)){if(e.mode===Ie.once){(o=e.reject)==null||o.call(e,t===je.error?new m("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new m("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,Zt.end,n?{reason:t,message:n}:{reason:t})}},_o=e=>{(I==null?void 0:I.owner)===e&&Rt(I,je.web)},Le=e=>{(I==null?void 0:I.owner)===e&&Rt(I,je.closed)},nn=()=>{I&&Rt(I,je.user)},Ao=e=>{I&&Rt(I,je.error,e)},on=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=I;if(!(!o||!H.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(o.last_seen.set(c,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Ie.once){en(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}H.setState(g=>({last_value:c,hit_tick:g.hit_tick+1,scan_count:g.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,Zt.result,{value:c,type:l})}}},jr={1:oe.code128,2:oe.code39,4:oe.code93,8:oe.codabar,16:oe.dataMatrix,32:oe.ean13,64:oe.ean8,128:oe.itf,256:oe.qr,512:oe.upcA,1024:oe.upcE,2048:oe.pdf417,4096:oe.aztec},Hr=2500,mo=2e3,Xt=e=>{H.setState({notice:e}),setTimeout(()=>{H.getState().notice===e&&H.setState({notice:null})},Hr)},So=async()=>{var t,n;let e=I;if(!(!e||H.getState().is_picking)){e.requesting_permission=!0,H.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:mo,maxHeight:mo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||I!==e)return;if(r.errorCode||!i){Xt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(I!==e)return;let l=c.map(({value:s,format:g})=>({value:s,code_type:jr[g]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:g})=>({value:s,type:g!=null?g:"unknown"}));if(!l.length){Xt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}on(l,Date.now(),!0)}catch{I===e&&Xt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await Mt(),e.requesting_permission=!1,I===e&&H.setState({is_picking:!1})}}};var Tt=1,m=class extends Error{constructor(n,o){super(o);this.code=n}},Mo=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Tt&&typeof t.method=="string"?t:null}catch{return null}},at=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,xo=(e,t)=>at({id:e,result:t}),Eo=(e,t)=>at({id:e,error:{code:t.code,message:t.message}}),Ro=(e,t)=>at({event:e,data:t}),sn=e=>at({event:"context",data:e});var Po=()=>`(function () {
2
2
  var post = function (level, args) {
3
3
  try {
4
4
  var parts = [];
@@ -19,7 +19,7 @@ var jt="https://retion-miniapp-platform.vercel.app",Ve=null,On=new Set,lr=e=>{Ve
19
19
  window.addEventListener('unhandledrejection', function (e) { post('error', ['[unhandledrejection]', e.reason]); });
20
20
  // Kh\xF4ng log query (c\xF3 th\u1EC3 ch\u1EE9a token) \u2014 ch\u1EC9 \u0111\u01B0\u1EDDng d\u1EABn + route.
21
21
  post('info', ['[page] ' + location.pathname + location.hash]);
22
- })(); true;`,Eo=()=>`(function () {
22
+ })(); true;`,To=()=>`(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; }
@@ -38,7 +38,7 @@ var jt="https://retion-miniapp-platform.vercel.app",Ve=null,On=new Set,lr=e=>{Ve
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;`,Ro=()=>`(function () {
41
+ })(); true;`,Co=()=>`(function () {
42
42
  if (window.__retionSafeAreaFrozen) { return; }
43
43
  window.__retionSafeAreaFrozen = true;
44
44
  var max = {};
@@ -59,14 +59,14 @@ var jt="https://retion-miniapp-platform.vercel.app",Ve=null,On=new Set,lr=e=>{Ve
59
59
  },
60
60
  });
61
61
  };
62
- })(); true;`,To=e=>at({event:e}),Po=(e,t)=>{let n=Co(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
63
- ${rn(e)}`},Co=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),Oo=(e,t={})=>{let n=Co(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${Tt} };
62
+ })(); true;`,Oo=e=>at({event:e}),ko=(e,t)=>{let n=Io(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
63
+ ${sn(e)}`},Io=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),Lo=(e,t={})=>{let n=Io(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${Tt} };
64
64
  window.__RETION_MINIAPP_CONTEXT__ = ${JSON.stringify(e)};
65
65
  ${n?`try { history.replaceState(history.state, '', location.pathname + '?' + ${JSON.stringify(n)} + location.hash); } catch (e) {}`:""}
66
- true;`},ko={partner:"partner_token",chatbox:"chatbox_token"},Io=(e,t)=>{let n={...e};for(let o of Object.values(ko))t.includes(o)||delete n[o];return n},on=new Set,st=async(e,t)=>{if(on.has(e))throw new m("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);on.add(e);try{return await t()}finally{on.delete(e)}},sn=e=>`(function () {
66
+ true;`},Fo={partner:"partner_token",chatbox:"chatbox_token"},Do=(e,t)=>{let n={...e};for(let o of Object.values(Fo))t.includes(o)||delete n[o];return n},rn=new Set,st=async(e,t)=>{if(rn.has(e))throw new m("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);rn.add(e);try{return await t()}finally{rn.delete(e)}},an=e=>`(function () {
67
67
  window.__retionScannerHeight = ${Math.max(0,Math.round(e))};
68
68
  window.dispatchEvent(new Event('retionscannerheight'));
69
- })(); true;`,Lo=()=>`(function () {
69
+ })(); true;`,No=()=>`(function () {
70
70
  try {
71
71
  var AudioCtx = window.AudioContext || window.webkitAudioContext;
72
72
  if (!AudioCtx) { return; }
@@ -85,4 +85,4 @@ var jt="https://retion-miniapp-platform.vercel.app",Ve=null,On=new Set,lr=e=>{Ve
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;`,jr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Rt=(e,t)=>{if(typeof e!="string"||!e)throw new m("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},Fo=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:g,isActive:d,playBeep:h})=>{var v,A,O,N,X,xe,re;let u=s==null?void 0:s.handlers,y={app_id:c,instance_id:l,close:a},P=()=>{var p;(p=s==null?void 0:s.haptic)==null||p.call(s,"impactLight"),h==null||h()},M=()=>new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let p=Ln(t);return st(e,()=>Fn(p,d))}case"speech.start":{if(!g)throw M();let p={};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 m("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");p.lang=t.lang}for(let S of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[S])!==void 0){if(typeof t[S]!="boolean")throw new m("INVALID_PARAMS",`${S} ph\u1EA3i l\xE0 boolean`);p[S]=t[S]}return so(l,p,g,d)}case"speech.stop":return ao(l);case it.scan:return fo(l,Zt(t),d,P);case it.start:{if(!g)throw M();return ho(l,Zt(t),g,d,P)}case it.stop:return yo(l);case"uploadFiles":{let{task_id:p,...S}=t!=null?t:{};if(p!==void 0&&(typeof p!="string"||!p))throw new m("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return eo(Wn(S),{instance_id:l,app_id:c,getContext:r,task_id:p,config:s==null?void 0:s.upload,emit:g,exclusivePick:Z=>st("uploadFiles.pick",Z)})}case"uploadFiles.cancel":Qn(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Xn(s==null?void 0:s.upload);case"getBiometricAvailability":return((v=s==null?void 0:s.biometrics)!=null?v:await Ht()).getAvailability();case"authenticateBiometric":{let p=Rt(t==null?void 0:t.reason,"reason").trim();if(!p||p.length>200)throw new m("INVALID_PARAMS","reason must contain 1\u2013200 characters");let S=t==null?void 0:t.cancelButtonText;if(S!==void 0&&(typeof S!="string"||!S.trim()||S.length>80))throw new m("INVALID_PARAMS","Invalid cancelButtonText");return st(e,async()=>{var x;return((x=s==null?void 0:s.biometrics)!=null?x:await Ht()).authenticate({reason:p,cancelButtonText:S})})}case"requestPayment":{let p=u==null?void 0:u.requestPayment;if(!p)throw M();let S=t==null?void 0:t.amount;if(typeof S!="number"||!Number.isFinite(S)||S<=0)throw new m("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let Z={...t,amount:S,currency:Rt(t==null?void 0:t.currency,"currency")};return st(e,()=>p(Z,y))}case"printImage":{let p=u==null?void 0:u.printImage;if(!p)throw M();let S=Rt(t==null?void 0:t.image,"image");await st(e,()=>p({image:S},y));return}case"openScreen":if(!(u!=null&&u.openScreen))throw M();await u.openScreen({screen:Rt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},y);return;case"closeApp":a();return;case"openWebview":{let p=String((A=t==null?void 0:t.url)!=null?A:"");if(!/^https?:\/\//i.test(p))throw new m("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(p):_o.openURL(p));return}case"openLink":{let p=String((O=t==null?void 0:t.url)!=null?O:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(p)||/^(javascript|file|data|about|blob):/i.test(p))throw new m("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(p):_o.openURL(p))}catch(S){throw new m("NOT_SUPPORTED",String((X=(N=S==null?void 0:S.message)!=null?N:S)!=null?X:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let p=no(t);if(!p||(d==null?void 0:d())===!1)return;s!=null&&s.showToast?s.showToast(p.message,{type:p.type}):oo(p.message,p.type);return}case"haptic":{let p=jr.has(t==null?void 0:t.type)?t.type:"selection";(xe=s==null?void 0:s.haptic)==null||xe.call(s,p);return}case"getSystemInfo":return{platform:Wr.OS==="ios"?"ios":"android",appVersion:(re=s==null?void 0:s.app_version)!=null?re:"",theme:i?"dark":"light"};case"getAccessToken":{let p=n().access_token;if(!p)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return p}case"getToken":{let p=t==null?void 0:t.type;if(p==="access"){let x=n().access_token;if(!x)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return x}if(p!=="partner"&&p!=="chatbox")throw new m("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(p)}`);let S=ko[p];if(!o().includes(S))throw new m("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${S} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let Z=p==="partner"?n().partner_token:n().chatbox_token;if(!Z)throw new m("HOST_ERROR",`Kh\xF4ng c\xF3 ${S}`);return Z}case"getUserInfo":{let p=n().user;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return p}case"getPageInfo":{let p=n().page;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return p}case"sendMessage":case"insertText":throw new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new m("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var cn=e=>`bundle:${e}`,ln=()=>`${F().file_system.document_dir}/miniapps`,pn=ln,un=(e,t,n="index.html",o=!1,r=[])=>{let i=`${pn()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},an=e=>{var t;F().storage.setString(cn(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Hr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,L=e=>{let t=F().storage.getString(cn(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return un(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Te=e=>F().file_system.exists(e.entry_uri.replace("file://","")),dn=async e=>{let t=L(e.app_id);return(t==null?void 0:t.version)===e.version&&await Te(t)},No=async(e,t)=>{let n=F().file_system,o=`${pn()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Uo=async e=>{var t;await((t=lt[e])==null?void 0:t.catch(()=>{})),F().storage.setString(cn(e),""),await F().file_system.remove(`${pn()}/${e}`).catch(()=>{})},He=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},lt={},Vo=(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},Jr=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let c=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(c)return c}return 0},Gr=({manifest:e,zip_path:t})=>Vo(e.app_id,async()=>{var i;let n=F().file_system,o=L(e.app_id);if(o&&Jr(o.version,e.version)>=0&&await Te(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=un(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),an(e),ue("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),No(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),gn=(e,{base_url:t,onProgress:n}={})=>{let o=F().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new He},l=async()=>{var d;c();let s=L(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return an(e),L(e.app_id);c();let g=o.download({url:t?Hr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(h,u)=>{var P;let y=u>0?u:(P=e.size)!=null?P:0;y>0&&(n==null||n(Math.min(1,h/y)))}});r=g;try{let{status:h}=await g.promise;if(c(),h!==200)throw new Error(`bundle ${h}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else ue("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let u=un(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(a,u.dir),an(e),No(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),u}catch(h){throw i?new He:h}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:Vo(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},ct={},Kr=__DEV__?0:60*1e3,Do={},Bo=(e,t)=>{var o,r;let n=L(e);return n&&Date.now()-((o=Do[t])!=null?o:0)<Kr?Promise.resolve(n):((r=ct[e])!=null||(ct[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),c=await gn(a,{base_url:t}).promise;return Do[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),L(e))).finally(()=>{ct[e]=void 0})),ct[e])};var Pt=new Map,qo=(e,t)=>(Pt.set(e,t),()=>{Pt.get(e)===t&&Pt.delete(e)}),Yr=(e,t)=>{let n=Pt.get(e);return n?n(t):!1};import{useCallback as $o,useEffect as Je,useRef as Me,useState as Ct}from"react";import{Animated as D,BackHandler as Xr,Dimensions as Zr,Easing as Ot,Pressable as Qr,StyleSheet as fn,Text as pt,View as $}from"react-native";import{Fragment as pi,jsx as E,jsxs as ve}from"react/jsx-runtime";var ut="#22C55E",ei="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",ti=2,It=18,ni=1600,dt=14,oi=2e3,jo=.38,ri=40,zo=2,ii=8,si=2e3,ai=250,Ge=2e3,ci=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:dt},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:dt},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:dt},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:dt}],Wo=({color:e})=>E(pi,{children:ci.map((t,n)=>E($,{style:[_.corner,t,{borderColor:e}]},n))}),kt=({style:e,children:t,...n})=>{let o=Me(new D.Value(1)).current,r=i=>D.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return E(Qr,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:E(D.View,{style:[e,{transform:[{scale:o}]}],children:t})})},hn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var f,b;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:g}=e,d=c===ge.top,h=Me(new D.Value(0)).current,u=r.useCameraDevice("back"),y=Me(new D.Value(1)).current,[P,M]=Ct(!1),[v,A]=Ct(1),O=Me(null),[N,X]=Ct(()=>{let{width:w,height:k}=Zr.get("window");return{width:w,height:d?k*jo:k,window_y:0}}),xe=V(j,w=>w.last_value),re=V(j,w=>w.hit_tick),p=V(j,w=>w.scan_count),S=V(j,w=>w.notice),Z=V(j,w=>w.is_picking),x=Me(null),ie=xt(),fe=ie.top,z=Me(new D.Value(0)).current,T=Me(new D.Value(0)).current,Q=Me(new D.Value(0)).current,B=Me(n);B.current=n,Je(()=>{if(!t)return;h.setValue(N.height);let w=D.timing(h,{toValue:0,duration:ai,easing:Ot.out(Ot.cubic),useNativeDriver:!1});return w.start(({finished:k})=>{var te;k&&((te=B.current)==null||te.call(B))}),()=>w.stop()},[t,h]);let K=Math.round(N.width*(d?.8:.78)),ee=Math.round(d?N.height*.46:K*.78),_e=Math.round((N.height-ee)/2),Ae=Math.round((N.width-K)/2),We=r.useCodeScanner({codeTypes:i,onCodeScanned:$o(w=>nn(w),[])});Je(()=>{let w=Xr.addEventListener("hardwareBackPress",()=>(tn(),!0));return()=>w.remove()},[]);let Se=Me(re);Je(()=>{if(re===Se.current)return;z.setValue(1),Q.setValue(1);let w=D.parallel([D.timing(z,{toValue:0,duration:450,useNativeDriver:!0}),D.sequence([D.delay(oi),D.timing(Q,{toValue:0,duration:250,useNativeDriver:!0})])]);return w.start(),()=>w.stop()},[re,z,Q]),Je(()=>{let w=te=>D.timing(T,{toValue:te,duration:ni,easing:Ot.inOut(Ot.quad),useNativeDriver:!0}),k=D.loop(D.sequence([w(1),w(0)]));return k.start(),()=>k.stop()},[T]);let Ee=$o(()=>{D.timing(y,{toValue:0,duration:220,useNativeDriver:!0}).start()},[y]);Je(()=>{let w=setTimeout(Ee,si);return()=>clearTimeout(w)},[Ee]);let[Ye,$t]=Ct(!1);Je(()=>{let w=requestAnimationFrame(()=>{w=requestAnimationFrame(()=>$t(!0))});return()=>cancelAnimationFrame(w)},[]);let Ue=!!(u!=null&&u.hasTorch),Xe=(f=u==null?void 0:u.neutralZoom)!=null?f:1,Ze=u?Math.min(u.maxZoom/Xe,ii):1,zt=Xe*Math.min(v,Ze),wt=w=>{var ne;let{touches:k}=w.nativeEvent;if(k.length!==2){O.current=null;return}let te=Math.hypot(k[0].pageX-k[1].pageX,k[0].pageY-k[1].pageY);(ne=O.current)!=null||(O.current={distance:te,level:v}),A(Math.max(1,Math.min(Ze,O.current.level*(te/O.current.distance))))},bt=E(pt,{style:[_.hint,!!S&&_.hint_notice],numberOfLines:1,children:(b=S!=null?S:l)!=null?b:ei});return E(D.View,{ref:x,onTouchMove:wt,onTouchEnd:()=>{O.current=null},pointerEvents:t?"none":"auto",style:d?[_.top,g&&_.top_absolute,t&&{height:h}]:_.full,onLayout:({nativeEvent:{layout:w}})=>{var k;t||(o==null||o(w.height),(k=x.current)==null||k.measureInWindow((te,ne)=>{X({width:w.width,height:w.height,window_y:ne||0})}))},children:ve($,{style:t?[_.content_closing,{height:N.height}]:_.content,children:[u&&Ye&&E(r.Camera,{style:fn.absoluteFill,device:u,isActive:!Z,codeScanner:We,torch:P&&Ue?"on":"off",zoom:zt,onPreviewStarted:Ee,onError:w=>wo(w.message)}),E(D.View,{style:[_.preview_cover,{opacity:y}],pointerEvents:"none"}),N.height>0&&ve($,{style:_.overlay,pointerEvents:"none",children:[E($,{style:[_.dim_ring,{top:_e-Ge,left:Ae-Ge,width:K+Ge*2,height:ee+Ge*2}]}),ve($,{style:{position:"absolute",top:_e,left:Ae,width:K,height:ee},children:[E(Wo,{color:"#FFFFFF"}),E(D.View,{style:[fn.absoluteFill,{opacity:z}],children:E(Wo,{color:ut})}),ve(D.View,{style:[_.scan_line_wrap,{transform:[{translateY:T.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,ee-It)]})}]}],children:[E($,{style:_.scan_glow_outer}),E($,{style:_.scan_glow_inner}),E($,{style:_.scan_line})]})]}),E($,{style:[_.hint_slot,d?{top:0,height:_e-6,justifyContent:"flex-end"}:{top:_e+ee+20}],children:bt}),a===Ie.continuous&&!!xe&&E(D.View,{style:[_.result_slot,{top:d?_e+ee-ri:_e+ee+52},{opacity:Q}],children:ve($,{style:_.result,children:[E($,{style:_.check_badge,children:E($,{style:_.check_mark})}),E(pt,{style:_.result_text,numberOfLines:1,children:xe}),ve(pt,{style:_.result_count,children:["\xB7 ",p," m\xE3"]})]})})]}),N.height>0&&E($,{style:[_.close_slot,d?_.close_slot_top:{top:Math.max(12,fe-N.window_y+12)}],children:ve(kt,{style:[_.close_button,!!s&&_.glass_surface],onPress:tn,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&E(s,{style:_.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),E($,{style:[_.close_bar,_.close_bar_a]}),E($,{style:[_.close_bar,_.close_bar_b]})]})}),E($,{style:[_.toolbar_wrap,!d&&{bottom:ie.bottom+20}],pointerEvents:"box-none",children:ve($,{style:[_.toolbar,!!s&&_.glass_surface],children:[s&&E(s,{style:_.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),E(kt,{style:_.tool,onPress:bo,disabled:Z,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:ve($,{style:_.image_icon,children:[E($,{style:_.image_icon_dot}),E($,{style:_.image_icon_hill})]})}),!!u&&Ze>=zo&&E(kt,{style:[_.tool,v>1&&_.tool_on],onPress:()=>A(w=>w>1?1:zo),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:ve(pt,{style:[_.zoom_text,v>1&&_.zoom_text_on],children:[Math.round(v*10)/10,"x"]})}),Ue&&E(kt,{style:[_.tool,P&&_.tool_on],onPress:()=>M(w=>!w),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:P},children:E(pt,{style:[_.torch_icon,P&&_.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},li="rgba(0,0,0,0.5)",mn=50,_=fn.create({top:{height:`${jo*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:Ge,borderColor:li,borderRadius:Ge+dt},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:It,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:It,borderRadius:It/2,backgroundColor:ut,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:ut,opacity:.2},scan_line:{height:ti,borderRadius:1,backgroundColor:ut},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:mn,height:mn,borderRadius:mn/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:ut},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}});import{useEffect as Ho,useRef as gt,useState as Jo}from"react";import{AccessibilityInfo as ui,Animated as H,Platform as di,StyleSheet as Go,Text as gi,View as $e}from"react-native";import{Fragment as Xo,jsx as se,jsxs as wn}from"react/jsx-runtime";var yn={[he.info]:"#3B82F6",[he.success]:"#22C55E",[he.error]:"#EF4444"},Ko=-120,Lt=di.OS==="android",Yo=({type:e})=>e===he.success?se($e,{style:Y.check_mark}):e===he.error?wn(Xo,{children:[se($e,{style:[Y.cross_bar,Y.cross_a]}),se($e,{style:[Y.cross_bar,Y.cross_b]})]}):wn(Xo,{children:[se($e,{style:Y.info_dot}),se($e,{style:Y.info_bar})]}),Zo=()=>{let e=V(ot,h=>h.message),t=V(ot,h=>h.type),n=V(ot,h=>h.tick),o=gt(new H.Value(Ko)).current,r=gt(new H.Value(0)).current,i=gt(new H.Value(.92)).current,a=gt(new H.Value(0)).current,[c,l]=Jo(),[s,g]=Jo(!1);Ho(()=>{let h=!0;return en().then(u=>{h&&u&&l(()=>u)}),()=>{h=!1}},[]);let d=gt(n);return Ho(()=>{if(n===d.current)return;ui.announceForAccessibility(e),g(!0),a.setValue(0),i.setValue(.92);let h=H.sequence([H.parallel([H.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),H.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),H.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),H.sequence([H.delay(90),H.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),H.delay(to[t]),H.parallel([H.timing(o,{toValue:Ko,duration:240,useNativeDriver:!0}),H.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return h.start(({finished:u})=>{u&&g(!1)}),()=>h.stop()},[n]),s?se($e,{style:[Y.layer,{top:xt().top+(Lt?12:8)}],pointerEvents:"none",children:wn(H.View,{style:[Y.toast,Lt&&Y.toast_android,!!c&&Y.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&se(c,{style:Y.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Lt?se(H.View,{style:[Y.badge_halo,{backgroundColor:`${yn[t]}33`,transform:[{scale:a}]}],children:se($e,{style:[Y.badge,{backgroundColor:yn[t]}],children:se(Yo,{type:t})})}):se(H.View,{style:[Y.badge,{backgroundColor:yn[t],transform:[{scale:a}]}],children:se(Yo,{type:t})}),se(gi,{style:[Y.message,Lt&&Y.message_android],numberOfLines:2,children:e})]})}):null},Y=Go.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:Go.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ae=ke({active_key:null,instances:{}}),Qo=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=F().keep_alive)==null?void 0:c.max_webviews;ae.setState(l=>{let s=t!=null?t:e.app_id,g={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},d=Object.keys(g);return a&&a>0&&d.length>a&&d.filter(h=>h!==s).sort((h,u)=>g[h].last_used_at-g[u].last_used_at).slice(0,d.length-a).forEach(h=>{delete g[h]}),i?{active_key:s,instances:g}:{instances:g}})},mi=e=>Qo(e,!0),fi=e=>Qo(e,!1),mt=()=>ae.setState({active_key:null}),Ft=e=>{ae.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var er="catalog",hi="paused_apps",yi="removed_apps",wi=10*1e3,bi=2,_i=3e3,Ai=()=>{var e;try{return JSON.parse((e=F().storage.getString(er))!=null?e:"{}")}catch{return{}}},C=ke({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),tr=e=>{var t;return!!((t=F().manual_update)!=null&&t.includes(e))},Ut=new Set,nr=e=>{let t=new Set,n=()=>F().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=F().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},we=nr(hi),Ne=nr(yi);kn(()=>{we.load(),Ne.load();let e=Ai(),t={};Object.keys(e).filter(n=>!Ne.has(n)).forEach(n=>{let o=L(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:we.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),C.setState({catalog:e,downloads:t})});var _n=e=>V(C,t=>e?t.downloads[e]:void 0),Si=()=>V(C,e=>e.pause_reasons.length>0),ye=(...e)=>ue("queue",...e),J=[],Pe={},R=null,Dt=new Set,ze={},bn=new Set,Fe=e=>{bn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},vi=e=>(bn.add(e),()=>{bn.delete(e)}),Mi=()=>C.getState().downloads,ce=(e,t)=>{let n=!!L(e),o=C.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};C.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?Fe({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Fe({type:"progress",app_id:e,progress:i.progress,version:i.version})},Nt=(e,t)=>{var n;(n=ze[e])==null||n.forEach(o=>o(t)),delete ze[e]},xi=()=>C.getState().pause_reasons.length>0,De=e=>{var c;if(R)return;let t=e?J.indexOf(e):xi()?-1:J.findIndex(l=>!we.has(l));if(t<0||t>=J.length)return;let[n]=J.splice(t,1),o=C.getState().catalog[n];if(!o){Nt(n,L(n)),De();return}let r=Date.now();Pe[n]=((c=Pe[n])!=null?c:0)+1,ce(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=gn(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,ce(n,{progress:s/100,version:o.version}))}});R={app_id:n,handle:a,forced:!!e},ye("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{ye("installed",n,o.version,`${Date.now()-r}ms`),ce(n,{status:"installed",progress:1,version:o.version}),Nt(n,l)}).catch(l=>{var g;if(l instanceof He){if(Dt.has(n))return;ye("paused",n),Pe[n]-=1,J.unshift(n),ce(n,{status:we.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((g=l==null?void 0:l.message)!=null?g:l);if(console.warn("[miniapp-queue] failed",n,s),Pe[n]<bi){ce(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var d;J.includes(n)||(R==null?void 0:R.app_id)===n||(J.push(n),De((d=ze[n])!=null&&d.length?n:void 0))},_i);return}ce(n,{status:"failed",progress:0,version:o.version,error:s}),Nt(n,L(n))}).finally(()=>{R=null;let l=J.find(s=>{var g;return(g=ze[s])==null?void 0:g.length});De(l)})},Vt=(e,{front:t=!1}={})=>{if((R==null?void 0:R.app_id)===e)return;let n=J.indexOf(e);if(n>=0){if(!t)return;J.splice(n,1)}t?J.unshift(e):J.push(e)},Ei=async e=>{let{host_id:t,client_token:n}=F(),o=new AbortController,r=setTimeout(()=>o.abort(),wi);try{let i=`${jt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},ft=null,An=()=>(ft!=null||(ft=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(F().channels.map(Ei)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(C.getState().catalog).filter(l=>!o[l]);F().storage.setString(er,JSON.stringify(o)),C.setState({catalog:o}),await Promise.all(r.map(l=>or(l,{by_user:!1}))),r.forEach(l=>Ne.delete(l));let i=Object.keys(o).filter(l=>!Ne.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await dn(l)){ce(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=L(l.app_id);if(tr(l.app_id)&&!Ut.has(l.app_id)&&s&&await Te(s)){ce(l.app_id,{status:"installed",progress:1,version:s.version}),c[l.app_id]={app_id:l.app_id,current_version:s.version,next_version:l.version};continue}a.push(l)}return C.setState({updates:c}),a.forEach(l=>{Pe[l.app_id]=0,ce(l.app_id,{status:we.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Vt(l.app_id)}),ye("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Fe({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Fe({type:"update_available",...l})),De(),{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),Fe({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{ft=null}})()),ft),or=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ne.add(e),Dt.has(e))return;Dt.add(e),we.delete(e);let n=J.indexOf(e);n>=0&&J.splice(n,1),(R==null?void 0:R.app_id)===e&&R.handle.cancel();let o=(c=(a=(r=C.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=L(e))==null?void 0:i.version)!=null?c:"";ce(e,{status:"uninstalling",progress:0,version:o}),await Uo(e),Ft(e),C.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Pe[e],Dt.delete(e),Nt(e,null),ye("uninstalled",e,t?"(user)":"(not in list)"),Fe({type:"uninstalled",app_id:e})},Ri=e=>or(e,{by_user:!0}),Ti=e=>{let t=ht(e);return t?(Ne.delete(e),(R==null?void 0:R.app_id)===e||J.includes(e)||(Pe[e]=0,ce(e,{status:we.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Vt(e),De(),ye("restore",e)),!0):!1},Pi=e=>{if(we.has(e))return;if(we.add(e),ye("pause app",e),(R==null?void 0:R.app_id)===e&&!R.forced){R.handle.cancel();return}let t=C.getState().downloads[e];J.includes(e)&&t&&ce(e,{status:"paused",progress:0,version:t.version})},Ci=e=>{if(!we.delete(e))return;ye("resume app",e);let t=C.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!J.includes(e)&&ht(e)&&(Pe[e]=0,Vt(e)),J.includes(e)&&t&&ce(e,{status:"queued",progress:0,version:t.version}),De()},Oi=e=>{let{pause_reasons:t}=C.getState();t.includes(e)||(C.setState({pause_reasons:[...t,e]}),ye("pause",e),t.length===0&&Fe({type:"pause_change",paused:!0,reasons:[e]}),R&&!R.forced&&R.handle.cancel())},ki=e=>{let{pause_reasons:t}=C.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);C.setState({pause_reasons:n}),ye("resume",e),n.length===0&&Fe({type:"pause_change",paused:!1,reasons:n}),De()},rr=e=>C.getState().updates[e],Ii=async e=>{var n,o;let t=rr(e);Ut.add(e);try{let r=await Bt(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:(C.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),ye("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Ut.delete(e)}},Li=()=>Object.values(C.getState().catalog).map(e=>({...e,installed:!!L(e.app_id),removed_by_user:Ne.has(e.app_id)})),ht=e=>C.getState().catalog[e],Bt=async e=>{let t=ht(e);if(!t)return;if(we.delete(e),Ne.delete(e),await dn(t))return L(e);let n=L(e);if(tr(e)&&!Ut.has(e)&&n&&await Te(n))return n;let o=new Promise(r=>{var i;((i=ze[e])!=null?i:ze[e]=[]).push(r)});return(R==null?void 0:R.app_id)===e?R.forced=!0:(Pe[e]=0,Vt(e,{front:!0}),R&&!R.forced?R.handle.cancel():De(e)),o};import{Fragment as En,jsx as G,jsxs as Ke}from"react/jsx-runtime";var vn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),sr=0,Bi=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},qi=Rn.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:g})=>{var wt,bt;let d=be(null),h=be(!1),u=V(ae,f=>f.instances[e]),y=u==null?void 0:u.app.app_id,P=u==null?void 0:u.app.manifest_url,M=u==null?void 0:u.context,v=u==null?void 0:u.url_params,A=V(j,f=>{var b;return((b=f.active)==null?void 0:b.owner)===e?f.active:null}),[O,N]=Ce(null),[X,xe]=Ce(A);A!==X&&(xe(A),A?N(null):(X==null?void 0:X.layout)===ge.top&&N(X));let re=(A==null?void 0:A.layout)===ge.top?A:O,[p,S]=Ce(()=>y?L(y):null),[Z,x]=Ce(!1),[ie,fe]=Ce(0),[z,T]=Ce(0),[Q,B]=Ce(!1),K=be(null),ee=f=>{K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{K.current=null,B(!0)},f)};le(()=>()=>{K.current&&clearTimeout(K.current)},[]),le(()=>{if(!y||!t&&p)return;let f=!0;return x(!1),(async()=>{let b=L(y),w=b?await Te(b):!1;if(!f||(S(w?ne=>!ne||ne.version!==b.version||ne.permissions.join(",")!==b.permissions.join(",")?b:ne:null),__DEV__&&Date.now()-sr>1e4&&(sr=Date.now(),await An()),!f))return;let k=await Bt(y),te=k!==void 0?k:P?await Bo(y,P):L(y);if(f){if(!te){x(!0);return}S(ne=>ne!=null?ne:te)}})(),()=>{f=!1}},[t,y,P,ie]),le(()=>qo(e,f=>d.current?(d.current.postMessage(f),!0):!1),[e]);let _e=V(C,f=>{let b=y?f.downloads[y]:void 0;return(b==null?void 0:b.status)==="installed"?b.version:void 0});le(()=>{if(t||!y||!p)return;let f=L(y);if(!f||f.version===p.version)return;let b=!0;return Te(f).then(w=>{!b||!w||(ue(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",p.version,"\u2192",f.version),S(f))}),()=>{b=!1}},[t,y,_e,p==null?void 0:p.version]);let Ae=V(C,f=>{var b;return y&&(b=f.apply_ticks[y])!=null?b:0});le(()=>{if(!Ae||!y)return;let f=L(y);if(!f||f.version===(p==null?void 0:p.version))return;let b=!0;return Te(f).then(w=>{!b||!w||(ue(`webview:${e}`,"c\u1EADp nh\u1EADt",p==null?void 0:p.version,"\u2192",f.version),B(!1),S(f))}),()=>{b=!1}},[Ae]),le(()=>{var w;let f=(w=F().keep_alive)==null?void 0:w.idle_close_ms;if(t||!f||f<=0)return;let b=setTimeout(()=>{Ft(e)},f);return()=>clearTimeout(b)},[t,e]),le(()=>{r>0&&(x(!1),B(!1),T(f=>f+1),fe(f=>f+1))},[r]);let We=be(t);le(()=>{var f;We.current!==t&&(We.current=t,h.current&&((f=d.current)==null||f.injectJavaScript(To(t?"resumed":"paused"))))},[t]);let Se=`${(wt=p==null?void 0:p.version)!=null?wt:"none"}:${(bt=p==null?void 0:p.permissions.join(","))!=null?bt:""}:${z}`,Ee=qt(()=>JSON.stringify([M!=null?M:{},v!=null?v:{}]),[M,v]),Ye=qt(()=>{var f;return Io(v!=null?v:{},(f=p==null?void 0:p.permissions)!=null?f:[])},[Ee,p==null?void 0:p.permissions]),$t=qt(()=>Oo(M!=null?M:{},Ye)+Eo()+Ro()+(F().debug?xo():""),[Ye]),Ue=be(null),Xe=be(null);le(()=>{var b,w,k;if(!p)return;if(Xe.current!==Se){Xe.current=Se,Ue.current=Ee;return}if(Ue.current===Ee)return;let f=((w=JSON.parse((b=Ue.current)!=null?b:"[]")[0])!=null?w:{}).org_id;if(Ue.current=Ee,f===(M==null?void 0:M.org_id)&&h.current){B(!1),ee(1500),(k=d.current)==null||k.injectJavaScript(Po(M!=null?M:{},Ye));return}B(!1),T(te=>te+1)},[Ee,p,Se]),le(()=>(t||(Re(e),Le(e),qe(e)),()=>{Re(e),Le(e),qe(e)}),[t,e,Se,r]),le(()=>{let f=ir.addEventListener("change",b=>{b==="background"&&!io()&&Re(e),b==="background"&&!uo()&&Le(e)});return()=>f.remove()},[e]);let Ze=Mn(async f=>{var w,k,te,ne,Wt,Pn;let b=Ao(f.nativeEvent.data);if(!b){if(y&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(f.nativeEvent.data,{app_id:y,instance_id:e})).catch(U=>{console.warn("[miniapp] onWebEvent l\u1ED7i",y,U)})}catch(U){console.warn("[miniapp] onWebEvent l\u1ED7i",y,U)}return}if(b.method==="log"){let{level:U,text:q}=b;ue(`web:${e}`,U!=null?U:"log",q!=null?q:"");return}if(b.method==="pong"){K.current||B(!0);return}if(b.method==="touchAtTop"){i.emit(!!b.at_top);return}if(b.method==="contextApplied"){K.current&&clearTimeout(K.current),K.current=null,B(!0);return}if(b.method==="ready"){h.current=!0,B(!0);let U=(w=ae.getState().instances[e])==null?void 0:w.context;U&&((k=d.current)==null||k.injectJavaScript(rn(U)));return}try{let U=await Fo(b,{getHostData:()=>{var q,pe;return(pe=(q=ae.getState().instances[e])==null?void 0:q.host_data)!=null?pe:{}},getPermissions:()=>{var q,pe;return y?(pe=(q=L(y))==null?void 0:q.permissions)!=null?pe:[]:[]},getContext:()=>{var q,pe;return(pe=(q=ae.getState().instances[e])==null?void 0:q.context)!=null?pe:{}},is_dark:o,close:mt,app_id:y!=null?y:"",instance_id:e,options:c,emit:(q,pe)=>{var Cn;(Cn=d.current)==null||Cn.injectJavaScript(Mo(q,pe))},playBeep:(te=c==null?void 0:c.playScannerBeep)!=null?te:(()=>{var q;(q=d.current)==null||q.injectJavaScript(Lo())}),isActive:()=>ae.getState().active_key===e&&ir.currentState!=="background"});b.id&&((ne=d.current)==null||ne.injectJavaScript(So(b.id,U)))}catch(U){if(!b.id)return;let q=U==null?void 0:U.code,pe=U instanceof m?U:new m(typeof q=="string"?q:"HOST_ERROR",String((Wt=U==null?void 0:U.message)!=null?Wt:U));(Pn=d.current)==null||Pn.injectJavaScript(vo(b.id,pe))}},[e,o,y,i,c]),zt=Mn(()=>{x(!1),T(f=>f+1),fe(f=>f+1)},[]);return Ke(xn,{style:[Tn.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&me.behind],pointerEvents:t?"auto":"none",children:[re&&G(hn,{scanner:re,closing:re===O,onClosed:()=>{var f;N(null),re.absolute&&((f=d.current)==null||f.injectJavaScript(sn(0)))},onHeight:re.absolute?f=>{var b;return(b=d.current)==null?void 0:b.injectJavaScript(sn(f))}:void 0}),p?G(Vi,{ref:d,source:{uri:p.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?ln():p.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:$t,onMessage:Ze,bounces:!1,overScrollMode:"never",onLoadStart:f=>{Re(e),Le(e),qe(e),ue(`webview:${e}`,"load start",vn(f.nativeEvent.url)),h.current=!1,B(!1)},onError:f=>{Re(e),Le(e),qe(e),ue(`webview:${e}`,"load error",vn(f.nativeEvent.url),f.nativeEvent.description),x(!0),B(!1)},onLoadEnd:f=>{let b=f.nativeEvent.url;ue(`webview:${e}`,"load end",vn(b)),y&&(g==null||g({app_id:y,instance_id:e,url:b})),ee(1500)},onContentProcessDidTerminate:()=>{Re(e),Le(e),qe(e),h.current=!1,B(!1),T(f=>f+1)},onRenderProcessGone:()=>(Re(e),Le(e),qe(e),h.current=!1,B(!1),T(f=>f+1),!0),style:me.webview},Se):null,(A==null?void 0:A.layout)===ge.full&&G(hn,{scanner:A}),u&&G(zi,{visible:!p||!Q,interactive:Z,children:G($i,{splash:a,app:u.app,is_dark:o,error:Z,has_bundle:!!p,retry:zt})})]})}),$i=Rn.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=_n(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return G(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),zi=({visible:e,interactive:t,children:n})=>{let o=be(new Sn.Value(e?1:0)).current,[r,i]=Ce(e);return le(()=>{if(e){i(!0),o.setValue(1);return}let a=Sn.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?G(Sn.View,{style:[Tn.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},cr=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return Ke(xn,{style:[me.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[G(xn,{style:[me.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?G(Ni,{source:{uri:e.icon},style:me.splash_icon_image}):G(yt,{style:me.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),G(yt,{style:[me.splash_name,{color:i}],children:e.name}),n==="error"?Ke(En,{children:[G(yt,{style:me.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),G(Ui,{activeOpacity:.7,style:[me.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:G(yt,{style:[me.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):Ke(En,{children:[G(Fi,{style:me.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&Ke(yt,{style:me.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},ar=(e,t)=>{let n=be(t),o=be(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},Wi=({container:e,splash:t=cr,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{ar("container",e),ar("splash",t);let l=e,s=V(ae,A=>A.active_key),g=be(s);s&&(g.current=s);let d=V(ae,A=>Object.keys(A.instances).join("|")),h=V(ae,A=>{var O;return A.active_key?(O=A.instances[A.active_key])==null?void 0:O.app.name:void 0}),u=qt(()=>d?d.split("|"):[],[d]),[y,P]=Ce({}),M=be(Bi()).current;le(()=>{if(!s||!r)return;let A=Di.addEventListener("hardwareBackPress",()=>(mt(),!0));return()=>A.remove()},[s,r]);let v=Mn(()=>{let A=ae.getState().active_key;A&&P(O=>({...O,[A]:(O[A]||0)+1}))},[]);return u.length?Ke(En,{children:[G(l,{visible:!!s,title:h!=null?h:"",is_dark:n,close:mt,reload:v,subscribeWebAtTop:M.subscribe,children:u.map(A=>G(qi,{instance_key:A,is_active:s===A,is_front:(s!=null?s:g.current)===A,is_dark:n,reload_tick:y[A]||0,web_at_top:M,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},A))}),G(Zo,{})]}):null},me=Tn.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"}}),ji=Rn.memo(Wi);export{oe as CodeType,cr as DefaultMiniAppSplash,jt as MINIAPP_PLATFORM_URL,ji as MiniAppHost,m as MiniAppHostError,je as ScannerEndReason,Xt as ScannerEvent,ge as ScannerLayout,it as ScannerMethod,he as ToastType,mt as closeMiniApp,lr as configureMiniApp,ur as createMmkvStorage,In as createReactNativeBiometrics,pr as createRnfsFileSystem,Bt as ensureMiniApp,L as getLocalMiniApp,Li as getMiniAppCatalog,ht as getMiniAppCatalogEntry,Mi as getMiniAppStatuses,rr as getMiniAppUpdate,Gr as installBundledMiniApp,vi as onMiniAppEvent,mi as openMiniApp,Pi as pauseMiniApp,Oi as pauseMiniAppDownloads,fi as preloadMiniApp,Re as releaseSpeechFor,Ti as restoreMiniApp,Ci as resumeMiniApp,ki as resumeMiniAppDownloads,Yr as sendEventToWeb,An as syncMiniAppCatalog,Ri as uninstallMiniApp,Ii as updateMiniApp,Kn as uploadToUrl,_n as useMiniAppDownload,Si as useMiniAppDownloadsPaused};
88
+ })(); true;`,Gr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Pt=(e,t)=>{if(typeof e!="string"||!e)throw new m("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},Uo=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:g,isActive:d,playBeep:h})=>{var v,A,O,U,Z,xe,re;let u=s==null?void 0:s.handlers,y={app_id:c,instance_id:l,close:a},T=()=>{var p;(p=s==null?void 0:s.haptic)==null||p.call(s,"impactLight"),h==null||h()},M=()=>new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let p=Fn(t);return st(e,()=>Dn(p,d))}case"speech.start":{if(!g)throw M();let p={};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 m("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");p.lang=t.lang}for(let L of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[L])!==void 0){if(typeof t[L]!="boolean")throw new m("INVALID_PARAMS",`${L} ph\u1EA3i l\xE0 boolean`);p[L]=t[L]}let S=s==null?void 0:s.speech;if(S){so(l,S);try{return await S.start({owner:l,app_id:c,options:p,emit:g,isActive:d!=null?d:(()=>!0)})}catch(L){throw ao(l),L}}return lo(l,p,g,d)}case"speech.stop":return s!=null&&s.speech?s.speech.stop(l):po(l);case it.scan:return wo(l,Qt(t),d,T);case it.start:{if(!g)throw M();return bo(l,Qt(t),g,d,T)}case it.stop:return _o(l);case"uploadFiles":{let{task_id:p,...S}=t!=null?t:{};if(p!==void 0&&(typeof p!="string"||!p))throw new m("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return to(jn(S),{instance_id:l,app_id:c,getContext:r,task_id:p,config:s==null?void 0:s.upload,emit:g,exclusivePick:L=>st("uploadFiles.pick",L)})}case"uploadFiles.cancel":eo(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Zn(s==null?void 0:s.upload);case"getBiometricAvailability":return((v=s==null?void 0:s.biometrics)!=null?v:await Jt()).getAvailability();case"authenticateBiometric":{let p=Pt(t==null?void 0:t.reason,"reason").trim();if(!p||p.length>200)throw new m("INVALID_PARAMS","reason must contain 1\u2013200 characters");let S=t==null?void 0:t.cancelButtonText;if(S!==void 0&&(typeof S!="string"||!S.trim()||S.length>80))throw new m("INVALID_PARAMS","Invalid cancelButtonText");return st(e,async()=>{var x;return((x=s==null?void 0:s.biometrics)!=null?x:await Jt()).authenticate({reason:p,cancelButtonText:S})})}case"requestPayment":{let p=u==null?void 0:u.requestPayment;if(!p)throw M();let S=t==null?void 0:t.amount;if(typeof S!="number"||!Number.isFinite(S)||S<=0)throw new m("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let L={...t,amount:S,currency:Pt(t==null?void 0:t.currency,"currency")};return st(e,()=>p(L,y))}case"printImage":{let p=u==null?void 0:u.printImage;if(!p)throw M();let S=Pt(t==null?void 0:t.image,"image");await st(e,()=>p({image:S},y));return}case"openScreen":if(!(u!=null&&u.openScreen))throw M();await u.openScreen({screen:Pt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},y);return;case"closeApp":a();return;case"openWebview":{let p=String((A=t==null?void 0:t.url)!=null?A:"");if(!/^https?:\/\//i.test(p))throw new m("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(p):vo.openURL(p));return}case"openLink":{let p=String((O=t==null?void 0:t.url)!=null?O:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(p)||/^(javascript|file|data|about|blob):/i.test(p))throw new m("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(p):vo.openURL(p))}catch(S){throw new m("NOT_SUPPORTED",String((Z=(U=S==null?void 0:S.message)!=null?U:S)!=null?Z:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let p=oo(t);if(!p||(d==null?void 0:d())===!1)return;s!=null&&s.showToast?s.showToast(p.message,{type:p.type}):ro(p.message,p.type);return}case"haptic":{let p=Gr.has(t==null?void 0:t.type)?t.type:"selection";(xe=s==null?void 0:s.haptic)==null||xe.call(s,p);return}case"getSystemInfo":return{platform:Jr.OS==="ios"?"ios":"android",appVersion:(re=s==null?void 0:s.app_version)!=null?re:"",theme:i?"dark":"light"};case"getAccessToken":{let p=n().access_token;if(!p)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return p}case"getToken":{let p=t==null?void 0:t.type;if(p==="access"){let x=n().access_token;if(!x)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return x}if(p!=="partner"&&p!=="chatbox")throw new m("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(p)}`);let S=Fo[p];if(!o().includes(S))throw new m("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${S} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let L=p==="partner"?n().partner_token:n().chatbox_token;if(!L)throw new m("HOST_ERROR",`Kh\xF4ng c\xF3 ${S}`);return L}case"getUserInfo":{let p=n().user;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return p}case"getPageInfo":{let p=n().page;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return p}case"sendMessage":case"insertText":throw new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new m("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var ln=e=>`bundle:${e}`,pn=()=>`${D().file_system.document_dir}/miniapps`,un=pn,dn=(e,t,n="index.html",o=!1,r=[])=>{let i=`${un()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},cn=e=>{var t;D().storage.setString(ln(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Kr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,F=e=>{let t=D().storage.getString(ln(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return dn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Pe=e=>D().file_system.exists(e.entry_uri.replace("file://","")),gn=async e=>{let t=F(e.app_id);return(t==null?void 0:t.version)===e.version&&await Pe(t)},Bo=async(e,t)=>{let n=D().file_system,o=`${un()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},qo=async e=>{var t;await((t=lt[e])==null?void 0:t.catch(()=>{})),D().storage.setString(ln(e),""),await D().file_system.remove(`${un()}/${e}`).catch(()=>{})},He=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},lt={},$o=(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},Yr=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let c=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(c)return c}return 0},Xr=({manifest:e,zip_path:t})=>$o(e.app_id,async()=>{var i;let n=D().file_system,o=F(e.app_id);if(o&&Yr(o.version,e.version)>=0&&await Pe(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=dn(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),cn(e),ue("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),Bo(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),mn=(e,{base_url:t,onProgress:n}={})=>{let o=D().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new He},l=async()=>{var d;c();let s=F(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return cn(e),F(e.app_id);c();let g=o.download({url:t?Kr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(h,u)=>{var T;let y=u>0?u:(T=e.size)!=null?T:0;y>0&&(n==null||n(Math.min(1,h/y)))}});r=g;try{let{status:h}=await g.promise;if(c(),h!==200)throw new Error(`bundle ${h}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else ue("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let u=dn(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(a,u.dir),cn(e),Bo(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),u}catch(h){throw i?new He:h}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:$o(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},ct={},Zr=__DEV__?0:60*1e3,Vo={},zo=(e,t)=>{var o,r;let n=F(e);return n&&Date.now()-((o=Vo[t])!=null?o:0)<Zr?Promise.resolve(n):((r=ct[e])!=null||(ct[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),c=await mn(a,{base_url:t}).promise;return Vo[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),F(e))).finally(()=>{ct[e]=void 0})),ct[e])};var Ct=new Map,Wo=(e,t)=>(Ct.set(e,t),()=>{Ct.get(e)===t&&Ct.delete(e)}),Qr=(e,t)=>{let n=Ct.get(e);return n?n(t):!1};import{useCallback as jo,useEffect as Je,useRef as Me,useState as Ot}from"react";import{Animated as N,BackHandler as ei,Dimensions as ti,Easing as kt,Pressable as ni,StyleSheet as hn,Text as pt,View as z}from"react-native";import{Fragment as gi,jsx as E,jsxs as ve}from"react/jsx-runtime";var ut="#22C55E",oi="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",ri=2,Lt=18,ii=1600,dt=14,si=2e3,Go=.38,ai=40,Ho=2,ci=8,li=2e3,pi=250,Ge=2e3,ui=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:dt},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:dt},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:dt},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:dt}],Jo=({color:e})=>E(gi,{children:ui.map((t,n)=>E(z,{style:[_.corner,t,{borderColor:e}]},n))}),It=({style:e,children:t,...n})=>{let o=Me(new N.Value(1)).current,r=i=>N.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return E(ni,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:E(N.View,{style:[e,{transform:[{scale:o}]}],children:t})})},yn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var f,b;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:g}=e,d=c===ge.top,h=Me(new N.Value(0)).current,u=r.useCameraDevice("back"),y=Me(new N.Value(1)).current,[T,M]=Ot(!1),[v,A]=Ot(1),O=Me(null),[U,Z]=Ot(()=>{let{width:w,height:k}=ti.get("window");return{width:w,height:d?k*Go:k,window_y:0}}),xe=B(H,w=>w.last_value),re=B(H,w=>w.hit_tick),p=B(H,w=>w.scan_count),S=B(H,w=>w.notice),L=B(H,w=>w.is_picking),x=Me(null),ie=Et(),fe=ie.top,W=Me(new N.Value(0)).current,P=Me(new N.Value(0)).current,Q=Me(new N.Value(0)).current,q=Me(n);q.current=n,Je(()=>{if(!t)return;h.setValue(U.height);let w=N.timing(h,{toValue:0,duration:pi,easing:kt.out(kt.cubic),useNativeDriver:!1});return w.start(({finished:k})=>{var te;k&&((te=q.current)==null||te.call(q))}),()=>w.stop()},[t,h]);let Y=Math.round(U.width*(d?.8:.78)),ee=Math.round(d?U.height*.46:Y*.78),_e=Math.round((U.height-ee)/2),Ae=Math.round((U.width-Y)/2),We=r.useCodeScanner({codeTypes:i,onCodeScanned:jo(w=>on(w),[])});Je(()=>{let w=ei.addEventListener("hardwareBackPress",()=>(nn(),!0));return()=>w.remove()},[]);let Se=Me(re);Je(()=>{if(re===Se.current)return;W.setValue(1),Q.setValue(1);let w=N.parallel([N.timing(W,{toValue:0,duration:450,useNativeDriver:!0}),N.sequence([N.delay(si),N.timing(Q,{toValue:0,duration:250,useNativeDriver:!0})])]);return w.start(),()=>w.stop()},[re,W,Q]),Je(()=>{let w=te=>N.timing(P,{toValue:te,duration:ii,easing:kt.inOut(kt.quad),useNativeDriver:!0}),k=N.loop(N.sequence([w(1),w(0)]));return k.start(),()=>k.stop()},[P]);let Ee=jo(()=>{N.timing(y,{toValue:0,duration:220,useNativeDriver:!0}).start()},[y]);Je(()=>{let w=setTimeout(Ee,li);return()=>clearTimeout(w)},[Ee]);let[Ye,zt]=Ot(!1);Je(()=>{let w=requestAnimationFrame(()=>{w=requestAnimationFrame(()=>zt(!0))});return()=>cancelAnimationFrame(w)},[]);let Ue=!!(u!=null&&u.hasTorch),Xe=(f=u==null?void 0:u.neutralZoom)!=null?f:1,Ze=u?Math.min(u.maxZoom/Xe,ci):1,Wt=Xe*Math.min(v,Ze),wt=w=>{var ne;let{touches:k}=w.nativeEvent;if(k.length!==2){O.current=null;return}let te=Math.hypot(k[0].pageX-k[1].pageX,k[0].pageY-k[1].pageY);(ne=O.current)!=null||(O.current={distance:te,level:v}),A(Math.max(1,Math.min(Ze,O.current.level*(te/O.current.distance))))},bt=E(pt,{style:[_.hint,!!S&&_.hint_notice],numberOfLines:1,children:(b=S!=null?S:l)!=null?b:oi});return E(N.View,{ref:x,onTouchMove:wt,onTouchEnd:()=>{O.current=null},pointerEvents:t?"none":"auto",style:d?[_.top,g&&_.top_absolute,t&&{height:h}]:_.full,onLayout:({nativeEvent:{layout:w}})=>{var k;t||(o==null||o(w.height),(k=x.current)==null||k.measureInWindow((te,ne)=>{Z({width:w.width,height:w.height,window_y:ne||0})}))},children:ve(z,{style:t?[_.content_closing,{height:U.height}]:_.content,children:[u&&Ye&&E(r.Camera,{style:hn.absoluteFill,device:u,isActive:!L,codeScanner:We,torch:T&&Ue?"on":"off",zoom:Wt,onPreviewStarted:Ee,onError:w=>Ao(w.message)}),E(N.View,{style:[_.preview_cover,{opacity:y}],pointerEvents:"none"}),U.height>0&&ve(z,{style:_.overlay,pointerEvents:"none",children:[E(z,{style:[_.dim_ring,{top:_e-Ge,left:Ae-Ge,width:Y+Ge*2,height:ee+Ge*2}]}),ve(z,{style:{position:"absolute",top:_e,left:Ae,width:Y,height:ee},children:[E(Jo,{color:"#FFFFFF"}),E(N.View,{style:[hn.absoluteFill,{opacity:W}],children:E(Jo,{color:ut})}),ve(N.View,{style:[_.scan_line_wrap,{transform:[{translateY:P.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,ee-Lt)]})}]}],children:[E(z,{style:_.scan_glow_outer}),E(z,{style:_.scan_glow_inner}),E(z,{style:_.scan_line})]})]}),E(z,{style:[_.hint_slot,d?{top:0,height:_e-6,justifyContent:"flex-end"}:{top:_e+ee+20}],children:bt}),a===Ie.continuous&&!!xe&&E(N.View,{style:[_.result_slot,{top:d?_e+ee-ai:_e+ee+52},{opacity:Q}],children:ve(z,{style:_.result,children:[E(z,{style:_.check_badge,children:E(z,{style:_.check_mark})}),E(pt,{style:_.result_text,numberOfLines:1,children:xe}),ve(pt,{style:_.result_count,children:["\xB7 ",p," m\xE3"]})]})})]}),U.height>0&&E(z,{style:[_.close_slot,d?_.close_slot_top:{top:Math.max(12,fe-U.window_y+12)}],children:ve(It,{style:[_.close_button,!!s&&_.glass_surface],onPress:nn,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&E(s,{style:_.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),E(z,{style:[_.close_bar,_.close_bar_a]}),E(z,{style:[_.close_bar,_.close_bar_b]})]})}),E(z,{style:[_.toolbar_wrap,!d&&{bottom:ie.bottom+20}],pointerEvents:"box-none",children:ve(z,{style:[_.toolbar,!!s&&_.glass_surface],children:[s&&E(s,{style:_.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),E(It,{style:_.tool,onPress:So,disabled:L,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:ve(z,{style:_.image_icon,children:[E(z,{style:_.image_icon_dot}),E(z,{style:_.image_icon_hill})]})}),!!u&&Ze>=Ho&&E(It,{style:[_.tool,v>1&&_.tool_on],onPress:()=>A(w=>w>1?1:Ho),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:ve(pt,{style:[_.zoom_text,v>1&&_.zoom_text_on],children:[Math.round(v*10)/10,"x"]})}),Ue&&E(It,{style:[_.tool,T&&_.tool_on],onPress:()=>M(w=>!w),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:T},children:E(pt,{style:[_.torch_icon,T&&_.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},di="rgba(0,0,0,0.5)",fn=50,_=hn.create({top:{height:`${Go*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:Ge,borderColor:di,borderRadius:Ge+dt},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:Lt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:Lt,borderRadius:Lt/2,backgroundColor:ut,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:ut,opacity:.2},scan_line:{height:ri,borderRadius:1,backgroundColor:ut},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:fn,height:fn,borderRadius:fn/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:ut},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}});import{useEffect as Ko,useRef as gt,useState as Yo}from"react";import{AccessibilityInfo as mi,Animated as J,Platform as fi,StyleSheet as Xo,Text as hi,View as $e}from"react-native";import{Fragment as er,jsx as se,jsxs as bn}from"react/jsx-runtime";var wn={[he.info]:"#3B82F6",[he.success]:"#22C55E",[he.error]:"#EF4444"},Zo=-120,Ft=fi.OS==="android",Qo=({type:e})=>e===he.success?se($e,{style:X.check_mark}):e===he.error?bn(er,{children:[se($e,{style:[X.cross_bar,X.cross_a]}),se($e,{style:[X.cross_bar,X.cross_b]})]}):bn(er,{children:[se($e,{style:X.info_dot}),se($e,{style:X.info_bar})]}),tr=()=>{let e=B(ot,h=>h.message),t=B(ot,h=>h.type),n=B(ot,h=>h.tick),o=gt(new J.Value(Zo)).current,r=gt(new J.Value(0)).current,i=gt(new J.Value(.92)).current,a=gt(new J.Value(0)).current,[c,l]=Yo(),[s,g]=Yo(!1);Ko(()=>{let h=!0;return tn().then(u=>{h&&u&&l(()=>u)}),()=>{h=!1}},[]);let d=gt(n);return Ko(()=>{if(n===d.current)return;mi.announceForAccessibility(e),g(!0),a.setValue(0),i.setValue(.92);let h=J.sequence([J.parallel([J.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),J.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),J.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),J.sequence([J.delay(90),J.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),J.delay(no[t]),J.parallel([J.timing(o,{toValue:Zo,duration:240,useNativeDriver:!0}),J.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return h.start(({finished:u})=>{u&&g(!1)}),()=>h.stop()},[n]),s?se($e,{style:[X.layer,{top:Et().top+(Ft?12:8)}],pointerEvents:"none",children:bn(J.View,{style:[X.toast,Ft&&X.toast_android,!!c&&X.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&se(c,{style:X.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Ft?se(J.View,{style:[X.badge_halo,{backgroundColor:`${wn[t]}33`,transform:[{scale:a}]}],children:se($e,{style:[X.badge,{backgroundColor:wn[t]}],children:se(Qo,{type:t})})}):se(J.View,{style:[X.badge,{backgroundColor:wn[t],transform:[{scale:a}]}],children:se(Qo,{type:t})}),se(hi,{style:[X.message,Ft&&X.message_android],numberOfLines:2,children:e})]})}):null},X=Xo.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:Xo.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ae=ke({active_key:null,instances:{}}),nr=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=D().keep_alive)==null?void 0:c.max_webviews;ae.setState(l=>{let s=t!=null?t:e.app_id,g={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},d=Object.keys(g);return a&&a>0&&d.length>a&&d.filter(h=>h!==s).sort((h,u)=>g[h].last_used_at-g[u].last_used_at).slice(0,d.length-a).forEach(h=>{delete g[h]}),i?{active_key:s,instances:g}:{instances:g}})},yi=e=>nr(e,!0),wi=e=>nr(e,!1),mt=()=>ae.setState({active_key:null}),Dt=e=>{ae.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var or="catalog",bi="paused_apps",_i="removed_apps",Ai=10*1e3,Si=2,vi=3e3,Mi=()=>{var e;try{return JSON.parse((e=D().storage.getString(or))!=null?e:"{}")}catch{return{}}},C=ke({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),rr=e=>{var t;return!!((t=D().manual_update)!=null&&t.includes(e))},Vt=new Set,ir=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{}}}},we=ir(bi),Ne=ir(_i);In(()=>{we.load(),Ne.load();let e=Mi(),t={};Object.keys(e).filter(n=>!Ne.has(n)).forEach(n=>{let o=F(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:we.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),C.setState({catalog:e,downloads:t})});var An=e=>B(C,t=>e?t.downloads[e]:void 0),xi=()=>B(C,e=>e.pause_reasons.length>0),ye=(...e)=>ue("queue",...e),G=[],Te={},R=null,Nt=new Set,ze={},_n=new Set,Fe=e=>{_n.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Ei=e=>(_n.add(e),()=>{_n.delete(e)}),Ri=()=>C.getState().downloads,ce=(e,t)=>{let n=!!F(e),o=C.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};C.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?Fe({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Fe({type:"progress",app_id:e,progress:i.progress,version:i.version})},Ut=(e,t)=>{var n;(n=ze[e])==null||n.forEach(o=>o(t)),delete ze[e]},Pi=()=>C.getState().pause_reasons.length>0,De=e=>{var c;if(R)return;let t=e?G.indexOf(e):Pi()?-1:G.findIndex(l=>!we.has(l));if(t<0||t>=G.length)return;let[n]=G.splice(t,1),o=C.getState().catalog[n];if(!o){Ut(n,F(n)),De();return}let r=Date.now();Te[n]=((c=Te[n])!=null?c:0)+1,ce(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=mn(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,ce(n,{progress:s/100,version:o.version}))}});R={app_id:n,handle:a,forced:!!e},ye("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{ye("installed",n,o.version,`${Date.now()-r}ms`),ce(n,{status:"installed",progress:1,version:o.version}),Ut(n,l)}).catch(l=>{var g;if(l instanceof He){if(Nt.has(n))return;ye("paused",n),Te[n]-=1,G.unshift(n),ce(n,{status:we.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((g=l==null?void 0:l.message)!=null?g:l);if(console.warn("[miniapp-queue] failed",n,s),Te[n]<Si){ce(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var d;G.includes(n)||(R==null?void 0:R.app_id)===n||(G.push(n),De((d=ze[n])!=null&&d.length?n:void 0))},vi);return}ce(n,{status:"failed",progress:0,version:o.version,error:s}),Ut(n,F(n))}).finally(()=>{R=null;let l=G.find(s=>{var g;return(g=ze[s])==null?void 0:g.length});De(l)})},Bt=(e,{front:t=!1}={})=>{if((R==null?void 0:R.app_id)===e)return;let n=G.indexOf(e);if(n>=0){if(!t)return;G.splice(n,1)}t?G.unshift(e):G.push(e)},Ti=async e=>{let{host_id:t,client_token:n}=D(),o=new AbortController,r=setTimeout(()=>o.abort(),Ai);try{let i=`${Ht}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},ft=null,Sn=()=>(ft!=null||(ft=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(D().channels.map(Ti)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(C.getState().catalog).filter(l=>!o[l]);D().storage.setString(or,JSON.stringify(o)),C.setState({catalog:o}),await Promise.all(r.map(l=>sr(l,{by_user:!1}))),r.forEach(l=>Ne.delete(l));let i=Object.keys(o).filter(l=>!Ne.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await gn(l)){ce(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=F(l.app_id);if(rr(l.app_id)&&!Vt.has(l.app_id)&&s&&await Pe(s)){ce(l.app_id,{status:"installed",progress:1,version:s.version}),c[l.app_id]={app_id:l.app_id,current_version:s.version,next_version:l.version};continue}a.push(l)}return C.setState({updates:c}),a.forEach(l=>{Te[l.app_id]=0,ce(l.app_id,{status:we.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Bt(l.app_id)}),ye("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Fe({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Fe({type:"update_available",...l})),De(),{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),Fe({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{ft=null}})()),ft),sr=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ne.add(e),Nt.has(e))return;Nt.add(e),we.delete(e);let n=G.indexOf(e);n>=0&&G.splice(n,1),(R==null?void 0:R.app_id)===e&&R.handle.cancel();let o=(c=(a=(r=C.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=F(e))==null?void 0:i.version)!=null?c:"";ce(e,{status:"uninstalling",progress:0,version:o}),await qo(e),Dt(e),C.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Te[e],Nt.delete(e),Ut(e,null),ye("uninstalled",e,t?"(user)":"(not in list)"),Fe({type:"uninstalled",app_id:e})},Ci=e=>sr(e,{by_user:!0}),Oi=e=>{let t=ht(e);return t?(Ne.delete(e),(R==null?void 0:R.app_id)===e||G.includes(e)||(Te[e]=0,ce(e,{status:we.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Bt(e),De(),ye("restore",e)),!0):!1},ki=e=>{if(we.has(e))return;if(we.add(e),ye("pause app",e),(R==null?void 0:R.app_id)===e&&!R.forced){R.handle.cancel();return}let t=C.getState().downloads[e];G.includes(e)&&t&&ce(e,{status:"paused",progress:0,version:t.version})},Ii=e=>{if(!we.delete(e))return;ye("resume app",e);let t=C.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!G.includes(e)&&ht(e)&&(Te[e]=0,Bt(e)),G.includes(e)&&t&&ce(e,{status:"queued",progress:0,version:t.version}),De()},Li=e=>{let{pause_reasons:t}=C.getState();t.includes(e)||(C.setState({pause_reasons:[...t,e]}),ye("pause",e),t.length===0&&Fe({type:"pause_change",paused:!0,reasons:[e]}),R&&!R.forced&&R.handle.cancel())},Fi=e=>{let{pause_reasons:t}=C.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);C.setState({pause_reasons:n}),ye("resume",e),n.length===0&&Fe({type:"pause_change",paused:!1,reasons:n}),De()},ar=e=>C.getState().updates[e],Di=async e=>{var n,o;let t=ar(e);Vt.add(e);try{let r=await qt(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:(C.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),ye("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Vt.delete(e)}},Ni=()=>Object.values(C.getState().catalog).map(e=>({...e,installed:!!F(e.app_id),removed_by_user:Ne.has(e.app_id)})),ht=e=>C.getState().catalog[e],qt=async e=>{let t=ht(e);if(!t)return;if(we.delete(e),Ne.delete(e),await gn(t))return F(e);let n=F(e);if(rr(e)&&!Vt.has(e)&&n&&await Pe(n))return n;let o=new Promise(r=>{var i;((i=ze[e])!=null?i:ze[e]=[]).push(r)});return(R==null?void 0:R.app_id)===e?R.forced=!0:(Te[e]=0,Bt(e,{front:!0}),R&&!R.forced?R.handle.cancel():De(e)),o};import{Fragment as Rn,jsx as K,jsxs as Ke}from"react/jsx-runtime";var Mn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),lr=0,zi=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},Wi=Pn.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:g})=>{var wt,bt;let d=be(null),h=be(!1),u=B(ae,f=>f.instances[e]),y=u==null?void 0:u.app.app_id,T=u==null?void 0:u.app.manifest_url,M=u==null?void 0:u.context,v=u==null?void 0:u.url_params,A=B(H,f=>{var b;return((b=f.active)==null?void 0:b.owner)===e?f.active:null}),[O,U]=Ce(null),[Z,xe]=Ce(A);A!==Z&&(xe(A),A?U(null):(Z==null?void 0:Z.layout)===ge.top&&U(Z));let re=(A==null?void 0:A.layout)===ge.top?A:O,[p,S]=Ce(()=>y?F(y):null),[L,x]=Ce(!1),[ie,fe]=Ce(0),[W,P]=Ce(0),[Q,q]=Ce(!1),Y=be(null),ee=f=>{Y.current&&clearTimeout(Y.current),Y.current=setTimeout(()=>{Y.current=null,q(!0)},f)};le(()=>()=>{Y.current&&clearTimeout(Y.current)},[]),le(()=>{if(!y||!t&&p)return;let f=!0;return x(!1),(async()=>{let b=F(y),w=b?await Pe(b):!1;if(!f||(S(w?ne=>!ne||ne.version!==b.version||ne.permissions.join(",")!==b.permissions.join(",")?b:ne:null),__DEV__&&Date.now()-lr>1e4&&(lr=Date.now(),await Sn()),!f))return;let k=await qt(y),te=k!==void 0?k:T?await zo(y,T):F(y);if(f){if(!te){x(!0);return}S(ne=>ne!=null?ne:te)}})(),()=>{f=!1}},[t,y,T,ie]),le(()=>Wo(e,f=>d.current?(d.current.postMessage(f),!0):!1),[e]);let _e=B(C,f=>{let b=y?f.downloads[y]:void 0;return(b==null?void 0:b.status)==="installed"?b.version:void 0});le(()=>{if(t||!y||!p)return;let f=F(y);if(!f||f.version===p.version)return;let b=!0;return Pe(f).then(w=>{!b||!w||(ue(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",p.version,"\u2192",f.version),S(f))}),()=>{b=!1}},[t,y,_e,p==null?void 0:p.version]);let Ae=B(C,f=>{var b;return y&&(b=f.apply_ticks[y])!=null?b:0});le(()=>{if(!Ae||!y)return;let f=F(y);if(!f||f.version===(p==null?void 0:p.version))return;let b=!0;return Pe(f).then(w=>{!b||!w||(ue(`webview:${e}`,"c\u1EADp nh\u1EADt",p==null?void 0:p.version,"\u2192",f.version),q(!1),S(f))}),()=>{b=!1}},[Ae]),le(()=>{var w;let f=(w=D().keep_alive)==null?void 0:w.idle_close_ms;if(t||!f||f<=0)return;let b=setTimeout(()=>{Dt(e)},f);return()=>clearTimeout(b)},[t,e]),le(()=>{r>0&&(x(!1),q(!1),P(f=>f+1),fe(f=>f+1))},[r]);let We=be(t);le(()=>{var f;We.current!==t&&(We.current=t,h.current&&((f=d.current)==null||f.injectJavaScript(Oo(t?"resumed":"paused"))))},[t]);let Se=`${(wt=p==null?void 0:p.version)!=null?wt:"none"}:${(bt=p==null?void 0:p.permissions.join(","))!=null?bt:""}:${W}`,Ee=$t(()=>JSON.stringify([M!=null?M:{},v!=null?v:{}]),[M,v]),Ye=$t(()=>{var f;return Do(v!=null?v:{},(f=p==null?void 0:p.permissions)!=null?f:[])},[Ee,p==null?void 0:p.permissions]),zt=$t(()=>Lo(M!=null?M:{},Ye)+To()+Co()+(D().debug?Po():""),[Ye]),Ue=be(null),Xe=be(null);le(()=>{var b,w,k;if(!p)return;if(Xe.current!==Se){Xe.current=Se,Ue.current=Ee;return}if(Ue.current===Ee)return;let f=((w=JSON.parse((b=Ue.current)!=null?b:"[]")[0])!=null?w:{}).org_id;if(Ue.current=Ee,f===(M==null?void 0:M.org_id)&&h.current){q(!1),ee(1500),(k=d.current)==null||k.injectJavaScript(ko(M!=null?M:{},Ye));return}q(!1),P(te=>te+1)},[Ee,p,Se]),le(()=>(t||(Re(e),Le(e),qe(e)),()=>{Re(e),Le(e),qe(e)}),[t,e,Se,r]),le(()=>{let f=cr.addEventListener("change",b=>{b==="background"&&!co()&&Re(e),b==="background"&&!fo()&&Le(e)});return()=>f.remove()},[e]);let Ze=xn(async f=>{var w,k,te,ne,jt,Cn;let b=Mo(f.nativeEvent.data);if(!b){if(y&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(f.nativeEvent.data,{app_id:y,instance_id:e})).catch(V=>{console.warn("[miniapp] onWebEvent l\u1ED7i",y,V)})}catch(V){console.warn("[miniapp] onWebEvent l\u1ED7i",y,V)}return}if(b.method==="log"){let{level:V,text:$}=b;ue(`web:${e}`,V!=null?V:"log",$!=null?$:"");return}if(b.method==="pong"){Y.current||q(!0);return}if(b.method==="touchAtTop"){i.emit(!!b.at_top);return}if(b.method==="contextApplied"){Y.current&&clearTimeout(Y.current),Y.current=null,q(!0);return}if(b.method==="ready"){h.current=!0,q(!0);let V=(w=ae.getState().instances[e])==null?void 0:w.context;V&&((k=d.current)==null||k.injectJavaScript(sn(V)));return}try{let V=await Uo(b,{getHostData:()=>{var $,pe;return(pe=($=ae.getState().instances[e])==null?void 0:$.host_data)!=null?pe:{}},getPermissions:()=>{var $,pe;return y?(pe=($=F(y))==null?void 0:$.permissions)!=null?pe:[]:[]},getContext:()=>{var $,pe;return(pe=($=ae.getState().instances[e])==null?void 0:$.context)!=null?pe:{}},is_dark:o,close:mt,app_id:y!=null?y:"",instance_id:e,options:c,emit:($,pe)=>{var On;(On=d.current)==null||On.injectJavaScript(Ro($,pe))},playBeep:(te=c==null?void 0:c.playScannerBeep)!=null?te:(()=>{var $;($=d.current)==null||$.injectJavaScript(No())}),isActive:()=>ae.getState().active_key===e&&cr.currentState!=="background"});b.id&&((ne=d.current)==null||ne.injectJavaScript(xo(b.id,V)))}catch(V){if(!b.id)return;let $=V==null?void 0:V.code,pe=V instanceof m?V:new m(typeof $=="string"?$:"HOST_ERROR",String((jt=V==null?void 0:V.message)!=null?jt:V));(Cn=d.current)==null||Cn.injectJavaScript(Eo(b.id,pe))}},[e,o,y,i,c]),Wt=xn(()=>{x(!1),P(f=>f+1),fe(f=>f+1)},[]);return Ke(En,{style:[Tn.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&me.behind],pointerEvents:t?"auto":"none",children:[re&&K(yn,{scanner:re,closing:re===O,onClosed:()=>{var f;U(null),re.absolute&&((f=d.current)==null||f.injectJavaScript(an(0)))},onHeight:re.absolute?f=>{var b;return(b=d.current)==null?void 0:b.injectJavaScript(an(f))}:void 0}),p?K($i,{ref:d,source:{uri:p.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?pn():p.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:zt,onMessage:Ze,bounces:!1,overScrollMode:"never",onLoadStart:f=>{Re(e),Le(e),qe(e),ue(`webview:${e}`,"load start",Mn(f.nativeEvent.url)),h.current=!1,q(!1)},onError:f=>{Re(e),Le(e),qe(e),ue(`webview:${e}`,"load error",Mn(f.nativeEvent.url),f.nativeEvent.description),x(!0),q(!1)},onLoadEnd:f=>{let b=f.nativeEvent.url;ue(`webview:${e}`,"load end",Mn(b)),y&&(g==null||g({app_id:y,instance_id:e,url:b})),ee(1500)},onContentProcessDidTerminate:()=>{Re(e),Le(e),qe(e),h.current=!1,q(!1),P(f=>f+1)},onRenderProcessGone:()=>(Re(e),Le(e),qe(e),h.current=!1,q(!1),P(f=>f+1),!0),style:me.webview},Se):null,(A==null?void 0:A.layout)===ge.full&&K(yn,{scanner:A}),u&&K(Hi,{visible:!p||!Q,interactive:L,children:K(ji,{splash:a,app:u.app,is_dark:o,error:L,has_bundle:!!p,retry:Wt})})]})}),ji=Pn.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=An(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return K(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),Hi=({visible:e,interactive:t,children:n})=>{let o=be(new vn.Value(e?1:0)).current,[r,i]=Ce(e);return le(()=>{if(e){i(!0),o.setValue(1);return}let a=vn.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?K(vn.View,{style:[Tn.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},ur=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return Ke(En,{style:[me.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[K(En,{style:[me.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?K(Bi,{source:{uri:e.icon},style:me.splash_icon_image}):K(yt,{style:me.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),K(yt,{style:[me.splash_name,{color:i}],children:e.name}),n==="error"?Ke(Rn,{children:[K(yt,{style:me.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),K(qi,{activeOpacity:.7,style:[me.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:K(yt,{style:[me.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):Ke(Rn,{children:[K(Ui,{style:me.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&Ke(yt,{style:me.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},pr=(e,t)=>{let n=be(t),o=be(!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.`))},Ji=({container:e,splash:t=ur,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{pr("container",e),pr("splash",t);let l=e,s=B(ae,A=>A.active_key),g=be(s);s&&(g.current=s);let d=B(ae,A=>Object.keys(A.instances).join("|")),h=B(ae,A=>{var O;return A.active_key?(O=A.instances[A.active_key])==null?void 0:O.app.name:void 0}),u=$t(()=>d?d.split("|"):[],[d]),[y,T]=Ce({}),M=be(zi()).current;le(()=>{if(!s||!r)return;let A=Vi.addEventListener("hardwareBackPress",()=>(mt(),!0));return()=>A.remove()},[s,r]);let v=xn(()=>{let A=ae.getState().active_key;A&&T(O=>({...O,[A]:(O[A]||0)+1}))},[]);return u.length?Ke(Rn,{children:[K(l,{visible:!!s,title:h!=null?h:"",is_dark:n,close:mt,reload:v,subscribeWebAtTop:M.subscribe,children:u.map(A=>K(Wi,{instance_key:A,is_active:s===A,is_front:(s!=null?s:g.current)===A,is_dark:n,reload_tick:y[A]||0,web_at_top:M,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},A))}),K(tr,{})]}):null},me=Tn.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"}}),Gi=Pn.memo(Ji);export{oe as CodeType,ur as DefaultMiniAppSplash,Ht as MINIAPP_PLATFORM_URL,Gi as MiniAppHost,m as MiniAppHostError,je as ScannerEndReason,Zt as ScannerEvent,ge as ScannerLayout,it as ScannerMethod,he as ToastType,mt as closeMiniApp,dr as configureMiniApp,mr as createMmkvStorage,Ln as createReactNativeBiometrics,gr as createRnfsFileSystem,qt as ensureMiniApp,F as getLocalMiniApp,Ni as getMiniAppCatalog,ht as getMiniAppCatalogEntry,Ri as getMiniAppStatuses,ar as getMiniAppUpdate,Xr as installBundledMiniApp,Ei as onMiniAppEvent,yi as openMiniApp,ki as pauseMiniApp,Li as pauseMiniAppDownloads,wi as preloadMiniApp,Re as releaseSpeechFor,Oi as restoreMiniApp,Ii as resumeMiniApp,Fi as resumeMiniAppDownloads,Qr as sendEventToWeb,Sn as syncMiniAppCatalog,Ci as uninstallMiniApp,Di as updateMiniApp,Yn as uploadToUrl,An as useMiniAppDownload,xi as useMiniAppDownloadsPaused};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retion-miniapp/react-native",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "React Native host for Retion Mini Apps with built-in biometric authentication",
5
5
  "license": "MIT",
6
6
  "repository": {