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/productExtension/fields/Forms/index.tsx
var Forms_exports = {};
__export(Forms_exports, {
  default: () => Forms_default
});
module.exports = __toCommonJS(Forms_exports);
var import_react = __toESM(require("react"));
var import_forms = __toESM(require("../../../booking/forms/forms"));
var relation_type = "appointment_booking";
var Forms = (props) => {
  const { relation_id, action, value, onChange, apis } = props;
  const [formList, setFormList] = (0, import_react.useState)([]);
  const [loading, setLoading] = (0, import_react.useState)(true);
  (0, import_react.useEffect)(() => {
    geForms();
  }, []);
  const getFormDataById = async (item) => {
    let _params = {
      form_id: item.form_id,
      skip: 1,
      num: 999
    };
    let options = [];
    const data = await apis.getPetsData(_params);
    options = (data == null ? void 0 : data.list) || [];
    return {
      ...item,
      options
    };
  };
  const getFormData = async (formList2) => {
    let all = [];
    all = formList2.map((d) => getFormDataById(d));
    return Promise.all(all);
  };
  const getFormValues = (data) => {
    let _values = {};
    for (let item of data) {
      _values[item.form_id] = item.form_record;
    }
    return _values;
  };
  const geForms = async () => {
    setLoading(true);
    try {
      let data = await apis.getForms({
        relation_type,
        relation_id
      });
      const formData = await getFormData(data);
      setFormList(formData);
      setLoading(false);
    } catch (err) {
      console.log("form_error", err);
    }
  };
  const onValueChange = (data) => {
    const { values } = data;
    onChange == null ? void 0 : onChange(values);
  };
  const addCallback = async (form) => {
    let _data = [...formList];
    const data = await getFormDataById(form);
    _data = _data.map((d) => d.form_id === form.form_id ? data : d);
    setFormList(_data);
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_forms.default,
    {
      forms: formList,
      action,
      modalOpen: false,
      value,
      onChange: onValueChange,
      addCallback,
      client: 0
    }
  );
};
var Forms_default = Forms;
