import * as p from "yup";
import { DYNAMIC_FORM_DICTIONARY as m } from "../../dictionary.js";
import { createBaseSchema as c } from "./strategies/baseSchema/createBaseSchema.js";
import { VALIDATION_STRATEGY_REGISTRY as v } from "./strategies/validation/validationStrategies.js";
import { resolveFieldMandatory as y } from "../resolveFieldContractAliases.js";
import { normalizeValidation as f } from "../normalizeValidation/normalizeValidation.js";
import { applyRequiredValidation as u } from "../applyRequiredValidation/applyRequiredValidation.js";
function _(t, n) {
  const r = y(t);
  if ((!t.validations || t.validations.length === 0) && !r)
    return;
  const e = c(t), s = t.validations ? t.validations.filter((i) => i.isActive).map(f).sort((i, o) => i.displayOrder - o.displayOrder) : [];
  let a = e;
  for (const i of s) {
    const o = i.validationType || i.type;
    if (!o)
      continue;
    const d = v[o.id];
    d !== void 0 ? a = d.apply({
      field: t,
      getLabel: n,
      baseSchema: e,
      schema: a,
      validation: i
    }) : console.warn(`Unsupported validation type: ${o.id}`);
  }
  const l = s.some((i) => (i.validationType || i.type)?.id === "fvl_required");
  return r && !l && (a = u(
    t,
    a,
    e,
    n(m.IS_REQUIRED_MESSAGE)
  )), r || (e instanceof p.ArraySchema ? a = a.default([]) : a = a.nullable()), a;
}
export {
  _ as createFieldValidationSchema
};
