const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _zxing_library = require("@zxing/library");
require("./index.less");
//#region src/components/pisellScan/index.tsx
const _excluded = [
	"width",
	"height",
	"borderRadius",
	"style",
	"children",
	"onChange",
	"timeBetweenScansMillis"
];
/**
* 二维码条形码扫描组件
*/
const PisellScan = (0, react.forwardRef)((props, ref) => {
	const { width, height, borderRadius, style, children, onChange, timeBetweenScansMillis = 500 } = props, others = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
	const videoRef = (0, react.useRef)(null);
	const codeReaderRef = (0, react.useRef)(null);
	(0, react.useImperativeHandle)(ref, () => {
		return { codeReader: codeReaderRef.current };
	});
	(0, react.useEffect)(() => {
		const codeReader = new _zxing_library.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 _zxing_library.NotFoundException)) console.error(err);
			});
		}).catch((err) => {
			console.error(err);
		});
		return () => {
			codeReaderRef.current.reset();
		};
	}, []);
	return /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-scan-wrap",
		style: require_objectSpread2._objectSpread2({
			width,
			height,
			borderRadius
		}, style)
	}, /* @__PURE__ */ react.default.createElement("video", require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, others), {}, {
		ref: videoRef,
		style: require_objectSpread2._objectSpread2({
			width,
			height,
			borderRadius,
			background: "#000"
		}, style)
	})), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-scan-action" }, children));
});
//#endregion
exports.default = PisellScan;
