var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/ticketBooking/hooks/pisellos/useScanGlobal.ts
var useScanGlobal_exports = {};
__export(useScanGlobal_exports, {
  default: () => useScanGlobal_default
});
module.exports = __toCommonJS(useScanGlobal_exports);
var import_react = require("react");
var import_bookingTicket = require("./bookingTicket");
var import_utils = require("../../utils");
var import_materials = require("@pisell/materials");
var import_utils2 = require("@pisell/utils");
var useScanGlobal = () => {
  const bookingTicket = (0, import_bookingTicket.useBookingTicket)();
  const scanRef = (0, import_react.useRef)(null);
  const Toast = (0, import_materials.useToast)();
  const handleScanGlobal = (callback) => {
    scanRef.current = bookingTicket == null ? void 0 : bookingTicket.scanGlobalListener(
      (data) => {
        console.log("scanGlobalListener>>>>>>>", data);
        if (data.status === "failed") {
          Toast.fail(import_utils2.locales.getText("pisell2.text.scan-global-failed"));
          return;
        }
        const result = (0, import_utils.formatScanGlobal)(data);
        callback(result);
      }
    );
  };
  return {
    openScan: handleScanGlobal,
    closeScan: () => {
      var _a, _b;
      (_b = (_a = scanRef.current) == null ? void 0 : _a.remove) == null ? void 0 : _b.call(_a);
    }
  };
};
var useScanGlobal_default = useScanGlobal;
