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/useScanCustomer.ts
var useScanCustomer_exports = {};
__export(useScanCustomer_exports, {
  default: () => useScanCustomer_default
});
module.exports = __toCommonJS(useScanCustomer_exports);
var import_react = require("react");
var import_utils = require("@pisell/utils");
var import_bookingTicket = require("./bookingTicket");
var import_utils2 = require("../../utils");
var import_materials = require("@pisell/materials");
var import_useActiveExecute = require("./useActiveExecute");
var useScanCustomer = () => {
  const bookingTicket = (0, import_bookingTicket.useBookingTicket)();
  const scanRef = (0, import_react.useRef)(null);
  const Toast = (0, import_materials.useToast)();
  const { executeIfActive } = (0, import_useActiveExecute.useActiveExecute)();
  const handleScanCustomer = (callback) => {
    console.log("handleScanCustomer>>>>>>>", callback);
    scanRef.current = bookingTicket == null ? void 0 : bookingTicket.scanCustomerListener(executeIfActive((data) => {
      console.log("scanCustomerListener>>>>>>>", data);
      if (data.status === "failed") {
        Toast.fail(import_utils.locales.getText("pisell2.text.scan-global-failed"));
        return;
      }
      const customer = (0, import_utils2.formatScanCustomer)(data);
      callback(customer);
    }));
  };
  return {
    openScan: handleScanCustomer,
    closeScan: () => {
      var _a, _b;
      (_b = (_a = scanRef.current) == null ? void 0 : _a.remove) == null ? void 0 : _b.call(_a);
    }
  };
};
var useScanCustomer_default = useScanCustomer;
