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