Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../../chunk-BN4qSVkS.cjs");
const require_components_QRReader_utils = require("./utils.cjs");
let react = require("react");
//#region src/components/QRReader/hooks.ts
const useQRReader = ({ scanDelay: delayBetweenScanAttempts = 500, constraints: video, onResult, videoId }) => {
	const mountedRef = (0, react.useRef)(true);
	(0, react.useEffect)(() => {
		const readQRCode = async () => {
			const { BrowserQRCodeReader } = await import(
				/* webpackChunkName: "zxing" */
				"@zxing/browser"
);
			const codeReader = new BrowserQRCodeReader(void 0, { delayBetweenScanAttempts });
			if (!require_components_QRReader_utils.isMediaDevicesSupported() && onResult) onResult(null, /* @__PURE__ */ new Error("MediaDevices API has no support for your browser. You can fix this by running \"npm i webrtc-adapter\""), codeReader);
			if (video && require_components_QRReader_utils.isValidType(video, "constraints", "object")) codeReader.decodeFromConstraints({ video }, videoId, (result, error, controls) => {
				if (mountedRef.current === false) {
					controls.stop();
					return;
				}
				if (typeof result !== "undefined" && onResult) {
					controls.stop();
					onResult(result, error, codeReader);
				}
			}).catch((error) => {
				if (onResult) onResult(null, error, codeReader);
			});
		};
		mountedRef.current = true;
		readQRCode();
		return () => {
			mountedRef.current = false;
		};
	}, [
		delayBetweenScanAttempts,
		onResult,
		video,
		videoId
	]);
};
//#endregion
exports.useQRReader = useQRReader;
