import { formatScanCustomer } from "../../utils/index.js";
import { useBookingTicket } from "./bookingTicket.js";
import { useActiveExecute } from "./useActiveExecute.js";
import { useRef } from "react";
import { locales } from "@pisell/utils";
import { useToast } from "@pisell/materials";
//#region src/components/ticketBooking/hooks/pisellos/useScanCustomer.ts
const useScanCustomer = () => {
	const bookingTicket = useBookingTicket();
	const scanRef = useRef(null);
	const Toast = useToast();
	const { executeIfActive } = useActiveExecute();
	const handleScanCustomer = (callback) => {
		console.log("handleScanCustomer>>>>>>>", callback);
		scanRef.current = bookingTicket === null || bookingTicket === void 0 ? void 0 : bookingTicket.scanCustomerListener(executeIfActive((data) => {
			console.log("scanCustomerListener>>>>>>>", data);
			if (data.status === "failed") {
				Toast.fail(locales.getText("pisell2.text.scan-global-failed"));
				return;
			}
			callback(formatScanCustomer(data));
		}));
	};
	return {
		openScan: handleScanCustomer,
		closeScan: () => {
			var _scanRef$current, _scanRef$current$remo;
			(_scanRef$current = scanRef.current) === null || _scanRef$current === void 0 || (_scanRef$current$remo = _scanRef$current.remove) === null || _scanRef$current$remo === void 0 || _scanRef$current$remo.call(_scanRef$current);
		}
	};
};
//#endregion
export { useScanCustomer as default };
