import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import React, { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
import { BrowserMultiFormatReader, NotFoundException } from "@zxing/library";
import "./index.less";
//#region src/components/pisellScan/index.tsx
const _excluded = [
	"width",
	"height",
	"borderRadius",
	"style",
	"children",
	"onChange",
	"timeBetweenScansMillis"
];
/**
* 二维码条形码扫描组件
*/
const PisellScan = forwardRef((props, ref) => {
	const { width, height, borderRadius, style, children, onChange, timeBetweenScansMillis = 500 } = props, others = _objectWithoutProperties(props, _excluded);
	const videoRef = useRef(null);
	const codeReaderRef = useRef(null);
	useImperativeHandle(ref, () => {
		return { codeReader: codeReaderRef.current };
	});
	useEffect(() => {
		const codeReader = new BrowserMultiFormatReader(void 0, timeBetweenScansMillis);
		codeReaderRef.current = codeReader;
		codeReaderRef.current.listVideoInputDevices().then((videoInputDevices) => {
			videoInputDevices[0].deviceId;
			codeReader.decodeFromVideoDevice(null, videoRef.current, (result, err) => {
				if (result) onChange === null || onChange === void 0 || onChange(result.getText());
				if (err && !(err instanceof NotFoundException)) console.error(err);
			});
		}).catch((err) => {
			console.error(err);
		});
		return () => {
			codeReaderRef.current.reset();
		};
	}, []);
	return /* @__PURE__ */ React.createElement("div", {
		className: "pisell-scan-wrap",
		style: _objectSpread2({
			width,
			height,
			borderRadius
		}, style)
	}, /* @__PURE__ */ React.createElement("video", _objectSpread2(_objectSpread2({}, others), {}, {
		ref: videoRef,
		style: _objectSpread2({
			width,
			height,
			borderRadius,
			background: "#000"
		}, style)
	})), /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-action" }, children));
});
//#endregion
export { PisellScan as default };
