const linkVisitor = {
    match (node) {
        if ('link' !== node.type) return null;
        const attributes = node.attributes;
        if (null == attributes) return null;
        if ('internal' !== attributes.linkType) return null;
        const collectionPath = attributes.targetCollectionPath;
        const documentId = attributes.targetDocumentId;
        if (!collectionPath || !documentId) return null;
        return {
            node,
            collectionPath,
            documentId,
            apply (target) {
                const targetFields = target.fields ?? {};
                const path = target.path;
                const title = targetFields.title;
                const next = {
                    ...attributes.document ?? {}
                };
                if ('string' == typeof title && title.length > 0) next.title = title;
                if ('string' == typeof path && path.length > 0) next.path = path;
                attributes.document = next;
            }
        };
    }
};
export { linkVisitor };
