import { useRef } from 'react';
import { locales } from "@pisell/utils";
import { useBookingTicket } from "./bookingTicket";
import { formatScanCustomer } from "../../utils";
import { useToast } from '@pisell/materials';
var useScanCustomer = function useScanCustomer() {
  var bookingTicket = useBookingTicket();
  var scanRef = useRef(null);
  var Toast = useToast();
  var handleScanCustomer = function handleScanCustomer(callback) {
    console.log('handleScanCustomer>>>>>>>', callback);
    scanRef.current = bookingTicket === null || bookingTicket === void 0 ? void 0 : bookingTicket.scanCustomerListener(function (data) {
      console.log('scanCustomerListener>>>>>>>', data);
      if (data.status === 'failed') {
        Toast.fail(locales.getText('pisell2.text.scan-global-failed'));
        return;
      }
      var customer = formatScanCustomer(data);
      callback(customer);
    });
  };
  return {
    openScan: handleScanCustomer,
    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 useScanCustomer;