var l = Object.defineProperty;
var R = (A, g, I) => g in A ? l(A, g, { enumerable: !0, configurable: !0, writable: !0, value: I }) : A[g] = I;
var r = (A, g, I) => R(A, typeof g != "symbol" ? g + "" : g, I);
var o = /* @__PURE__ */ ((A) => (A.RequestConfigUIApp = "requestConfigUIApp", A.RequestInfo = "requestInfo", A.RequestToken = "requestToken", A.RequestCloseApp = "requestCloseApp", A.RequestPickerImage = "requestPickerImage", A.RequestPickerFile = "requestPickerFile", A.RequestVibrate = "requestVibrate", A.RequestCall = "requestCall", A.RequestSms = "requestSms", A.RequestLocationPermission = "requestLocationPermission", A.RequestCurrentLocation = "requestCurrentLocation", A.RequestPayment = "requestPayment", A.requestGetPermission = "requestGetPermission", A.requestSaveStore = "requestSaveStore", A.requestGetStore = "requestGetStore", A.requestClearStore = "requestClearStore", A))(o || {}), s = /* @__PURE__ */ ((A) => (A.ResponseConfigApp = "responseConfigUIApp", A.ResponseInfo = "responseInfo", A.ResponseToken = "responseToken", A.ResponsePickerImage = "responsePickerImage", A.ResponsePickerFile = "responsePickerFile", A.ResponseVibrate = "responseVibrate", A.ResponseCall = "responseCall", A.ResponseSms = "responseSms", A.ResponseLocationPermission = "responseLocationPermission", A.ResponseCurrentLocation = "responseCurrentLocation", A.ResponseCloseApp = "responseCloseApp", A.ResponsePayment = "responsePayment", A.ResponseNotification = "responseNotification", A.ResponseGetPermisstion = "responseGetPermisstion", A.responseSaveStore = "responseSaveStore", A.responseGetStore = "responseGetStore", A.responseClearStore = "responseClearStore", A))(s || {}), t = /* @__PURE__ */ ((A) => (A.SUCCESS = "success", A.ERROR = "error", A.PREMISSION_ERROR = "premissionError", A))(t || {}), u = /* @__PURE__ */ ((A) => (A.USER = "user", A))(u || {}), P = /* @__PURE__ */ ((A) => (A.gallery = "gallery", A.camera = "camera", A))(P || {});
class d {
  constructor() {
    r(this, "premissions");
    r(this, "getPremissions", () => ({
      [o.RequestInfo]: !0,
      [o.RequestCloseApp]: !0,
      [o.RequestPickerImage]: !0,
      [o.RequestVibrate]: !0
    }));
    r(this, "checkPremission", (g) => this.premissions[g] ?? !0);
    this.premissions = {}, this.initialize();
  }
  initialize() {
    window.flutter_inappwebview || (this.premissions = this.getPremissions());
  }
}
class m {
  constructor() {
    r(this, "handlers");
    r(this, "isInitialized");
    r(this, "isBrowserMode");
    r(this, "cachedInfo");
    r(this, "infoRequests");
    r(this, "premissionEvent");
    this.handlers = /* @__PURE__ */ new Map(), this.isInitialized = !1, this.isBrowserMode = !1, this.cachedInfo = /* @__PURE__ */ new Map(), this.infoRequests = /* @__PURE__ */ new Map(), this.premissionEvent = new d(), this.initialize();
  }
  initialize() {
    window.flutter_inappwebview ? (this.setupMessageHandler(), this.isInitialized = !0, this.isBrowserMode = !1, this.send(o.RequestInfo, {})) : (this.isInitialized = !0, this.isBrowserMode = !0, console.warn("Flutter channel not found. Running in browser mode."));
  }
  setupMessageHandler() {
    window.receiveFromFlutter = (g) => {
      try {
        const I = JSON.parse(g);
        if (I.type === s.ResponseInfo) {
          this.handleInfoUpdate(I.data);
          return;
        }
        this.handleMessage(I);
      } catch (I) {
        console.error("Error parsing message from Flutter:", I);
      }
    };
  }
  handleInfoUpdate(g) {
    g && Object.entries(g).forEach(([I, e]) => {
      this.cachedInfo.set(I, e), (this.infoRequests.get(I) || []).forEach((i) => i(e)), this.infoRequests.delete(I);
    });
  }
  handleMessage(g) {
    (this.handlers.get(g.type) || []).forEach((e) => {
      try {
        e(g);
      } catch (n) {
        console.error("Error in message handler:", n);
      }
    });
  }
  send(g, I) {
    if (!this.isInitialized) {
      console.error("SDK not initialized");
      return;
    }
    const n = JSON.stringify({ type: g, data: I });
    window.flutter_inappwebview && window.flutter_inappwebview.callHandler("Flutter", n).catch((i) => console.error("Error sending message to Flutter:", i));
  }
  on(g, I) {
    const e = this.handlers.get(g) || [];
    e.push(I), this.handlers.set(g, e);
  }
  off(g, I) {
    const e = this.handlers.get(g) || [], n = e.indexOf(I);
    n > -1 && (e.splice(n, 1), this.handlers.set(g, e));
  }
  getBrowserMode() {
    return this.isBrowserMode;
  }
  getInitialized() {
    return this.isInitialized;
  }
  getCachedInfo(g) {
    return this.cachedInfo.get(g);
  }
  getInfoRequests() {
    return this.infoRequests;
  }
  setInfoRequest(g, I) {
    this.infoRequests.set(g, I);
  }
  checkPremissionEvent(g) {
    return this.premissionEvent.checkPremission(g);
  }
}
const C = new m();
C.getBrowserMode();
const p = {
  user: {
    fullname: "Phạm Văn A",
    identityNumber: "039999963",
    phone: "0355600825",
    gender: 0,
    dob: "2001-11-20",
    address: "Thanh Bình, Phường Hà Đông",
    permanentAddress: "Thôn A, huyện, tỉnh B",
    avatar: "https://badinh.ioc-cloud.com/rs/images/bc3cf657-f537-4f4a-9562-f9bda926d640-1751356836934.jpg"
  }
}, w = async (A) => {
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.RequestInfo)) {
      const e = {
        type: s.ResponseInfo,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(e);
    }
    const I = {
      type: s.ResponseInfo,
      status: t.SUCCESS,
      data: p[A]
    };
    return Promise.resolve(I);
  }
  const g = C.getCachedInfo(A);
  if (g !== void 0) {
    const I = {
      type: s.ResponseInfo,
      status: t.SUCCESS,
      data: g
    };
    return Promise.resolve(I);
  }
  return new Promise((I) => {
    const n = C.getInfoRequests().get(A) || [];
    n.push((i) => {
      const a = {
        type: s.ResponseInfo,
        status: t.SUCCESS,
        data: i
      };
      I(a);
    }), C.setInfoRequest(A, n), C.send(o.RequestInfo, { key: A });
  });
}, h = "tokenEx.tokenEx", B = async () => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.RequestToken)) {
      const g = {
        type: s.ResponseToken,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(g);
    }
    const A = {
      type: s.ResponseToken,
      status: t.SUCCESS,
      data: h
    };
    return Promise.resolve(A);
  }
  return new Promise((A, g) => {
    const I = (e) => {
      e.status === t.ERROR ? g(e) : A(e), C.off(s.ResponseToken, I);
    };
    C.on(s.ResponseToken, I), C.send(o.RequestToken);
  });
}, S = {
  path: "/hello.png",
  base64: "data:image/jpeg;base64, "
}, f = {
  path: "/hello.png",
  size: 12e3,
  base64: "data:image/jpeg;base64, "
}, Z = async (A) => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.RequestPickerImage)) {
      const I = {
        type: s.ResponsePickerImage,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(I);
    }
    const g = {
      type: s.ResponsePickerImage,
      status: t.SUCCESS,
      data: S
    };
    return Promise.resolve(g);
  }
  return new Promise((g, I) => {
    const e = (n) => {
      n.status === t.ERROR ? I(n) : g(n), C.off(s.ResponsePickerImage, e);
    };
    C.on(s.ResponsePickerImage, e), C.send(o.RequestPickerImage, { type: A });
  });
}, Q = async () => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.RequestPickerFile)) {
      const g = {
        type: s.ResponsePickerFile,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(g);
    }
    const A = {
      type: s.ResponsePickerFile,
      status: t.SUCCESS,
      data: f
    };
    return Promise.resolve(A);
  }
  return new Promise((A, g) => {
    const I = (e) => {
      e.status === t.ERROR ? g(e) : A(e), C.off(s.ResponsePickerFile, I);
    };
    C.on(s.ResponsePickerFile, I), C.send(o.RequestPickerFile, void 0);
  });
}, z = (A) => {
  C.send(o.RequestCloseApp, A);
}, M = async () => {
  if (!C.checkPremissionEvent(o.RequestVibrate)) {
    const A = {
      type: s.ResponseVibrate,
      status: t.PREMISSION_ERROR
    };
    return Promise.resolve(A);
  }
  C.send(o.RequestVibrate);
}, k = async (A) => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.RequestCall)) {
      const I = {
        type: s.ResponseCall,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(I);
    }
    window.open(`tel:${A}`);
    const g = {
      type: s.ResponseCall,
      status: t.SUCCESS
    };
    return Promise.resolve(g);
  }
  C.send(o.RequestCall, { phoneNumber: A });
}, v = async (A) => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.RequestSms)) {
      const I = {
        type: s.ResponseSms,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(I);
    }
    window.open(`sms::${A}`);
    const g = {
      type: s.ResponseSms,
      status: t.SUCCESS
    };
    return Promise.resolve(g);
  }
  C.send(o.RequestSms, { phoneNumber: A });
}, Y = async (A) => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    const g = {
      type: s.ResponseConfigApp,
      status: t.SUCCESS
    };
    return Promise.resolve(g);
  }
  return new Promise((g, I) => {
    const e = (n) => {
      n.status === t.ERROR ? I(n) : g(n), C.off(s.ResponseConfigApp, e);
    };
    C.on(s.ResponseConfigApp, e), C.send(o.RequestConfigUIApp, A);
  });
}, K = async (A) => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.requestGetPermission)) {
      const I = {
        type: s.ResponseGetPermisstion,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(I);
    }
    const g = {
      type: s.ResponseGetPermisstion,
      status: t.SUCCESS,
      data: C.checkPremissionEvent(A)
    };
    return Promise.resolve(g);
  }
  return new Promise((g, I) => {
    const e = (n) => {
      n.status === t.ERROR ? I(n) : g(n), C.off(s.ResponseGetPermisstion, e);
    };
    C.on(s.ResponseGetPermisstion, e), C.send(o.requestGetPermission, { type: A });
  });
}, y = {
  status: "success",
  message: "Tạo đơn hàng thành công"
}, b = async (A) => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.RequestPayment)) {
      const I = {
        type: s.ResponsePayment,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(I);
    }
    const g = {
      type: s.ResponsePayment,
      status: t.SUCCESS,
      data: y
    };
    return Promise.resolve(g);
  }
  return new Promise((g, I) => {
    const e = (n) => {
      n.status === t.ERROR ? I(n) : g(n), C.off(s.ResponsePayment, e);
    };
    C.on(s.ResponsePayment, e), C.send(o.RequestPayment, A);
  });
}, D = (A, g) => {
  const I = g || C;
  if (!I.getInitialized())
    throw new Error("SDK not initialized");
  const e = (n) => {
    A(n);
  };
  return I.on(s.ResponsePayment, e), () => {
    I.off(s.ResponsePayment, e);
  };
}, G = {
  latitude: 21.0239852,
  longitude: 105.791488
}, j = async () => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.RequestCurrentLocation)) {
      const g = {
        type: s.ResponseCurrentLocation,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(g);
    }
    const A = {
      type: s.ResponseCurrentLocation,
      status: t.SUCCESS,
      data: G
    };
    return Promise.resolve(A);
  }
  return new Promise((A, g) => {
    const I = (e) => {
      e.status === t.ERROR ? g(e) : A(e), C.off(s.ResponseCurrentLocation, I);
    };
    C.on(s.ResponseCurrentLocation, I), C.send(o.RequestCurrentLocation);
  });
}, q = async () => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.RequestLocationPermission)) {
      const g = {
        type: s.ResponseLocationPermission,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(g);
    }
    const A = {
      type: s.ResponseLocationPermission,
      status: t.SUCCESS
    };
    return Promise.resolve(A);
  }
  return new Promise((A, g) => {
    const I = (e) => {
      e.status === t.ERROR ? g(e) : A(e), C.off(s.ResponseLocationPermission, I);
    };
    C.on(s.ResponseLocationPermission, I), C.send(o.RequestLocationPermission);
  });
}, J = (A, g) => {
  const I = g || C;
  if (!I.getInitialized())
    throw new Error("SDK not initialized");
  const e = (n) => {
    A(n);
  };
  return I.on(s.ResponseNotification, e), () => {
    I.off(s.ResponseNotification, e);
  };
}, c = "mini_app_sdk_x_app", W = async (A) => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.requestSaveStore)) {
      const I = {
        type: s.responseSaveStore,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(I);
    }
    localStorage.setItem(c, A);
    const g = {
      type: s.responseSaveStore,
      status: t.SUCCESS
    };
    return Promise.resolve(g);
  }
  return new Promise((g, I) => {
    const e = (n) => {
      n.status === t.ERROR ? I(n) : g(n), C.off(s.responseSaveStore, e);
    };
    C.on(s.responseSaveStore, e), C.send(o.requestSaveStore, { data: A });
  });
}, U = async () => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.requestGetStore)) {
      const I = {
        type: s.responseGetStore,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(I);
    }
    const A = localStorage.getItem(c), g = {
      type: s.responseGetStore,
      status: t.SUCCESS,
      data: A ?? ""
    };
    return Promise.resolve(g);
  }
  return new Promise((A, g) => {
    const I = (e) => {
      e.status === t.ERROR ? g(e) : A(e), C.off(s.responseGetStore, I);
    };
    C.on(s.responseGetStore, I), C.send(o.requestGetStore);
  });
}, L = async () => {
  if (!C.getInitialized())
    throw new Error("SDK not initialized");
  if (C.getBrowserMode()) {
    if (!C.checkPremissionEvent(o.requestClearStore)) {
      const g = {
        type: s.responseClearStore,
        status: t.PREMISSION_ERROR
      };
      return Promise.resolve(g);
    }
    localStorage.clear();
    const A = {
      type: s.responseClearStore,
      status: t.SUCCESS
    };
    return Promise.resolve(A);
  }
  return new Promise((A, g) => {
    const I = (e) => {
      e.status === t.ERROR ? g(e) : A(e), C.off(s.responseClearStore, I);
    };
    C.on(s.responseClearStore, I), C.send(o.requestClearStore);
  });
};
export {
  u as EKeyInfor,
  P as EMediaType,
  t as EStatus,
  o as ETypeRequest,
  s as ETypeResponse,
  k as call,
  L as clearStore,
  z as closeApp,
  Y as configUIApp,
  j as currentLocation,
  C as fltSDK,
  w as getInfo,
  U as getStore,
  B as getToken,
  J as listenNotifiactionEvent,
  D as listenPaymentEvent,
  Q as openPickerFile,
  Z as openPickerImage,
  b as paymentRequest,
  K as premissionsRequest,
  q as requestLocationPermission,
  W as saveStore,
  v as sms,
  M as vibrate
};
