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/plus/salesSdk/components/SalesSdkGlobalScanSubscriber.tsx
var SalesSdkGlobalScanSubscriber_exports = {};
__export(SalesSdkGlobalScanSubscriber_exports, {
  SalesSdkGlobalScanSubscriber: () => SalesSdkGlobalScanSubscriber,
  default: () => SalesSdkGlobalScanSubscriber_default
});
module.exports = __toCommonJS(SalesSdkGlobalScanSubscriber_exports);
var import_react = require("react");
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var import_SalesSdkContext = require("../context/SalesSdkContext");
var import_SalesSdkUIHostsContext = require("../context/SalesSdkUIHostsContext");
var import_SalesSdkProvider = require("../context/SalesSdkProvider");
var import_useSalesSdkCart = require("../hooks/useSalesSdkCart");
var import_createGlobalScanHostBridge = require("../utils/createGlobalScanHostBridge");
var import_useSalesSdkGlobalScanListener = require("../hooks/useSalesSdkGlobalScanListener");
var SalesSdkGlobalScanSubscriber = ({
  enabled,
  isActive,
  businessCode
}) => {
  var _a, _b, _c;
  const sales = (0, import_react.useContext)(import_SalesSdkContext.SalesSdkContext);
  const uiHosts = (0, import_react.useContext)(import_SalesSdkUIHostsContext.SalesSdkUIHostsContext);
  const refreshRootSnapshot = (0, import_react.useContext)(import_SalesSdkProvider.SalesSdkRootRefreshContext);
  const cart = (0, import_useSalesSdkCart.useSalesSdkCart)();
  const engineContext = (0, import_useEngineContext.default)();
  const Toast = (0, import_materials.useToast)();
  const action = (_b = (_a = engineContext == null ? void 0 : engineContext.appHelper) == null ? void 0 : _a.utils) == null ? void 0 : _b.action;
  const bookingTicket = (sales == null ? void 0 : sales.bookingTicket) ?? null;
  const getPubsub = (0, import_react.useCallback)(() => {
    var _a2, _b2, _c2, _d;
    return (_d = (_c2 = (_b2 = (_a2 = engineContext == null ? void 0 : engineContext.appHelper) == null ? void 0 : _a2.utils) == null ? void 0 : _b2.getApp) == null ? void 0 : _c2.call(_b2)) == null ? void 0 : _d.pubsub;
  }, [engineContext]);
  const getAcquireScanFocus = (0, import_react.useCallback)(() => {
    var _a2, _b2;
    const utils = (_a2 = engineContext == null ? void 0 : engineContext.appHelper) == null ? void 0 : _a2.utils;
    if (typeof (utils == null ? void 0 : utils.acquireScanFocus) === "function") {
      return utils.acquireScanFocus;
    }
    if (typeof ((_b2 = utils == null ? void 0 : utils.businessUtils) == null ? void 0 : _b2.acquireScanFocus) === "function") {
      return utils.businessUtils.acquireScanFocus;
    }
    return void 0;
  }, [engineContext]);
  const bridgeFactory = (0, import_react.useCallback)(() => {
    var _a2;
    if (!uiHosts || !refreshRootSnapshot) return void 0;
    const tempOrderCustomerId = Number((_a2 = sales == null ? void 0 : sales.tempOrder) == null ? void 0 : _a2.customer_id);
    return (0, import_createGlobalScanHostBridge.createGlobalScanHostBridge)({
      uiHosts,
      action,
      cart,
      businessCode,
      refreshRootSnapshot,
      getCustomerId: () => Number.isFinite(tempOrderCustomerId) ? tempOrderCustomerId : void 0,
      toast: Toast,
      getLocaleText: (key) => import_utils.locales.getText(key)
    });
  }, [uiHosts, action, cart, businessCode, refreshRootSnapshot, Toast, (_c = sales == null ? void 0 : sales.tempOrder) == null ? void 0 : _c.customer_id]);
  (0, import_useSalesSdkGlobalScanListener.useSalesSdkGlobalScanListener)({
    enabled,
    isActive,
    bookingTicket,
    bridgeFactory,
    getPubsub,
    getAcquireScanFocus
  });
  return null;
};
SalesSdkGlobalScanSubscriber.displayName = "SalesSdkGlobalScanSubscriber";
var SalesSdkGlobalScanSubscriber_default = SalesSdkGlobalScanSubscriber;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SalesSdkGlobalScanSubscriber
});
