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.MINI = "mini", A.FULL = "full", A))(u || {}), P = /* @__PURE__ */ ((A) => (A.RIGHT = "right", A.LEFT = "left", A))(P || {}), d = /* @__PURE__ */ ((A) => (A.USER = "user", A))(d || {}), m = /* @__PURE__ */ ((A) => (A.gallery = "gallery", A.camera = "camera", A))(m || {});
class p {
  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 h {
  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 p(), 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 h();
C.getBrowserMode();
const S = {
  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"
  }
}, Z = 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: S[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 });
  });
}, f = "tokenEx.tokenEx", Q = 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: f
    };
    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);
  });
}, y = {
  path: "/hello.png",
  base64: "data:image/jpeg;base64, "
}, G = {
  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: y
    };
    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 });
  });
}, M = 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: G
    };
    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);
  });
}, k = (A) => {
  C.send(o.RequestCloseApp, A);
}, v = async () => {
  if (!C.checkPremissionEvent(o.RequestVibrate)) {
    const A = {
      type: s.ResponseVibrate,
      status: t.PREMISSION_ERROR
    };
    return Promise.resolve(A);
  }
  C.send(o.RequestVibrate);
}, Y = 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 });
}, K = 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 });
}, b = 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);
  });
}, D = 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 });
  });
}, E = {
  status: "success",
  message: "Tạo đơn hàng thành công"
}, j = 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: E
    };
    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);
  });
}, q = (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);
  };
}, w = {
  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: w
    };
    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);
  });
}, L = 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);
  });
}, U = (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 });
  });
}, O = 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);
  });
}, x = 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 EHeaderMode,
  P as EIconNavigationPosision,
  d as EKeyInfor,
  m as EMediaType,
  t as EStatus,
  o as ETypeRequest,
  s as ETypeResponse,
  Y as call,
  x as clearStore,
  k as closeApp,
  b as configUIApp,
  J as currentLocation,
  C as fltSDK,
  Z as getInfo,
  O as getStore,
  Q as getToken,
  U as listenNotifiactionEvent,
  q as listenPaymentEvent,
  M as openPickerFile,
  z as openPickerImage,
  j as paymentRequest,
  D as premissionsRequest,
  L as requestLocationPermission,
  W as saveStore,
  K as sms,
  v as vibrate
};
