import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { EditorWarning } from "../EditorWarning";
export function ValidationErrors({ item, editContext }) {
    let validationResult = editContext.validationResult
        ?.find((x) => x.item.id === item.id &&
        x.item.language === item.language &&
        x.item.version === item.version)
        ?.results.filter((x) => x.itemId === item.id);
    if (!validationResult) {
        const pageResult = editContext.validationResult?.find((x) => x.item.id === editContext?.page?.item.id);
        if (pageResult)
            validationResult = pageResult.results.filter((x) => x.itemId === item.id);
    }
    if (!validationResult?.length)
        return null;
    const fields = validationResult?.filter((x) => x.fieldId);
    return (_jsxs(EditorWarning, { title: "Validation", severity: "warning", children: [validationResult
                ?.filter((x) => !x.fieldId)
                .map((x) => _jsx("div", { children: x.message }, x.validator)), fields?.length > 0 && (_jsxs("div", { children: ["The following fields have validation messages:", " ", fields.map((x) => (_jsx("span", { className: "cursor-pointer font-bold", onClick: () => {
                            const field = Object.values(item.fields).find((f) => f.id === x.fieldId);
                            if (field?.descriptor &&
                                editContext?.setFocusedField) {
                                // Back-compat: if parent passed EditContext with setFocusedField
                                editContext.setFocusedField(field.descriptor, false);
                            }
                        }, children: x.fieldName }, x.validator + x.fieldId)))] }))] }));
}
//# sourceMappingURL=ValidationErrors.js.map