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