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: !0 });
}, __copyProps = (to, from, except, desc) => {
  if (from && typeof from == "object" || typeof from == "function")
    for (let key of __getOwnPropNames(from))
      !__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: !0 }), mod);
var BarcodeScanner_native_exports = {};
__export(BarcodeScanner_native_exports, {
  BarcodeScanner: () => BarcodeScanner
});
module.exports = __toCommonJS(BarcodeScanner_native_exports);
var import_jsx_runtime = require("react/jsx-runtime"), import_core = require("@tamagui/core"), import_react_native_webview = require("react-native-webview");
function BarcodeScanner(param) {
  var { onScan, onError, ...props } = param, onMessage = function(event) {
    var data = JSON.parse(event.nativeEvent.data);
    data.type === "scanSuccess" ? onScan(data.payload) : data.type === "scanError" && onError(data.payload);
  };
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
    minWidth: 300,
    width: 300,
    borderRadius: "$shape.corner_m",
    overflow: "hidden",
    position: "relative",
    ...props,
    children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native_webview.WebView, {
      style: {
        width: "100%",
        height: "100%"
      },
      source: {
        html: Doc
      },
      onMessage,
      mediaPlaybackRequiresUserAction: !1
    })
  });
}
var Doc = `
<!DOCTYPE html>
<html>
<head>
    <title>QR Code Scanner</title>
    <script src="https://unpkg.com/html5-qrcode"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
            width: 100vw;
            height: 100vh;
            overflow: hidden;
        }
        
        #qr-reader {
            width: 100%;
            height: 100%;
        }
        
        .scanner-overlay {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 250px;
            height: 250px;
            border: 2px solid #ffffff;
            border-radius: 20px;
            box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
            pointer-events: none;
        }
    </style>
</head>
<body>
    <div id="qr-reader"></div>
    <div class="scanner-overlay"></div>

    <script>
        function onScanSuccess(decodedText) {
            // Send the scanned code back to React Native
            try {
                // For iOS
                window.webkit.messageHandlers.jsMessageHandler.postMessage(decodedText);
            } catch (e) {
                try {
                    // For Android
                    window.ReactNativeWebView.postMessage(decodedText);
                } catch (e) {
                    console.error('Failed to send message to React Native:', e);
                }
            }
        }

        function onScanError(error) {

        }

        // Initialize QR scanner
        window.addEventListener('load', function() {
            const html5QrCode = new Html5Qrcode("qr-reader");
            
            Html5Qrcode.getCameras().then(devices => {
                if (devices && devices.length) {
                    html5QrCode.start(
                        devices[0].id,
                        {
                            fps: 10,
                            qrbox: 250
                        },
                        onScanSuccess,
                        onScanError
                    );
                }
            }).catch(err => {
                console.error('Error getting cameras:', err);
            });
        });
    </script>
</body>
</html>
`;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  BarcodeScanner
});
//# sourceMappingURL=BarcodeScanner.native.js.map
