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/Translation/BaseTranslation.tsx
var BaseTranslation_exports = {};
__export(BaseTranslation_exports, {
  default: () => BaseTranslation_default
});
module.exports = __toCommonJS(BaseTranslation_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_icons = require("@ant-design/icons");
var import_locales = require("../../../../locales");
var import_index = require("./index.less");
var defaultValue = {
  en: "",
  "zh-CN": "",
  "zh-HK": "",
  "ja": "",
  "pt": "",
  original: ""
};
var languageConfig = [
  { key: "original", label: (0, import_locales.getText)("pisell-translation-original") },
  { key: "en", label: "English" },
  { key: "zh-CN", label: "简体中文" },
  { key: "zh-HK", label: "繁體中文" },
  { key: "ja", label: "日本語" },
  { key: "pt", label: "Português" }
];
var Translation = ({
  value = defaultValue,
  onChange,
  placeholder,
  disabled,
  type = "text",
  // 默认为普通文本输入
  maxLength,
  inputStyle,
  allowClear
}) => {
  const [open, setOpen] = (0, import_react.useState)(false);
  const getInputComponent = (0, import_react.useCallback)(() => {
    switch (type) {
      case "textarea":
        return import_antd.Input.TextArea;
      default:
        return import_antd.Input;
    }
  }, [type]);
  const InputComponent = getInputComponent();
  const hasAnyTranslation = (0, import_react.useCallback)(() => {
    if (!value) {
      return false;
    }
    return Object.entries(value).some(([key, val]) => key !== "original" && val);
  }, [value]);
  const handleInputChange = (0, import_react.useCallback)(
    (lang) => (e) => {
      const newValue = {
        ...value,
        [lang]: e.target.value
      };
      onChange == null ? void 0 : onChange(newValue);
    },
    [value, onChange]
  );
  const content = /* @__PURE__ */ import_react.default.createElement("div", { className: "translation-popover" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Space, { direction: "vertical", style: { width: "100%" }, size: 16 }, languageConfig.map(({ key, label }) => /* @__PURE__ */ import_react.default.createElement("div", { key, className: "translation-field" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "translation-label" }, label), /* @__PURE__ */ import_react.default.createElement(
    InputComponent,
    {
      value: (value == null ? void 0 : value[key]) || "",
      onChange: handleInputChange(key),
      allowClear: true,
      maxLength,
      style: inputStyle || {}
    }
  )))));
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "translation-wrapper" }, /* @__PURE__ */ import_react.default.createElement(
    InputComponent,
    {
      value: (value == null ? void 0 : value.original) || "",
      onChange: handleInputChange("original"),
      placeholder,
      disabled,
      className: "translation-input",
      maxLength,
      style: inputStyle || {},
      allowClear
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_antd.Popover,
    {
      content,
      trigger: "click",
      open,
      onOpenChange: (open2) => {
        if (disabled) {
          return;
        }
        setOpen(open2);
      },
      placement: "bottom"
    },
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `translation-icon-wrapper ${hasAnyTranslation() ? "has-translation" : ""} ${disabled ? "disabled" : ""}`
      },
      /* @__PURE__ */ import_react.default.createElement(import_icons.GlobalOutlined, { className: "translation-icon" })
    )
  ));
};
var BaseTranslation_default = Translation;
