"use client"; import { useState, useRef } from "react"; export default function SimpleQRScanner({ onScan }) { const [error, setError] = useState(null); const [isCameraActive, setIsCameraActive] = useState(false); const videoRef = useRef(null); const startCamera = async () => { try { const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" }, }); if (videoRef.current) { videoRef.current.srcObject = stream; setIsCameraActive(true); } } catch (err) { console.error("Error accessing camera:", err); setError( "Could not access camera. Please make sure you've given camera permission." ); } }; const stopCamera = () => { if (videoRef.current && videoRef.current.srcObject) { const tracks = videoRef.current.srcObject.getTracks(); tracks.forEach((track) => track.stop()); videoRef.current.srcObject = null; setIsCameraActive(false); } }; const handleManualInput = () => { const code = prompt("Enter the QR code value manually (e.g. QR123):"); if (code && onScan) { onScan(code); } }; return (