import type { ActionError } from "astro:actions";

export const getFormErrors = (
  path: string | number | (string | number)[],
  errors?: ActionError
) => {
  return Array.isArray(path)
    ? path.reduce((obj, key) => obj?.[key], errors?.fields)?.join(", ")
    : errors?.fields?.[path]?.join(", ");
};
