import SwitchCameraOutlined from "@mui/icons-material/SwitchCameraOutlined"; import { Box, IconButton, type SxProps } from "@mui/material"; import { getLocalizedString } from "@olenbetong/appframe-core"; import type BarcodeReaderType from "dynamsoft-javascript-barcode"; import { useRef } from "react"; import { ErrorIcon } from "./Error"; import { useScanner } from "./useScanner"; declare global { interface Window { BarcodeReader: typeof BarcodeReaderType; } } export type BarcodeScannerProps = { onRead: (barcode: string) => void; }; const frameSx: SxProps = { position: "absolute", bottom: 0, left: 0, right: 0, top: 0, height: "100%", width: "100%", }; export function BarcodeScanner({ onRead }: BarcodeScannerProps) { let readerRoot = useRef(null); let canvas = useRef(null); let { devices, error, setNextDevice } = useScanner(readerRoot, canvas, onRead); return ( {error && } {devices.length <= 1 && } {devices.length > 1 && ( setNextDevice()} size="large" > )} ); }