import { useMemo as s } from "react";
import * as F from "yup";
import { EMPTY_DATA as j } from "../../constants.js";
import { useDynamicFormData as E } from "../useDynamicFormData/useDynamicFormData.js";
import { useDynamicForm as M } from "../useDynamicForm/useDynamicForm.js";
function Y(r) {
  const {
    formId: u,
    formInstanceId: c,
    inputEndpoint: l,
    outputEndpoint: d,
    submitMode: p,
    formatInputData: f,
    formatOutputData: b,
    onSubmit: h,
    initialData: i,
    siblingInitialValues: t,
    siblingValidationShape: a
  } = r, {
    formData: n,
    statusLoad: D,
    handleSubmit: S,
    isLoading: y
  } = E({
    formId: u,
    formInstanceId: c,
    inputEndpoint: l,
    outputEndpoint: d,
    submitMode: p,
    initialData: i,
    formatInputData: f,
    formatOutputData: b,
    onSubmit: h
  }), m = s(
    () => n ?? i ?? null,
    [n, i]
  ), { initialValues: o, validationSchema: e } = M(m ?? j), g = s(() => !t || Object.keys(t).length === 0 ? o : { ...o, ...t }, [o, t]), I = s(() => {
    if (!a || Object.keys(a).length === 0)
      return e;
    const V = { ...e.fields ?? {}, ...a };
    return F.object().shape(V);
  }, [e, a]);
  return {
    formData: n,
    formDataToUse: m,
    statusLoad: D,
    handleSubmit: S,
    initialValues: g,
    validationSchema: I,
    isLoading: y
  };
}
export {
  Y as useDynamicFormCoupled
};
