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");
const require_index = require("../../../iconfont/index.js");
const require_utils = require("../../dataSourceForm/utils.js");
const require_index$1 = require("../../../pisellQRScanner/index.js");
const require_ReadPretty = require("./ReadPretty.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
//#region src/components/dataSourceComponents/fields/Input/WithMode.tsx
const _excluded = [
	"enableQRScanner",
	"value",
	"onChange",
	"renderMode",
	"innerRef",
	"className"
];
const Input = (props) => {
	const { enableQRScanner, value: propValue, onChange, renderMode, innerRef, className } = props, restProps = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
	const [inputValue, setInputValue] = (0, react.useState)(propValue || "");
	(0, react.useEffect)(() => {
		if (propValue !== void 0 && propValue !== inputValue) setInputValue(propValue);
	}, [propValue]);
	const [scanVisible, setScanVisible] = (0, react.useState)(false);
	const setValue = (value) => {
		console.log("设置输入框值:", value);
		setInputValue(value);
		if (typeof onChange === "function") try {
			onChange({
				target: { value },
				currentTarget: { value },
				preventDefault: () => {},
				stopPropagation: () => {}
			});
		} catch (err) {
			console.error("调用onChange失败:", err);
		}
	};
	const handleInputChange = (e) => {
		const newValue = e.target.value;
		setInputValue(newValue);
		if (typeof onChange === "function") onChange(e);
	};
	const handleScanClick = () => {
		setScanVisible(true);
	};
	const handleScanComplete = (value) => {
		setValue(value);
	};
	const handleScanClose = () => {
		setScanVisible(false);
	};
	const scanSuffix = enableQRScanner ? /* @__PURE__ */ react.default.createElement(require_index.default, {
		type: "pisell2-scan2",
		className: "scan-button-icon",
		style: {
			fontSize: 24,
			color: "#fff",
			cursor: "pointer"
		},
		onClick: handleScanClick
	}) : null;
	if (renderMode === "view" || renderMode === "tableView") return /* @__PURE__ */ react.default.createElement(require_ReadPretty.default, props);
	(0, react.useEffect)(() => {
		if (enableQRScanner) {
			const styleEl = document.createElement("style");
			styleEl.id = "pisell-qr-scanner-style";
			styleEl.innerHTML = `
        .pisell-input-with-scanner .pisell-lowcode-input-group .pisell-lowcode-input-group-addon {
          background-color: var(--primary-600, #7F56D9);
        }
      `;
			document.head.appendChild(styleEl);
			return () => {
				const existingStyle = document.getElementById("pisell-qr-scanner-style");
				if (existingStyle) document.head.removeChild(existingStyle);
			};
		}
	}, [enableQRScanner]);
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(antd.Input, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, restProps), {}, {
		ref: innerRef || void 0,
		className: `${className || ""} ${enableQRScanner ? "pisell-input-with-scanner" : ""}`,
		addonAfter: scanSuffix,
		value: inputValue,
		onChange: handleInputChange
	})), /* @__PURE__ */ react.default.createElement(require_index$1.default, {
		visible: scanVisible,
		onClose: handleScanClose,
		onScan: handleScanComplete
	}));
};
const InputWithMode = require_utils.withMode(Input, require_ReadPretty.default);
//#endregion
exports.default = InputWithMode;
