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_antd = require("antd");
var import_ahooks = require("ahooks");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_serve = require("../serve");
var RenderValueById = (props) => {
  var _a, _b, _c, _d, _e, _f;
  const { field, value: propsValue } = props;
  const { appHelper } = (0, import_useEngineContext.default)();
  const _getFormData = (0, import_ahooks.useRequest)(import_serve.getFormData, {
    manual: true,
    cacheKey: `formOption-${(_a = field.setting) == null ? void 0 : _a.linkedTable}`,
    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, (_b = field == null ? void 0 : field.setting) == null ? void 0 : _b.customTypeList, _getFormData.data]);
  if ((0, import_utils.isArr)(value)) {
    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 = (_list == null ? void 0 : _list.map((i) => {
      var _a2;
      return /* @__PURE__ */ import_react.default.createElement(import_antd.Tag, null, (_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("span", null, _str || "-");
  }
  if (!(0, import_utils.isUndefined)(value)) {
    if ((field == null ? void 0 : field.filed_type) === "select" && !((_c = field == null ? void 0 : field.setting) == null ? void 0 : _c.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 ((_f = appHelper == null ? void 0 : appHelper.utils) == null ? void 0 : _f.translationShop(
      ((_d = _item == null ? void 0 : _item[0]) == null ? void 0 : _d.title) || ((_e = _item == null ? void 0 : _item[0]) == null ? void 0 : _e.label)
    )) || "-";
  }
  return null;
};
var RenderValueById_default = RenderValueById;
