import { deriveImageSizes } from "./utils.js";
const inlineImageVisitor = {
    match (node) {
        if ('inline-image' !== node.type) return null;
        const collectionPath = node.targetCollectionPath;
        const documentId = node.targetDocumentId;
        if (!collectionPath || !documentId) return null;
        return {
            node,
            collectionPath,
            documentId,
            apply (target) {
                const targetFields = target.fields ?? {};
                const image = targetFields.image;
                const sizes = image ? deriveImageSizes(image) : [];
                const next = {
                    ...node.document ?? {}
                };
                if ('string' == typeof targetFields.title) next.title = targetFields.title;
                if ('string' == typeof targetFields.altText) next.altText = targetFields.altText;
                if (null != image) next.image = image;
                if (sizes.length > 0) next.sizes = sizes;
                node.document = next;
            }
        };
    }
};
export { inlineImageVisitor };
