import { useRef } from 'react';
import { useBookingTicket } from "./bookingTicket";
import { formatScanGlobal } from "../../utils";
import useToast from "../../../../hooks/useToast";
import { locales } from '@pisell/utils';
var useScanGlobal = function useScanGlobal() {
  var bookingTicket = useBookingTicket();
  var scanRef = useRef(null);
  var Toast = useToast();
  var handleScanGlobal = function handleScanGlobal(callback) {
    scanRef.current = bookingTicket === null || bookingTicket === void 0 ? void 0 : bookingTicket.scanGlobalListener(function (data) {
      console.log('scanGlobalListener>>>>>>>', data);
      if (data.status === 'failed') {
        Toast.fail(locales.getText('pisell2.text.scan-global-failed'));
        return;
      }
      var result = formatScanGlobal(data);
      callback(result);
    });
  };
  return {
    openScan: handleScanGlobal,
    closeScan: function 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);
    }
  };
};
export default useScanGlobal;