import { compile } from '@mdx-js/mdx';
function getIssueLocation(error) {
    const line = error?.line ?? error?.position?.start?.line ?? 1;
    const column = error?.column ?? error?.position?.start?.column ?? 1;
    return { line, column };
}
function getIssueMessage(error) {
    return error?.reason ?? error?.message ?? 'Unknown MDX compile error';
}
export async function validateMarkdownForMdx(content) {
    try {
        await compile(content, { format: 'mdx' });
        return { valid: true, issues: [] };
    }
    catch (error) {
        const { line, column } = getIssueLocation(error);
        return {
            valid: false,
            issues: [
                {
                    line,
                    column,
                    ruleId: 'mdx-compile-error',
                    message: getIssueMessage(error),
                    severity: 'error',
                },
            ],
        };
    }
}
export function formatMdxValidationIssues(issues) {
    return issues.map((issue) => `Line ${issue.line}:${issue.column} [${issue.ruleId}] ${issue.message}`);
}
//# sourceMappingURL=mdx-validator.js.map