var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/pro/comprehensiveSearch/hooks/useScannerGun.ts
var useScannerGun_exports = {};
__export(useScannerGun_exports, {
  SCAN_RESULT_EVENT: () => SCAN_RESULT_EVENT,
  default: () => useScannerGun_default
});
module.exports = __toCommonJS(useScannerGun_exports);
var import_react = require("react");
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var SCAN_RESULT_EVENT = "nativeScanResult";
var useScannerGun = ({ enabled = false, onScan }) => {
  var _a, _b;
  const onScanRef = (0, import_react.useRef)(onScan);
  onScanRef.current = onScan;
  const context = (0, import_useEngineContext.default)();
  const getAppRef = (0, import_react.useRef)(void 0);
  getAppRef.current = typeof ((_b = (_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.utils) == null ? void 0 : _b.getApp) === "function" ? context.appHelper.utils.getApp : void 0;
  (0, import_react.useEffect)(() => {
    if (!enabled) return void 0;
    const getApp = getAppRef.current;
    if (typeof getApp !== "function") return void 0;
    const app = getApp();
    const pubsub = app == null ? void 0 : app.pubsub;
    if (!pubsub || typeof pubsub.subscribe !== "function") {
      return void 0;
    }
    const handler = (payload) => {
      var _a2;
      const data = payload == null ? void 0 : payload.data;
      if (typeof data !== "string" || data.length === 0) {
        return;
      }
      (_a2 = onScanRef.current) == null ? void 0 : _a2.call(onScanRef, payload);
    };
    try {
      pubsub.subscribe(SCAN_RESULT_EVENT, handler);
    } catch (e) {
      console.warn("[ComprehensiveSearch] subscribe scanner failed:", e);
      return void 0;
    }
    return () => {
      var _a2;
      try {
        (_a2 = pubsub.unsubscribe) == null ? void 0 : _a2.call(pubsub, SCAN_RESULT_EVENT, handler);
      } catch (e) {
        console.warn("[ComprehensiveSearch] unsubscribe scanner failed:", e);
      }
    };
  }, [enabled]);
};
var useScannerGun_default = useScannerGun;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SCAN_RESULT_EVENT
});
