import { View } from "@tamagui/core";
import { Html5Qrcode } from "html5-qrcode";
import { useEffect } from "react";
import { jsx } from "react/jsx-runtime";
function BarcodeScanner({
  onScan,
  onError,
  ...props
}) {
  return useEffect(() => {
    Html5Qrcode.getCameras().then(devices => {
      if (devices && devices.length) {
        const html5QrCode = new Html5Qrcode("qr-code-region");
        return html5QrCode.start(devices[0].id, {
          fps: 10,
          qrbox: 250
        }, decodedText => {
          onScan(decodedText);
        }, errorMessage => {}), () => {
          html5QrCode.stop().catch(console.error);
        };
      }
    });
  }, []), /* @__PURE__ */jsx(View, {
    minWidth: 300,
    width: 300,
    borderRadius: "$shape.corner_m",
    overflow: "hidden",
    position: "relative",
    ...props,
    children: /* @__PURE__ */jsx(View, {
      id: "qr-code-region"
    })
  });
}
export { BarcodeScanner };
//# sourceMappingURL=BarcodeScanner.mjs.map
