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/booking/forms/single/RenderValueById.tsx
var RenderValueById_exports = {};
__export(RenderValueById_exports, {
  default: () => RenderValueById_default
});
module.exports = __toCommonJS(RenderValueById_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_antd = require("antd");
var import_ahooks = require("ahooks");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_serve = require("../serve");
var import_index = require("./index.less");
var RenderValueById = (props) => {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
  const { field, value: propsValue } = props;
  const { appHelper } = (0, import_useEngineContext.default)();
  const [displayCount, setDisplayCount] = (0, import_react.useState)(10);
  const _getFormData = (0, import_ahooks.useRequest)(import_serve.getFormData, {
    manual: true,
    cacheKey: `formOption-${(_a = field.setting) == null ? void 0 : _a.linkedTable}-${(_c = (_b = propsValue || []) == null ? void 0 : _b.toString) == null ? void 0 : _c.call(_b)}`,
    staleTime: 500,
    cacheTime: 5e3
  });
  const value = (0, import_react.useMemo)(() => {
    let v = propsValue;
    if (field.filed_type === "form_to_form") {
      if ((0, import_utils.isArr)(propsValue)) {
        v = propsValue;
      } else if (propsValue == null ? void 0 : propsValue.form_ids) {
        v = propsValue.form_ids;
      } else {
        v = propsValue;
      }
    }
    return v;
  }, [propsValue]);
  (0, import_react.useEffect)(() => {
    var _a2, _b2;
    if (field.filed_type === "form_to_form" && ((_a2 = field.setting) == null ? void 0 : _a2.linkedTable)) {
      _getFormData.run({
        form_record_ids: value,
        form_id: (_b2 = field.setting) == null ? void 0 : _b2.linkedTable,
        skip: 1,
        num: 999
      });
    }
  }, [field.filed_type, value]);
  const options = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2, _d2, _e2;
    if (field.filed_type === "form_to_form" && ((_a2 = field == null ? void 0 : field.setting) == null ? void 0 : _a2.linkedTable)) {
      return ((_d2 = (_c2 = (_b2 = _getFormData.data) == null ? void 0 : _b2.data) == null ? void 0 : _c2.list) == null ? void 0 : _d2.map((item) => ({
        title: item.main_field,
        id: item.form_record_id
      }))) || [];
    }
    return (_e2 = field == null ? void 0 : field.setting) == null ? void 0 : _e2.customTypeList;
  }, [field.filed_type, (_d = field == null ? void 0 : field.setting) == null ? void 0 : _d.customTypeList, _getFormData.data]);
  if ((0, import_utils.isArr)(value)) {
    const formListDisplay = ((_e = field == null ? void 0 : field.setting) == null ? void 0 : _e.displayStyle) === "list" && (field == null ? void 0 : field.filed_type) === "form_to_form";
    let _list = options == null ? void 0 : options.filter((i) => {
      return value == null ? void 0 : value.includes((i == null ? void 0 : i.id) || i.value);
    });
    let _str = !formListDisplay && (_list == null ? void 0 : _list.map((i) => {
      var _a2;
      const title = (_a2 = appHelper == null ? void 0 : appHelper.utils) == null ? void 0 : _a2.translationShop((i == null ? void 0 : i.title) || (i == null ? void 0 : i.label));
      return /* @__PURE__ */ import_react.default.createElement(import_antd.Tooltip, { title }, /* @__PURE__ */ import_react.default.createElement(import_antd.Tag, { className: "pisell-lowcode__booking-form-link-tag-title" }, title));
    })) || "-";
    if (formListDisplay) {
      const displayList = (_list == null ? void 0 : _list.slice(0, displayCount)) || [];
      _str = (displayList == null ? void 0 : displayList.map((i, index) => {
        var _a2;
        const title = (_a2 = appHelper == null ? void 0 : appHelper.utils) == null ? void 0 : _a2.translationShop((i == null ? void 0 : i.title) || (i == null ? void 0 : i.label));
        return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-form-link-to-list-item" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-lowcode__booking-form-link-to-list-item-index" }, index + 1), /* @__PURE__ */ import_react.default.createElement(import_antd.Tooltip, { title }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-lowcode__booking-form-link-to-list-item-title" }, title)));
      })) || "-";
    }
    return /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        className: formListDisplay ? "pisell-lowcode__booking-form-link-to-list-wrap" : ""
      },
      _str || "-",
      formListDisplay && (_list == null ? void 0 : _list.length) > displayCount && /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: "pisell-lowcode__booking-form-link-to-list-item-more",
          onClick: () => setDisplayCount((prev) => Math.min(prev + 10, (_list == null ? void 0 : _list.length) || 0))
        },
        /* @__PURE__ */ import_react.default.createElement("span", null, import_utils.locales.getText("pisell2.text.form.link.to.another.record.more")),
        /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "icona-IconStroke" })
      )
    );
  }
  if (!(0, import_utils.isUndefined)(value)) {
    if ((field == null ? void 0 : field.filed_type) === "select" && !((_f = field == null ? void 0 : field.setting) == null ? void 0 : _f.version)) {
      return /* @__PURE__ */ import_react.default.createElement("span", null, value || "-");
    }
    let _item = options == null ? void 0 : options.filter((i) => (i == null ? void 0 : i.id) == value);
    return ((_i = appHelper == null ? void 0 : appHelper.utils) == null ? void 0 : _i.translationShop(
      ((_g = _item == null ? void 0 : _item[0]) == null ? void 0 : _g.title) || ((_h = _item == null ? void 0 : _item[0]) == null ? void 0 : _h.label)
    )) || "-";
  }
  return null;
};
var RenderValueById_default = RenderValueById;
