var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/dataSourceComponents/fields/Input/WithMode.tsx
var WithMode_exports = {};
__export(WithMode_exports, {
  default: () => WithMode_default
});
module.exports = __toCommonJS(WithMode_exports);
var import_antd = require("antd");
var import_react = __toESM(require("react"));
var import_iconfont = __toESM(require("./../../../../components/iconfont"));
var import_ReadPretty = __toESM(require("./ReadPretty"));
var import_utils = require("../../dataSourceForm/utils");
var import_pisellQRScanner = __toESM(require("../../../../components/pisellQRScanner"));
var Input = (props) => {
  const {
    enableQRScanner,
    value: propValue,
    onChange,
    renderMode,
    // 明确解构，避免通过restProps传递
    innerRef,
    // 明确解构
    className,
    // 明确解构className
    ...restProps
  } = props;
  const [inputValue, setInputValue] = (0, import_react.useState)(propValue || "");
  (0, import_react.useEffect)(() => {
    if (propValue !== void 0 && propValue !== inputValue) {
      setInputValue(propValue);
    }
  }, [propValue]);
  const [scanVisible, setScanVisible] = (0, import_react.useState)(false);
  const setValue = (value) => {
    console.log("设置输入框值:", value);
    setInputValue(value);
    if (typeof onChange === "function") {
      try {
        const syntheticEvent = {
          target: { value },
          currentTarget: { value },
          preventDefault: () => {
          },
          stopPropagation: () => {
          }
        };
        onChange(syntheticEvent);
      } 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__ */ import_react.default.createElement(
    import_iconfont.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__ */ import_react.default.createElement(import_ReadPretty.default, { ...props });
  }
  (0, import_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__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Input,
    {
      ...restProps,
      ref: innerRef || void 0,
      className: `${className || ""} ${enableQRScanner ? "pisell-input-with-scanner" : ""}`,
      addonAfter: scanSuffix,
      value: inputValue,
      onChange: handleInputChange
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_pisellQRScanner.default,
    {
      visible: scanVisible,
      onClose: handleScanClose,
      onScan: handleScanComplete
    }
  ));
};
var InputWithMode = (0, import_utils.withMode)(Input, import_ReadPretty.default);
var WithMode_default = InputWithMode;
